From bec33650f02dbf6e9d82e2878702092b772aec2f Mon Sep 17 00:00:00 2001 From: Pig Fang Date: Sun, 23 Feb 2020 09:37:10 +0800 Subject: [PATCH] fix missing alert when uploading duplicated texture (fix #132) --- app/Http/Controllers/SkinlibController.php | 15 +++++---------- resources/misc/changelogs/en/5.0.0.md | 1 + resources/misc/changelogs/zh_CN/5.0.0.md | 1 + .../ControllersTest/SkinlibControllerTest.php | 2 +- 4 files changed, 8 insertions(+), 11 deletions(-) diff --git a/app/Http/Controllers/SkinlibController.php b/app/Http/Controllers/SkinlibController.php index f2af7624..e738c285 100644 --- a/app/Http/Controllers/SkinlibController.php +++ b/app/Http/Controllers/SkinlibController.php @@ -246,16 +246,11 @@ class SkinlibController extends Controller return json(trans('skinlib.upload.lack-score'), 7); } - $results = Texture::where('hash', $t->hash)->get(); - - if (!$results->isEmpty()) { - foreach ($results as $result) { - // if the texture already uploaded was set to private, - // then allow to re-upload it. - if ($result->public) { - return json(trans('skinlib.upload.repeated'), 0, ['tid' => $result->tid]); - } - } + $repeated = Texture::where('hash', $t->hash)->where('public', true)->first(); + if ($repeated) { + // if the texture already uploaded was set to private, + // then allow to re-upload it. + return json(trans('skinlib.upload.repeated'), 2, ['tid' => $repeated->tid]); } if (Storage::disk('textures')->missing($t->hash)) { diff --git a/resources/misc/changelogs/en/5.0.0.md b/resources/misc/changelogs/en/5.0.0.md index 0989cbff..c0bf09c9 100644 --- a/resources/misc/changelogs/en/5.0.0.md +++ b/resources/misc/changelogs/en/5.0.0.md @@ -57,6 +57,7 @@ - Fixed that `lang` attribute of HTML can't be configured correctly. - Fixed that avatar can't be resized when requesting an non-existed user. - Fixed that the same texture files with different models were treated as different textures. +- Fixed when uploading duplicated texture, alert is missing. ## Removed diff --git a/resources/misc/changelogs/zh_CN/5.0.0.md b/resources/misc/changelogs/zh_CN/5.0.0.md index 7cac33e4..be563be5 100644 --- a/resources/misc/changelogs/zh_CN/5.0.0.md +++ b/resources/misc/changelogs/zh_CN/5.0.0.md @@ -57,6 +57,7 @@ - 修复未能正确设置 HTML 的 `lang` 属性的问题 - 修复获取不存在的用户的头像时,未能正确设置尺寸的问题 - 修复同一材质文件但模型不同被认为不同材质的问题 +- 修复上传重复材质时没有提示用户的问题 ## 移除 diff --git a/tests/HttpTest/ControllersTest/SkinlibControllerTest.php b/tests/HttpTest/ControllersTest/SkinlibControllerTest.php index 62e95dd7..56faf17a 100644 --- a/tests/HttpTest/ControllersTest/SkinlibControllerTest.php +++ b/tests/HttpTest/ControllersTest/SkinlibControllerTest.php @@ -583,7 +583,7 @@ class SkinlibControllerTest extends TestCase 'file' => $upload, ] )->assertJson([ - 'code' => 0, + 'code' => 2, 'message' => trans('skinlib.upload.repeated'), 'data' => ['tid' => $t->tid], ]);