add API of fetching avatar and preview by texture hash
This commit is contained in:
parent
e50aed9017
commit
f607ba8a41
|
|
@ -39,9 +39,16 @@ class TextureController extends Controller
|
||||||
return response()->json($player)->setLastModified($player->last_modified);
|
return response()->json($player)->setLastModified($player->last_modified);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function preview(Minecraft $minecraft, Request $request, $tid)
|
public function previewByHash(Minecraft $minecraft, Request $request, $hash)
|
||||||
{
|
{
|
||||||
$texture = Texture::findOrFail($tid);
|
$texture = Texture::where('hash', $hash)->firstOrFail();
|
||||||
|
|
||||||
|
return $this->preview($minecraft, $request, $texture);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function preview(Minecraft $minecraft, Request $request, Texture $texture)
|
||||||
|
{
|
||||||
|
$tid = $texture->tid;
|
||||||
$hash = $texture->hash;
|
$hash = $texture->hash;
|
||||||
$usePNG = $request->has('png') || !(imagetypes() & IMG_WEBP);
|
$usePNG = $request->has('png') || !(imagetypes() & IMG_WEBP);
|
||||||
|
|
||||||
|
|
@ -110,6 +117,13 @@ class TextureController extends Controller
|
||||||
return $this->avatar($minecraft, $request, $texture);
|
return $this->avatar($minecraft, $request, $texture);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function avatarByHash(Minecraft $minecraft, Request $request, $hash)
|
||||||
|
{
|
||||||
|
$texture = Texture::where('hash', $hash)->first();
|
||||||
|
|
||||||
|
return $this->avatar($minecraft, $request, $texture);
|
||||||
|
}
|
||||||
|
|
||||||
public function avatarByTexture(Minecraft $minecraft, Request $request, $tid)
|
public function avatarByTexture(Minecraft $minecraft, Request $request, $tid)
|
||||||
{
|
{
|
||||||
$texture = Texture::find($tid);
|
$texture = Texture::find($tid);
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,7 @@
|
||||||
|
## Added
|
||||||
|
|
||||||
|
- Added API of fetching avatar and preview by texture hash.
|
||||||
|
|
||||||
## Changed
|
## Changed
|
||||||
|
|
||||||
- Select text automatically when click the hash text at texture detail page.
|
- Select text automatically when click the hash text at texture detail page.
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,7 @@
|
||||||
|
## 新增
|
||||||
|
|
||||||
|
- 新增以材质 hash 方式获取材质的预览图和头像的 API
|
||||||
|
|
||||||
## 调整
|
## 调整
|
||||||
|
|
||||||
- 材质详情页中点击 hash 文本时自动选择整条文本
|
- 材质详情页中点击 hash 文本时自动选择整条文本
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,10 @@ Route::get('raw/{tid}', 'TextureController@raw');
|
||||||
Route::prefix('avatar')->name('avatar.')->group(function () {
|
Route::prefix('avatar')->name('avatar.')->group(function () {
|
||||||
Route::get('player/{name}', 'TextureController@avatarByPlayer')->name('player');
|
Route::get('player/{name}', 'TextureController@avatarByPlayer')->name('player');
|
||||||
Route::get('user/{uid}', 'TextureController@avatarByUser')->name('user');
|
Route::get('user/{uid}', 'TextureController@avatarByUser')->name('user');
|
||||||
|
Route::get('hash/{hash}', 'TextureController@avatarByHash')->name('hash');
|
||||||
Route::get('{tid}', 'TextureController@avatarByTexture')->name('texture');
|
Route::get('{tid}', 'TextureController@avatarByTexture')->name('texture');
|
||||||
});
|
});
|
||||||
|
|
||||||
Route::get('preview/{tid}', 'TextureController@preview');
|
Route::get('preview/{texture}', 'TextureController@preview')
|
||||||
|
->middleware(Illuminate\Routing\Middleware\SubstituteBindings::class);
|
||||||
|
Route::get('preview/hash/{hash}', 'TextureController@previewByHash');
|
||||||
|
|
|
||||||
|
|
@ -42,12 +42,24 @@ class TextureControllerTest extends TestCase
|
||||||
])->assertHeader('Last-Modified');
|
])->assertHeader('Last-Modified');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testPreviewByHash()
|
||||||
|
{
|
||||||
|
$disk = Storage::fake('textures');
|
||||||
|
$this->mock(Minecraft::class, function ($mock) {
|
||||||
|
$mock->shouldReceive('renderSkin')->andReturn(Image::canvas(1, 1));
|
||||||
|
$mock->shouldReceive('renderCape')->andReturn(Image::canvas(1, 1));
|
||||||
|
});
|
||||||
|
|
||||||
|
$skin = factory(Texture::class)->create();
|
||||||
|
$disk->put($skin->hash, '');
|
||||||
|
$this->get('/preview/hash/'.$skin->hash)
|
||||||
|
->assertHeader('Content-Type', 'image/webp');
|
||||||
|
}
|
||||||
|
|
||||||
public function testPreview()
|
public function testPreview()
|
||||||
{
|
{
|
||||||
$disk = Storage::fake('textures');
|
$disk = Storage::fake('textures');
|
||||||
|
|
||||||
$this->get('/preview/0')->assertNotFound();
|
|
||||||
|
|
||||||
$this->mock(Minecraft::class, function ($mock) {
|
$this->mock(Minecraft::class, function ($mock) {
|
||||||
$mock->shouldReceive('renderSkin')->andReturn(Image::canvas(1, 1));
|
$mock->shouldReceive('renderSkin')->andReturn(Image::canvas(1, 1));
|
||||||
$mock->shouldReceive('renderCape')->andReturn(Image::canvas(1, 1));
|
$mock->shouldReceive('renderCape')->andReturn(Image::canvas(1, 1));
|
||||||
|
|
@ -57,8 +69,7 @@ class TextureControllerTest extends TestCase
|
||||||
$this->get('/preview/'.$skin->tid)->assertNotFound();
|
$this->get('/preview/'.$skin->tid)->assertNotFound();
|
||||||
|
|
||||||
$disk->put($skin->hash, '');
|
$disk->put($skin->hash, '');
|
||||||
$this->get('/preview/'.$skin->tid)
|
$this->get('/preview/'.$skin->tid)->assertHeader('Content-Type', 'image/webp');
|
||||||
->assertHeader('Content-Type', 'image/webp');
|
|
||||||
Cache::clear();
|
Cache::clear();
|
||||||
$this->get('/preview/'.$skin->tid.'?png')
|
$this->get('/preview/'.$skin->tid.'?png')
|
||||||
->assertHeader('Content-Type', 'image/png');
|
->assertHeader('Content-Type', 'image/png');
|
||||||
|
|
@ -182,6 +193,21 @@ class TextureControllerTest extends TestCase
|
||||||
$this->assertEquals(50, $image->height());
|
$this->assertEquals(50, $image->height());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testAvatarByHash()
|
||||||
|
{
|
||||||
|
$disk = Storage::fake('textures');
|
||||||
|
$this->mock(Minecraft::class, function ($mock) {
|
||||||
|
$mock->shouldReceive('render2dAvatar')->andReturn(Image::canvas(1, 1));
|
||||||
|
$mock->shouldReceive('render3dAvatar')->andReturn(Image::canvas(1, 1));
|
||||||
|
});
|
||||||
|
|
||||||
|
$texture = factory(Texture::class)->create();
|
||||||
|
$disk->put($texture->hash, '');
|
||||||
|
$this->get('/avatar/hash/'.$texture->hash)
|
||||||
|
->assertSuccessful()
|
||||||
|
->assertHeader('Content-Type', 'image/webp');
|
||||||
|
}
|
||||||
|
|
||||||
public function testAvatarByTexture()
|
public function testAvatarByTexture()
|
||||||
{
|
{
|
||||||
$disk = Storage::fake('textures');
|
$disk = Storage::fake('textures');
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user