diff --git a/CHANGELOG.md b/CHANGELOG.md index debdc7f47..a6a87f2d3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,8 @@ - Fix word-break on statuses ([16ced7b4](https://github.com/pixelfed/pixelfed/commit/16ced7b4)) - Add pronouns to hovercards ([33f863e8](https://github.com/pixelfed/pixelfed/commit/33f863e8)) - Improved onboarding ([042c5b6c](https://github.com/pixelfed/pixelfed/commit/042c5b6c)) +- Add Hide Counts & Stats setting ([01af7d80](https://github.com/pixelfed/pixelfed/commit/01af7d80)) +- Fix nsfw videos not displaying sensitive warning ([01af7d80](https://github.com/pixelfed/pixelfed/commit/01af7d80)) ### Updated - Updated MediaStorageService, fix remote avatar bug. ([1c20d696](https://github.com/pixelfed/pixelfed/commit/1c20d696)) @@ -28,6 +30,8 @@ - Updated StatusService, use BookmarkService for bookmarked state. ([a7d71551](https://github.com/pixelfed/pixelfed/commit/a7d71551)) - Updated Apis, added ReblogService to improve reblogged state for api entities ([6cfd6be5](https://github.com/pixelfed/pixelfed/commit/6cfd6be5)) - Updated InstanceActorController, fix content-type header. ([21792246](https://github.com/pixelfed/pixelfed/commit/21792246)) +- Updated Exception handler to report validation message bag errors. ([74905ba1](https://github.com/pixelfed/pixelfed/commit/74905ba1)) +- Updated ApiV1Controller, add validation messages to update_credentials endpoint. ([cd785601](https://github.com/pixelfed/pixelfed/commit/cd785601)) - ([](https://github.com/pixelfed/pixelfed/commit/)) ## [v0.11.2 (2022-01-09)](https://github.com/pixelfed/pixelfed/compare/v0.11.1...v0.11.2) diff --git a/app/Exceptions/Handler.php b/app/Exceptions/Handler.php index dd98cdb23..9e2b8d35b 100644 --- a/app/Exceptions/Handler.php +++ b/app/Exceptions/Handler.php @@ -68,11 +68,20 @@ class Handler extends ExceptionHandler */ public function render($request, Throwable $exception) { - if ($request->wantsJson()) + if ($exception instanceof \Illuminate\Validation\ValidationException && $request->wantsJson()) { + return response()->json( + [ + 'message' => $exception->getMessage(), + 'errors' => $exception->validator->getMessageBag() + ], + method_exists($exception, 'getStatusCode') ? $exception->getStatusCode() : 500 + ); + } else if ($request->wantsJson()) { return response()->json( ['error' => $exception->getMessage()], method_exists($exception, 'getStatusCode') ? $exception->getStatusCode() : 500 ); + } return parent::render($request, $exception); } } diff --git a/app/Http/Controllers/Api/ApiV1Controller.php b/app/Http/Controllers/Api/ApiV1Controller.php index 7ea3f5133..b43de1fc7 100644 --- a/app/Http/Controllers/Api/ApiV1Controller.php +++ b/app/Http/Controllers/Api/ApiV1Controller.php @@ -74,6 +74,7 @@ use App\Services\{ UserFilterService }; use App\Util\Lexer\Autolink; +use App\Util\Lexer\PrettyNumber; use App\Util\Localization\Localization; use App\Util\Media\License; use App\Jobs\MediaPipeline\MediaSyncLicensePipeline; @@ -182,13 +183,17 @@ class ApiV1Controller extends Controller abort_if(!$request->user(), 403); $this->validate($request, [ - 'avatar' => 'sometimes|mimetypes:image/jpeg,image/png', + 'avatar' => 'sometimes|mimetypes:image/jpeg,image/png|min:10|max:' . config('pixelfed.max_avatar_size'), 'display_name' => 'nullable|string', 'note' => 'nullable|string', 'locked' => 'nullable', 'website' => 'nullable', // 'source.privacy' => 'nullable|in:unlisted,public,private', // 'source.sensitive' => 'nullable|boolean' + ], [ + 'required' => 'The :attribute field is required.', + 'avatar.mimetypes' => 'The file must be in jpeg or png format', + 'avatar.max' => 'The :attribute exceeds the file size limit of ' . PrettyNumber::size(config('pixelfed.max_avatar_size'), true, false), ]); $user = $request->user(); @@ -201,8 +206,6 @@ class ApiV1Controller extends Controller $licenseChanged = false; $composeSettings = array_merge(AccountService::defaultSettings()['compose_settings'], $settings->compose_settings ?? []); - // return $request->input('locked'); - if($request->has('avatar')) { $av = Avatar::whereProfileId($profile->id)->first(); if($av) { diff --git a/app/Util/Lexer/PrettyNumber.php b/app/Util/Lexer/PrettyNumber.php index 43daf7161..98c1952fd 100644 --- a/app/Util/Lexer/PrettyNumber.php +++ b/app/Util/Lexer/PrettyNumber.php @@ -24,14 +24,13 @@ class PrettyNumber return $number; } - public static function size($expression, $kb = false) + public static function size($expression, $kb = false, $short = true) { if ($kb) { $expression = $expression * 1024; } $size = intval($expression); $precision = 0; - $short = true; $units = $short ? ['B', 'k', 'M', 'G', 'T', 'P', 'E', 'Z', 'Y'] : ['B', 'kB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB']; diff --git a/public/js/spa.js b/public/js/spa.js index 777de5341..102bf8c91 100644 Binary files a/public/js/spa.js and b/public/js/spa.js differ diff --git a/public/mix-manifest.json b/public/mix-manifest.json index c8449c700..f0c616303 100644 Binary files a/public/mix-manifest.json and b/public/mix-manifest.json differ