refactor SkinlibController

This commit is contained in:
Pig Fang 2020-08-20 08:48:53 +08:00
parent d10bcae197
commit 5b738ffe6f
No known key found for this signature in database
GPG Key ID: A8198F548DADA9E2
3 changed files with 4 additions and 13 deletions

View File

@ -77,21 +77,16 @@ class SkinlibController extends Controller
->paginate(20);
}
public function show(Filter $filter, $tid)
public function show(Filter $filter, Texture $texture)
{
$texture = Texture::find($tid);
/** @var User */
$user = Auth::user();
/** @var FilesystemAdapter */
$disk = Storage::disk('textures');
if (!$texture || $texture && $disk->missing($texture->hash)) {
if ($disk->missing($texture->hash)) {
if (option('auto_del_invalid_texture')) {
if ($texture) {
$texture->delete();
}
abort(404, trans('skinlib.show.deleted'));
$texture->delete();
}
abort(404, trans('skinlib.show.deleted'));
}

View File

@ -103,7 +103,7 @@ Route::prefix('texture')->name('texture.')->group(function () {
Route::prefix('skinlib')->name('skinlib.')->group(function () {
Route::view('', 'skinlib.index')->name('home');
Route::get('info/{texture}', 'SkinlibController@info')->name('info');
Route::get('show/{tid}', 'SkinlibController@show')->name('show');
Route::get('show/{texture}', 'SkinlibController@show')->name('show');
Route::get('list', 'SkinlibController@library')->name('list');
Route::middleware(['authorize', 'verified'])->group(function () {

View File

@ -136,10 +136,6 @@ class SkinlibControllerTest extends TestCase
Storage::fake('textures');
$filter = Fakes\Filter::fake();
// Cannot find texture
$this->get('/skinlib/show/1')
->assertSee(trans('skinlib.show.deleted'));
// Invalid texture
option(['auto_del_invalid_texture' => false]);
$texture = factory(Texture::class)->create();