diff --git a/app/Http/Controllers/SkinlibController.php b/app/Http/Controllers/SkinlibController.php index f11ff615..66ff6d19 100644 --- a/app/Http/Controllers/SkinlibController.php +++ b/app/Http/Controllers/SkinlibController.php @@ -219,6 +219,17 @@ class SkinlibController extends Controller $type = $data['type']; $size = getimagesize($file); + + if ($size[0] % 64 != 0 || $size[1] % 32 != 0) { + $message = trans('skinlib.upload.invalid-size', [ + 'type' => $type === 'cape' ? trans('general.cape') : trans('general.skin'), + 'width' => $size[0], + 'height' => $size[1], + ]); + + return json($message, 1); + } + $ratio = $size[0] / $size[1]; if ($type == 'steve' || $type == 'alex') { if ($ratio != 2 && $ratio != 1 || $type === 'alex' && $ratio === 2) { @@ -228,15 +239,6 @@ class SkinlibController extends Controller 'height' => $size[1], ]); - return json($message, 1); - } - if ($size[0] % 64 != 0 || $size[1] % 32 != 0) { - $message = trans('skinlib.upload.invalid-hd-skin', [ - 'type' => trans('general.skin'), - 'width' => $size[0], - 'height' => $size[1], - ]); - return json($message, 1); } } elseif ($type == 'cape') { diff --git a/tests/HttpTest/ControllersTest/SkinlibControllerTest.php b/tests/HttpTest/ControllersTest/SkinlibControllerTest.php index 2693ec08..c9400307 100644 --- a/tests/HttpTest/ControllersTest/SkinlibControllerTest.php +++ b/tests/HttpTest/ControllersTest/SkinlibControllerTest.php @@ -337,12 +337,25 @@ class SkinlibControllerTest extends TestCase 'file' => UploadedFile::fake()->image('texture.png', 100, 50), ])->assertJson([ 'code' => 1, - 'message' => trans('skinlib.upload.invalid-hd-skin', [ + 'message' => trans('skinlib.upload.invalid-size', [ 'type' => trans('general.skin'), 'width' => 100, 'height' => 50, ]), ]); + $this->postJson(route('texture.upload'), [ + 'name' => 'texture', + 'public' => true, + 'type' => 'cape', + 'file' => UploadedFile::fake()->image('texture.png', 100, 50), + ])->assertJson([ + 'code' => 1, + 'message' => trans('skinlib.upload.invalid-size', [ + 'type' => trans('general.cape'), + 'width' => 100, + 'height' => 50, + ]), + ]); $this->postJson(route('texture.upload'), [ 'name' => 'texture', 'public' => true,