mirror of
https://github.com/bs-community/blessing-skin-server.git
synced 2025-01-08 12:07:42 +08:00
fix previews and avatars cannot be indivdually cached
by image format fix #212
This commit is contained in:
parent
f607ba8a41
commit
353db6f250
@ -51,6 +51,7 @@ class TextureController extends Controller
|
||||
$tid = $texture->tid;
|
||||
$hash = $texture->hash;
|
||||
$usePNG = $request->has('png') || !(imagetypes() & IMG_WEBP);
|
||||
$format = $usePNG ? 'png' : 'webp';
|
||||
|
||||
$disk = Storage::disk('textures');
|
||||
abort_if($disk->missing($hash), 404);
|
||||
@ -58,7 +59,7 @@ class TextureController extends Controller
|
||||
$height = (int) $request->query('height', 200);
|
||||
$now = Carbon::now();
|
||||
$response = Cache::remember(
|
||||
'preview-t'.$tid,
|
||||
'preview-t'.$tid."-$format",
|
||||
option('enable_preview_cache') ? $now->addYear() : $now->addMinute(),
|
||||
function () use ($minecraft, $disk, $texture, $hash, $height, $usePNG) {
|
||||
$file = $disk->get($hash);
|
||||
@ -136,6 +137,7 @@ class TextureController extends Controller
|
||||
$size = (int) $request->query('size', 100);
|
||||
$mode = $request->has('3d') ? '3d' : '2d';
|
||||
$usePNG = $request->has('png') || !(imagetypes() & IMG_WEBP);
|
||||
$format = $usePNG ? 'png' : 'webp';
|
||||
|
||||
$disk = Storage::disk('textures');
|
||||
if (is_null($texture) || $disk->missing($texture->hash)) {
|
||||
@ -147,7 +149,7 @@ class TextureController extends Controller
|
||||
$hash = $texture->hash;
|
||||
$now = Carbon::now();
|
||||
$response = Cache::remember(
|
||||
'avatar-'.$mode.'-t'.$texture->tid.'-s'.$size,
|
||||
'avatar-'.$mode.'-t'.$texture->tid.'-s'.$size."-$format",
|
||||
option('enable_avatar_cache') ? $now->addYear() : $now->addMinute(),
|
||||
function () use ($minecraft, $disk, $hash, $size, $mode, $usePNG) {
|
||||
$file = $disk->get($hash);
|
||||
|
@ -10,3 +10,4 @@
|
||||
|
||||
- Fixed duplicated route names.
|
||||
- Fixed duplication of private textures.
|
||||
- Fixed that previews and avatars cannot be indivdually cached by image format.
|
||||
|
@ -10,3 +10,4 @@
|
||||
|
||||
- 修复重复的路由命名
|
||||
- 修复私有材质的重复问题
|
||||
- 修复预览图和头像不能根据图像格式来单独缓存的问题
|
||||
|
@ -14,6 +14,8 @@ Route::prefix('avatar')->name('avatar.')->group(function () {
|
||||
Route::get('{tid}', 'TextureController@avatarByTexture')->name('texture');
|
||||
});
|
||||
|
||||
Route::get('preview/{texture}', 'TextureController@preview')
|
||||
->middleware(Illuminate\Routing\Middleware\SubstituteBindings::class);
|
||||
Route::get('preview/hash/{hash}', 'TextureController@previewByHash');
|
||||
Route::prefix('preview')->name('preview.')->group(function () {
|
||||
Route::get('{texture}', 'TextureController@preview')->name('texture')
|
||||
->middleware(Illuminate\Routing\Middleware\SubstituteBindings::class);
|
||||
Route::get('hash/{hash}', 'TextureController@previewByHash')->name('hash');
|
||||
});
|
||||
|
@ -73,12 +73,12 @@ class TextureControllerTest extends TestCase
|
||||
Cache::clear();
|
||||
$this->get('/preview/'.$skin->tid.'?png')
|
||||
->assertHeader('Content-Type', 'image/png');
|
||||
$this->assertTrue(Cache::has('preview-t'.$skin->tid));
|
||||
$this->assertTrue(Cache::has('preview-t'.$skin->tid.'-png'));
|
||||
|
||||
$cape = factory(Texture::class)->states('cape')->create();
|
||||
$disk->put($cape->hash, '');
|
||||
$this->get('/preview/'.$cape->tid.'?height=100')->assertHeader('Content-Type', 'image/webp');
|
||||
$this->assertTrue(Cache::has('preview-t'.$cape->tid));
|
||||
$this->assertTrue(Cache::has('preview-t'.$cape->tid.'-webp'));
|
||||
}
|
||||
|
||||
public function testRaw()
|
||||
@ -245,17 +245,17 @@ class TextureControllerTest extends TestCase
|
||||
$image = Image::make($image);
|
||||
$this->assertEquals(100, $image->width());
|
||||
$this->assertEquals(100, $image->height());
|
||||
$this->assertTrue(Cache::has('avatar-2d-t'.$texture->tid.'-s100'));
|
||||
$this->assertTrue(Cache::has('avatar-2d-t'.$texture->tid.'-s100-png'));
|
||||
|
||||
$image = $this->get('/avatar/'.$texture->tid.'?size=50&png')->getContent();
|
||||
$image = Image::make($image);
|
||||
$this->assertEquals(50, $image->width());
|
||||
$this->assertEquals(50, $image->height());
|
||||
$this->assertTrue(Cache::has('avatar-2d-t'.$texture->tid.'-s50'));
|
||||
$this->assertTrue(Cache::has('avatar-2d-t'.$texture->tid.'-s50-png'));
|
||||
|
||||
$this->get('/avatar/'.$texture->tid.'?3d')
|
||||
->assertSuccessful()
|
||||
->assertHeader('Content-Type', 'image/webp');
|
||||
$this->assertTrue(Cache::has('avatar-3d-t'.$texture->tid.'-s100'));
|
||||
$this->assertTrue(Cache::has('avatar-3d-t'.$texture->tid.'-s100-webp'));
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user