From c08496fd55b65d19cd167cdddfad278f325e8f9d Mon Sep 17 00:00:00 2001 From: ScuffedNewt Date: Sun, 19 May 2024 17:13:01 +0100 Subject: [PATCH] fix: update image size validation to correctly be 2mb instead of approx. 20mb & add validation to admin reuploads --- .../Admin/Characters/CharacterImageController.php | 1 + app/Models/Character/Character.php | 8 ++++---- app/Models/Character/CharacterImage.php | 6 +++--- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/app/Http/Controllers/Admin/Characters/CharacterImageController.php b/app/Http/Controllers/Admin/Characters/CharacterImageController.php index 391874a3fd..780fa305e7 100644 --- a/app/Http/Controllers/Admin/Characters/CharacterImageController.php +++ b/app/Http/Controllers/Admin/Characters/CharacterImageController.php @@ -249,6 +249,7 @@ public function getImageReupload($id) { * @return \Illuminate\Http\RedirectResponse */ public function postImageReupload(Request $request, CharacterManager $service, $id) { + $request->validate(['image' => CharacterImage::$createRules['image'], 'thumbnail' => CharacterImage::$createRules['thumbnail']]); $data = $request->only(['image', 'thumbnail', 'x0', 'x1', 'y0', 'y1', 'use_cropper']); $image = CharacterImage::find($id); if (!$image) { diff --git a/app/Models/Character/Character.php b/app/Models/Character/Character.php index 5c797c2a88..1d6d4d2ee9 100644 --- a/app/Models/Character/Character.php +++ b/app/Models/Character/Character.php @@ -78,8 +78,8 @@ class Character extends Model { 'slug' => 'required|alpha_dash', 'description' => 'nullable', 'sale_value' => 'nullable', - 'image' => 'required|mimes:jpeg,jpg,gif,png|max:20000', - 'thumbnail' => 'nullable|mimes:jpeg,jpg,gif,png|max:20000', + 'image' => 'required|mimes:jpeg,jpg,gif,png|max:2048', + 'thumbnail' => 'nullable|mimes:jpeg,jpg,gif,png|max:2048', 'owner_url' => 'url|nullable', ]; @@ -109,8 +109,8 @@ class Character extends Model { 'description' => 'nullable', 'sale_value' => 'nullable', 'name' => 'required', - 'image' => 'nullable|mimes:jpeg,gif,png|max:20000', - 'thumbnail' => 'nullable|mimes:jpeg,gif,png|max:20000', + 'image' => 'nullable|mimes:jpeg,gif,png|max:2048', + 'thumbnail' => 'nullable|mimes:jpeg,gif,png|max:2048', ]; /********************************************************************************************** diff --git a/app/Models/Character/CharacterImage.php b/app/Models/Character/CharacterImage.php index 84b6fc36ae..7bf5eada21 100644 --- a/app/Models/Character/CharacterImage.php +++ b/app/Models/Character/CharacterImage.php @@ -47,8 +47,8 @@ class CharacterImage extends Model { public static $createRules = [ 'species_id' => 'required', 'rarity_id' => 'required', - 'image' => 'required|mimes:jpeg,jpg,gif,png,webp|max:20000', - 'thumbnail' => 'nullable|mimes:jpeg,jpg,gif,png,webp|max:20000', + 'image' => 'required|mimes:jpeg,jpg,gif,png,webp|max:2048', + 'thumbnail' => 'nullable|mimes:jpeg,jpg,gif,png,webp|max:2048', ]; /** @@ -225,7 +225,7 @@ public function getFullsizeUrlAttribute() { /** * Gets the file name of the model's fullsize image. * - * @param user + * @param User * @param mixed|null $user * * @return string