Merge branch 'develop' into feature/300-incoming-webhook
# Conflicts: # package.json # webpack.mix.js # yarn.lock
This commit is contained in:
@@ -9,23 +9,33 @@ use App\User;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Validator;
|
||||
|
||||
class EjaculationController extends Controller
|
||||
{
|
||||
public function create(Request $request)
|
||||
{
|
||||
$defaults = [
|
||||
'date' => $request->input('date', date('Y/m/d')),
|
||||
'time' => $request->input('time', date('H:i')),
|
||||
'link' => $request->input('link', ''),
|
||||
'tags' => $request->input('tags', ''),
|
||||
'note' => $request->input('note', ''),
|
||||
'is_private' => $request->input('is_private', 0) == 1,
|
||||
'is_too_sensitive' => $request->input('is_too_sensitive', 0) == 1
|
||||
$tags = old('tags') ?? $request->input('tags', '');
|
||||
if (!empty($tags)) {
|
||||
$tags = explode(' ', $tags);
|
||||
}
|
||||
|
||||
$errors = $request->session()->get('errors');
|
||||
$initialState = [
|
||||
'fields' => [
|
||||
'date' => old('date') ?? $request->input('date', date('Y/m/d')),
|
||||
'time' => old('time') ?? $request->input('time', date('H:i')),
|
||||
'link' => old('link') ?? $request->input('link', ''),
|
||||
'tags' => $tags,
|
||||
'note' => old('note') ?? $request->input('note', ''),
|
||||
'is_private' => old('is_private') ?? $request->input('is_private', 0) == 1,
|
||||
'is_too_sensitive' => old('is_too_sensitive') ?? $request->input('is_too_sensitive', 0) == 1
|
||||
],
|
||||
'errors' => isset($errors) ? $errors->getMessages() : null
|
||||
];
|
||||
|
||||
return view('ejaculation.checkin')->with('defaults', $defaults);
|
||||
return view('ejaculation.checkin')->with('initialState', $initialState);
|
||||
}
|
||||
|
||||
public function store(Request $request)
|
||||
@@ -52,29 +62,33 @@ class EjaculationController extends Controller
|
||||
return redirect()->route('checkin')->withErrors($validator)->withInput();
|
||||
}
|
||||
|
||||
$ejaculation = Ejaculation::create([
|
||||
'user_id' => Auth::id(),
|
||||
'ejaculated_date' => Carbon::createFromFormat('Y/m/d H:i', $inputs['date'] . ' ' . $inputs['time']),
|
||||
'note' => $inputs['note'] ?? '',
|
||||
'link' => $inputs['link'] ?? '',
|
||||
'source' => Ejaculation::SOURCE_WEB,
|
||||
'is_private' => $request->has('is_private') ?? false,
|
||||
'is_too_sensitive' => $request->has('is_too_sensitive') ?? false
|
||||
]);
|
||||
$ejaculation = DB::transaction(function () use ($request, $inputs) {
|
||||
$ejaculation = Ejaculation::create([
|
||||
'user_id' => Auth::id(),
|
||||
'ejaculated_date' => Carbon::createFromFormat('Y/m/d H:i', $inputs['date'] . ' ' . $inputs['time']),
|
||||
'note' => $inputs['note'] ?? '',
|
||||
'link' => $inputs['link'] ?? '',
|
||||
'source' => Ejaculation::SOURCE_WEB,
|
||||
'is_private' => $request->has('is_private') ?? false,
|
||||
'is_too_sensitive' => $request->has('is_too_sensitive') ?? false
|
||||
]);
|
||||
|
||||
$tagIds = [];
|
||||
if (!empty($inputs['tags'])) {
|
||||
$tags = explode(' ', $inputs['tags']);
|
||||
foreach ($tags as $tag) {
|
||||
if ($tag === '') {
|
||||
continue;
|
||||
$tagIds = [];
|
||||
if (!empty($inputs['tags'])) {
|
||||
$tags = explode(' ', $inputs['tags']);
|
||||
foreach ($tags as $tag) {
|
||||
if ($tag === '') {
|
||||
continue;
|
||||
}
|
||||
|
||||
$tag = Tag::firstOrCreate(['name' => $tag]);
|
||||
$tagIds[] = $tag->id;
|
||||
}
|
||||
|
||||
$tag = Tag::firstOrCreate(['name' => $tag]);
|
||||
$tagIds[] = $tag->id;
|
||||
}
|
||||
}
|
||||
$ejaculation->tags()->sync($tagIds);
|
||||
$ejaculation->tags()->sync($tagIds);
|
||||
|
||||
return $ejaculation;
|
||||
});
|
||||
|
||||
if (!empty($ejaculation->link)) {
|
||||
event(new LinkDiscovered($ejaculation->link));
|
||||
@@ -107,13 +121,36 @@ class EjaculationController extends Controller
|
||||
return view('ejaculation.show')->with(compact('user', 'ejaculation', 'ejaculatedSpan'));
|
||||
}
|
||||
|
||||
public function edit($id)
|
||||
public function edit(Request $request, $id)
|
||||
{
|
||||
$ejaculation = Ejaculation::findOrFail($id);
|
||||
|
||||
$this->authorize('edit', $ejaculation);
|
||||
|
||||
return view('ejaculation.edit')->with(compact('ejaculation'));
|
||||
if (old('tags') === null) {
|
||||
$tags = $ejaculation->tags->pluck('name');
|
||||
} else {
|
||||
$tags = old('tags');
|
||||
if (!empty($tags)) {
|
||||
$tags = explode(' ', $tags);
|
||||
}
|
||||
}
|
||||
|
||||
$errors = $request->session()->get('errors');
|
||||
$initialState = [
|
||||
'fields' => [
|
||||
'date' => old('date') ?? $ejaculation->ejaculated_date->format('Y/m/d'),
|
||||
'time' => old('time') ?? $ejaculation->ejaculated_date->format('H:i'),
|
||||
'link' => old('link') ?? $ejaculation->link,
|
||||
'tags' => $tags,
|
||||
'note' => old('note') ?? $ejaculation->note,
|
||||
'is_private' => is_bool(old('is_private')) ? old('is_private') : $ejaculation->note,
|
||||
'is_too_sensitive' => is_bool(old('is_too_sensitive')) ? old('is_too_sensitive') : $ejaculation->is_too_sensitive
|
||||
],
|
||||
'errors' => isset($errors) ? $errors->getMessages() : null
|
||||
];
|
||||
|
||||
return view('ejaculation.edit')->with(compact('ejaculation', 'initialState'));
|
||||
}
|
||||
|
||||
public function update(Request $request, $id)
|
||||
@@ -144,27 +181,29 @@ class EjaculationController extends Controller
|
||||
return redirect()->route('checkin.edit', ['id' => $id])->withErrors($validator)->withInput();
|
||||
}
|
||||
|
||||
$ejaculation->fill([
|
||||
'ejaculated_date' => Carbon::createFromFormat('Y/m/d H:i', $inputs['date'] . ' ' . $inputs['time']),
|
||||
'note' => $inputs['note'] ?? '',
|
||||
'link' => $inputs['link'] ?? '',
|
||||
'is_private' => $request->has('is_private') ?? false,
|
||||
'is_too_sensitive' => $request->has('is_too_sensitive') ?? false
|
||||
])->save();
|
||||
DB::transaction(function () use ($ejaculation, $request, $inputs) {
|
||||
$ejaculation->fill([
|
||||
'ejaculated_date' => Carbon::createFromFormat('Y/m/d H:i', $inputs['date'] . ' ' . $inputs['time']),
|
||||
'note' => $inputs['note'] ?? '',
|
||||
'link' => $inputs['link'] ?? '',
|
||||
'is_private' => $request->has('is_private') ?? false,
|
||||
'is_too_sensitive' => $request->has('is_too_sensitive') ?? false
|
||||
])->save();
|
||||
|
||||
$tagIds = [];
|
||||
if (!empty($inputs['tags'])) {
|
||||
$tags = explode(' ', $inputs['tags']);
|
||||
foreach ($tags as $tag) {
|
||||
if ($tag === '') {
|
||||
continue;
|
||||
$tagIds = [];
|
||||
if (!empty($inputs['tags'])) {
|
||||
$tags = explode(' ', $inputs['tags']);
|
||||
foreach ($tags as $tag) {
|
||||
if ($tag === '') {
|
||||
continue;
|
||||
}
|
||||
|
||||
$tag = Tag::firstOrCreate(['name' => $tag]);
|
||||
$tagIds[] = $tag->id;
|
||||
}
|
||||
|
||||
$tag = Tag::firstOrCreate(['name' => $tag]);
|
||||
$tagIds[] = $tag->id;
|
||||
}
|
||||
}
|
||||
$ejaculation->tags()->sync($tagIds);
|
||||
$ejaculation->tags()->sync($tagIds);
|
||||
});
|
||||
|
||||
if (!empty($ejaculation->link)) {
|
||||
event(new LinkDiscovered($ejaculation->link));
|
||||
@@ -180,8 +219,11 @@ class EjaculationController extends Controller
|
||||
$this->authorize('edit', $ejaculation);
|
||||
|
||||
$user = User::findOrFail($ejaculation->user_id);
|
||||
$ejaculation->tags()->detach();
|
||||
$ejaculation->delete();
|
||||
|
||||
DB::transaction(function () use ($ejaculation) {
|
||||
$ejaculation->tags()->detach();
|
||||
$ejaculation->delete();
|
||||
});
|
||||
|
||||
return redirect()->route('user.profile', ['name' => $user->name])->with('status', '削除しました。');
|
||||
}
|
||||
|
@@ -34,6 +34,7 @@ class MetadataResolver implements Resolver
|
||||
'~www\.xtube\.com/video-watch/.*-\d+$~'=> XtubeResolver::class,
|
||||
'~ss\.kb10uy\.org/posts/\d+$~' => Kb10uyShortStoryServerResolver::class,
|
||||
'~www\.hentai-foundry\.com/pictures/user/.+/\d+/.+~'=> HentaiFoundryResolver::class,
|
||||
'~(www\.)?((mobile|m)\.)?twitter\.com/(#!/)?[0-9a-zA-Z_]{1,15}/status(es)?/([0-9]+)/?(\\?.+)?$~' => TwitterResolver::class,
|
||||
];
|
||||
|
||||
public $mimeTypes = [
|
||||
|
@@ -3,6 +3,8 @@
|
||||
namespace App\MetadataResolver;
|
||||
|
||||
use GuzzleHttp\Client;
|
||||
use GuzzleHttp\Cookie\CookieJar;
|
||||
use GuzzleHttp\RequestOptions;
|
||||
|
||||
class OGPResolver implements Resolver, Parser
|
||||
{
|
||||
@@ -18,7 +20,7 @@ class OGPResolver implements Resolver, Parser
|
||||
|
||||
public function resolve(string $url): Metadata
|
||||
{
|
||||
return $this->parse($this->client->get($url)->getBody());
|
||||
return $this->parse($this->client->get($url, [RequestOptions::COOKIES => new CookieJar()])->getBody());
|
||||
}
|
||||
|
||||
public function parse(string $html): Metadata
|
||||
|
33
app/MetadataResolver/TwitterResolver.php
Normal file
33
app/MetadataResolver/TwitterResolver.php
Normal file
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
namespace App\MetadataResolver;
|
||||
|
||||
use GuzzleHttp\Client;
|
||||
|
||||
class TwitterResolver implements Resolver
|
||||
{
|
||||
/**
|
||||
* @var Client
|
||||
*/
|
||||
private $client;
|
||||
/**
|
||||
* @var OGPResolver
|
||||
*/
|
||||
private $ogpResolver;
|
||||
|
||||
public function __construct(Client $client, OGPResolver $ogpResolver)
|
||||
{
|
||||
$this->client = $client;
|
||||
$this->ogpResolver = $ogpResolver;
|
||||
}
|
||||
|
||||
public function resolve(string $url): Metadata
|
||||
{
|
||||
$url = preg_replace('/(www\.)?(mobile|m)\.twitter\.com/u', 'twitter.com', $url);
|
||||
|
||||
$res = $this->client->get($url);
|
||||
$html = (string) $res->getBody();
|
||||
|
||||
return $this->ogpResolver->parse($html);
|
||||
}
|
||||
}
|
62
app/Rules/FuzzyBoolean.php
Normal file
62
app/Rules/FuzzyBoolean.php
Normal file
@@ -0,0 +1,62 @@
|
||||
<?php
|
||||
|
||||
namespace App\Rules;
|
||||
|
||||
use Illuminate\Contracts\Validation\Rule;
|
||||
|
||||
class FuzzyBoolean implements Rule
|
||||
{
|
||||
public static function isTruthy($value): bool
|
||||
{
|
||||
if ($value === 1 || $value === '1') {
|
||||
return true;
|
||||
}
|
||||
|
||||
$lower = strtolower((string)$value);
|
||||
|
||||
return $lower === 'true';
|
||||
}
|
||||
|
||||
public static function isFalsy($value): bool
|
||||
{
|
||||
if ($value === null || $value === '' || $value === 0 || $value === '0') {
|
||||
return true;
|
||||
}
|
||||
|
||||
$lower = strtolower((string)$value);
|
||||
|
||||
return $lower === 'false';
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new rule instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if the validation rule passes.
|
||||
*
|
||||
* @param string $attribute
|
||||
* @param mixed $value
|
||||
* @return bool
|
||||
*/
|
||||
public function passes($attribute, $value)
|
||||
{
|
||||
return self::isTruthy($value) || self::isFalsy($value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation error message.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function message()
|
||||
{
|
||||
return __('validation.boolean');
|
||||
}
|
||||
}
|
@@ -30,7 +30,7 @@ class CheckinCsvExporter
|
||||
$csv->addStreamFilter('convert.mbstring.encoding.UTF-8:SJIS-win');
|
||||
}
|
||||
|
||||
$header = ['日時', 'ノート', 'オカズリンク'];
|
||||
$header = ['日時', 'ノート', 'オカズリンク', '非公開', 'センシティブ'];
|
||||
for ($i = 1; $i <= 32; $i++) {
|
||||
$header[] = "タグ{$i}";
|
||||
}
|
||||
@@ -45,6 +45,8 @@ class CheckinCsvExporter
|
||||
$ejaculation->ejaculated_date->format('Y/m/d H:i'),
|
||||
$ejaculation->note,
|
||||
$ejaculation->link,
|
||||
self::formatBoolean($ejaculation->is_private),
|
||||
self::formatBoolean($ejaculation->is_too_sensitive),
|
||||
];
|
||||
foreach ($ejaculation->tags->take(32) as $tag) {
|
||||
$record[] = $tag->name;
|
||||
@@ -54,4 +56,9 @@ class CheckinCsvExporter
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
private static function formatBoolean($value): string
|
||||
{
|
||||
return $value ? 'true' : 'false';
|
||||
}
|
||||
}
|
||||
|
@@ -6,6 +6,7 @@ namespace App\Services;
|
||||
use App\Ejaculation;
|
||||
use App\Exceptions\CsvImportException;
|
||||
use App\Rules\CsvDateTime;
|
||||
use App\Rules\FuzzyBoolean;
|
||||
use App\Tag;
|
||||
use App\User;
|
||||
use Carbon\Carbon;
|
||||
@@ -75,6 +76,8 @@ class CheckinCsvImporter
|
||||
'日時' => ['required', new CsvDateTime()],
|
||||
'ノート' => 'nullable|string|max:500',
|
||||
'オカズリンク' => 'nullable|url|max:2000',
|
||||
'非公開' => ['nullable', new FuzzyBoolean()],
|
||||
'センシティブ' => ['nullable', new FuzzyBoolean()],
|
||||
]);
|
||||
|
||||
if ($validator->fails()) {
|
||||
@@ -88,6 +91,12 @@ class CheckinCsvImporter
|
||||
$ejaculation->note = str_replace(["\r\n", "\r"], "\n", $record['ノート'] ?? '');
|
||||
$ejaculation->link = $record['オカズリンク'] ?? '';
|
||||
$ejaculation->source = Ejaculation::SOURCE_CSV;
|
||||
if (isset($record['非公開'])) {
|
||||
$ejaculation->is_private = FuzzyBoolean::isTruthy($record['非公開']);
|
||||
}
|
||||
if (isset($record['センシティブ'])) {
|
||||
$ejaculation->is_too_sensitive = FuzzyBoolean::isTruthy($record['センシティブ']);
|
||||
}
|
||||
|
||||
try {
|
||||
$tags = $this->parseTags($line, $record);
|
||||
|
Reference in New Issue
Block a user