From 80e6a5a98fdd009009c870fb9ba88163ade95f26 Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Wed, 1 Feb 2023 22:58:06 -0700 Subject: [PATCH] Update ComposeController, fix validation issue --- app/Http/Controllers/Api/ApiV1Controller.php | 26 ++++++++++++------- app/Http/Controllers/ComposeController.php | 17 +++++++----- .../assets/js/components/ComposeModal.vue | 7 +++++ 3 files changed, 33 insertions(+), 17 deletions(-) diff --git a/app/Http/Controllers/Api/ApiV1Controller.php b/app/Http/Controllers/Api/ApiV1Controller.php index cd999318d..d9dd6a0f4 100644 --- a/app/Http/Controllers/Api/ApiV1Controller.php +++ b/app/Http/Controllers/Api/ApiV1Controller.php @@ -1449,13 +1449,16 @@ class ApiV1Controller extends Controller abort_if(!$request->user(), 403); $this->validate($request, [ - 'file.*' => function() { - return [ - 'required', + 'file.*' => [ + 'required_without:file', 'mimetypes:' . config_cache('pixelfed.media_types'), 'max:' . config_cache('pixelfed.max_photo_size'), - ]; - }, + ], + 'file' => [ + 'required_without:file.*', + 'mimetypes:' . config_cache('pixelfed.media_types'), + 'max:' . config_cache('pixelfed.max_photo_size'), + ], 'filter_name' => 'nullable|string|max:24', 'filter_class' => 'nullable|alpha_dash|max:24', 'description' => 'nullable|string|max:' . config_cache('pixelfed.max_altext_length') @@ -1647,13 +1650,16 @@ class ApiV1Controller extends Controller abort_if(!$request->user(), 403); $this->validate($request, [ - 'file.*' => function() { - return [ - 'required', + 'file.*' => [ + 'required_without:file', 'mimetypes:' . config_cache('pixelfed.media_types'), 'max:' . config_cache('pixelfed.max_photo_size'), - ]; - }, + ], + 'file' => [ + 'required_without:file.*', + 'mimetypes:' . config_cache('pixelfed.media_types'), + 'max:' . config_cache('pixelfed.max_photo_size'), + ], 'filter_name' => 'nullable|string|max:24', 'filter_class' => 'nullable|alpha_dash|max:24', 'description' => 'nullable|string|max:' . config_cache('pixelfed.max_altext_length') diff --git a/app/Http/Controllers/ComposeController.php b/app/Http/Controllers/ComposeController.php index 7bb43e324..848e0c45d 100644 --- a/app/Http/Controllers/ComposeController.php +++ b/app/Http/Controllers/ComposeController.php @@ -75,13 +75,16 @@ class ComposeController extends Controller abort_if(!$request->user(), 403); $this->validate($request, [ - 'file.*' => function() { - return [ - 'required', - 'mimetypes:' . config_cache('pixelfed.media_types'), - 'max:' . config_cache('pixelfed.max_photo_size'), - ]; - }, + 'file.*' => [ + 'required_without:file', + 'mimetypes:' . config_cache('pixelfed.media_types'), + 'max:' . config_cache('pixelfed.max_photo_size'), + ], + 'file' => [ + 'required_without:file.*', + 'mimetypes:' . config_cache('pixelfed.media_types'), + 'max:' . config_cache('pixelfed.max_photo_size'), + ], 'filter_name' => 'nullable|string|max:24', 'filter_class' => 'nullable|alpha_dash|max:24' ]); diff --git a/resources/assets/js/components/ComposeModal.vue b/resources/assets/js/components/ComposeModal.vue index 22fc7ee95..09cc0831d 100644 --- a/resources/assets/js/components/ComposeModal.vue +++ b/resources/assets/js/components/ComposeModal.vue @@ -1192,6 +1192,13 @@ export default { self.page = 2; break; + case 500: + self.uploading = false; + io.value = null; + swal('Error', e.response.data.message, 'error'); + self.page = 2; + break; + default: self.uploading = false; io.value = null;