diff --git a/app/Actions/Storage/Wiki/Video/UploadVideoAction.php b/app/Actions/Storage/Wiki/Video/UploadVideoAction.php index eaf0a80bb..46badfde3 100644 --- a/app/Actions/Storage/Wiki/Video/UploadVideoAction.php +++ b/app/Actions/Storage/Wiki/Video/UploadVideoAction.php @@ -97,17 +97,10 @@ protected function getOrCreateVideo(): Video Video::ATTRIBUTE_FILENAME => File::name($this->file->getClientOriginalName()), Video::ATTRIBUTE_MIMETYPE => $this->file->getMimeType(), Video::ATTRIBUTE_PATH => $path, + Video::ATTRIBUTE_RESOLUTION => intval(Arr::get(SubmissionRule::$ffprobeData['streams'][0], 'height')), Video::ATTRIBUTE_SIZE => $this->file->getSize(), ]; - if (Arr::has($this->attributes, Video::ATTRIBUTE_RESOLUTION)) { - if (!empty($this->attributes[Video::ATTRIBUTE_RESOLUTION])) { - $attributes[Video::ATTRIBUTE_RESOLUTION] = Arr::get($this->attributes, Video::ATTRIBUTE_RESOLUTION); - } else { - $ffprobeData = SubmissionRule::$ffprobeData; - $attributes[Video::ATTRIBUTE_RESOLUTION] = intval($ffprobeData['streams'][0]['height']); - } - } if (Arr::has($this->attributes, Video::ATTRIBUTE_NC)) { $attributes[Video::ATTRIBUTE_NC] = Arr::get($this->attributes, Video::ATTRIBUTE_NC); } diff --git a/app/Nova/Actions/Storage/Base/UploadAction.php b/app/Nova/Actions/Storage/Base/UploadAction.php index 4d005b42a..ab4ed270b 100644 --- a/app/Nova/Actions/Storage/Base/UploadAction.php +++ b/app/Nova/Actions/Storage/Base/UploadAction.php @@ -39,8 +39,12 @@ public function fields(NovaRequest $request): array ->help(__('nova.actions.storage.upload.fields.file.help')), Text::make(__('nova.actions.storage.upload.fields.path.name'), 'path') - ->required() - ->rules(['required', 'string', 'doesnt_start_with:/', 'doesnt_end_with:/', new StorageDirectoryExistsRule($fs)]) + ->rules(fn ($request) => [ + 'doesnt_start_with:/', + 'doesnt_end_with:/', + empty($request->input('path')) ? '' : 'string', + empty($request->input('path')) ? '' : new StorageDirectoryExistsRule($fs), + ]) ->help(__('nova.actions.storage.upload.fields.path.help')), ]; } diff --git a/app/Nova/Actions/Storage/Wiki/Video/UploadVideoAction.php b/app/Nova/Actions/Storage/Wiki/Video/UploadVideoAction.php index a3b743f85..b732a949f 100644 --- a/app/Nova/Actions/Storage/Wiki/Video/UploadVideoAction.php +++ b/app/Nova/Actions/Storage/Wiki/Video/UploadVideoAction.php @@ -6,8 +6,10 @@ use App\Actions\Storage\Wiki\Video\UploadVideoAction as UploadVideo; use App\Constants\Config\VideoConstants; +use App\Enums\Models\Wiki\AnimeSeason; use App\Enums\Models\Wiki\VideoOverlap; use App\Enums\Models\Wiki\VideoSource; +use App\Models\Wiki\Anime; use App\Models\Wiki\Anime\Theme\AnimeThemeEntry; use App\Models\Wiki\Video; use App\Nova\Actions\Storage\Base\UploadAction; @@ -33,6 +35,7 @@ use App\Rules\Wiki\Submission\Video\VideoPixelFormatStreamRule; use Illuminate\Http\UploadedFile; use Illuminate\Support\Collection; +use Illuminate\Support\Str; use Illuminate\Support\Facades\Config; use Illuminate\Validation\Rules\Enum; use Illuminate\Validation\Rules\File as FileRule; @@ -81,13 +84,6 @@ public function fields(NovaRequest $request): array Hidden::make(__('nova.resources.singularLabel.anime_theme_entry'), AnimeThemeEntry::ATTRIBUTE_ID) ->default(fn () => $parent instanceof AnimeThemeEntry ? $parent->getKey() : null), - Number::make(__('nova.fields.video.resolution.name'), Video::ATTRIBUTE_RESOLUTION) - ->min(360) - ->max(1080) - ->nullable() - ->rules(['nullable', 'integer']) - ->help(__('nova.fields.video.resolution.help')), - Boolean::make(__('nova.fields.video.nc.name'), Video::ATTRIBUTE_NC) ->nullable() ->rules(['nullable', 'boolean']) @@ -141,7 +137,7 @@ public function fields(NovaRequest $request): array */ protected function action(ActionFields $fields, Collection $models): UploadVideo { - /** @var string $path */ + /** @var ?string $path */ $path = $fields->get('path'); /** @var UploadedFile $file */ @@ -153,8 +149,21 @@ protected function action(ActionFields $fields, Collection $models): UploadVideo /** @var UploadedFile|null $script */ $script = $fields->get('script'); + if ($path === null) { + /** @var Anime|null $anime */ + $anime = $entry->animetheme->anime; + if ($anime instanceof Anime) { + $year = $anime->year; + $path = $year >= 2000 ? + Str::of(strval($year)) + ->append('/') + ->append(AnimeSeason::tryFrom($anime->season->value)->localize()) + ->__toString() + : floor($year % 100 / 10) . '0s'; + } + } + $attributes = [ - Video::ATTRIBUTE_RESOLUTION => $fields->get(Video::ATTRIBUTE_RESOLUTION), Video::ATTRIBUTE_NC => $fields->get(Video::ATTRIBUTE_NC), Video::ATTRIBUTE_SUBBED => $fields->get(Video::ATTRIBUTE_SUBBED), Video::ATTRIBUTE_LYRICS => $fields->get(Video::ATTRIBUTE_LYRICS), diff --git a/tests/Feature/Actions/Storage/Wiki/Video/UploadVideoTest.php b/tests/Feature/Actions/Storage/Wiki/Video/UploadVideoTest.php index 608db077f..4c0a563f2 100644 --- a/tests/Feature/Actions/Storage/Wiki/Video/UploadVideoTest.php +++ b/tests/Feature/Actions/Storage/Wiki/Video/UploadVideoTest.php @@ -132,7 +132,6 @@ public function testSetsAttributes(): void $source = Arr::random(VideoSource::cases()); $attributes = [ - Video::ATTRIBUTE_RESOLUTION => $this->faker->numberBetween(360, 1080), Video::ATTRIBUTE_NC => $this->faker->boolean(), Video::ATTRIBUTE_SUBBED => $this->faker->boolean(), Video::ATTRIBUTE_LYRICS => $this->faker->boolean(),