fix cache of requests with size

This commit is contained in:
printempw 2016-09-03 21:12:13 +08:00
parent 2b55346a0c
commit 31001f15ae
8 changed files with 10 additions and 14 deletions

View File

@ -2,7 +2,6 @@
namespace App\Events; namespace App\Events;
use App\Events\Event;
use Illuminate\Queue\SerializesModels; use Illuminate\Queue\SerializesModels;
use Illuminate\Contracts\Broadcasting\ShouldBroadcast; use Illuminate\Contracts\Broadcasting\ShouldBroadcast;

View File

@ -2,7 +2,6 @@
namespace App\Events; namespace App\Events;
use App\Events\Event;
use Illuminate\Queue\SerializesModels; use Illuminate\Queue\SerializesModels;
use Illuminate\Contracts\Broadcasting\ShouldBroadcast; use Illuminate\Contracts\Broadcasting\ShouldBroadcast;

View File

@ -3,7 +3,6 @@
namespace App\Events; namespace App\Events;
use App\Models\Player; use App\Models\Player;
use App\Events\Event;
use Illuminate\Queue\SerializesModels; use Illuminate\Queue\SerializesModels;
use Illuminate\Contracts\Broadcasting\ShouldBroadcast; use Illuminate\Contracts\Broadcasting\ShouldBroadcast;

View File

@ -2,7 +2,6 @@
namespace App\Events; namespace App\Events;
use App\Events\Event;
use App\Models\Texture; use App\Models\Texture;
use Illuminate\Queue\SerializesModels; use Illuminate\Queue\SerializesModels;
use Illuminate\Contracts\Broadcasting\ShouldBroadcast; use Illuminate\Contracts\Broadcasting\ShouldBroadcast;

View File

@ -2,7 +2,6 @@
namespace App\Events; namespace App\Events;
use App\Events\Event;
use Illuminate\Queue\SerializesModels; use Illuminate\Queue\SerializesModels;
use Illuminate\Contracts\Broadcasting\ShouldBroadcast; use Illuminate\Contracts\Broadcasting\ShouldBroadcast;

View File

@ -3,7 +3,6 @@
namespace App\Events; namespace App\Events;
use App\Models\PlayerModel; use App\Models\PlayerModel;
use App\Events\Event;
use Illuminate\Queue\SerializesModels; use Illuminate\Queue\SerializesModels;
use Illuminate\Contracts\Broadcasting\ShouldBroadcast; use Illuminate\Contracts\Broadcasting\ShouldBroadcast;

View File

@ -19,15 +19,16 @@ class CacheAvatarPreview
{ {
$tid = $event->texture->tid; $tid = $event->texture->tid;
$hash = $event->texture->hash; $hash = $event->texture->hash;
$size = $event->size;
$path = BASE_DIR."/storage/textures/$hash"; $path = BASE_DIR."/storage/textures/$hash";
if (!\Storage::disk('cache')->has("avatar/$tid")) { if (!\Storage::disk('cache')->has("avatar/$tid-$size")) {
$png = \Minecraft::generateAvatarFromSkin($path, $event->size); $png = \Minecraft::generateAvatarFromSkin($path, $event->size);
imagepng($png, BASE_DIR."/storage/cache/avatar/$tid"); imagepng($png, BASE_DIR."/storage/cache/avatar/$tid-$size");
imagedestroy($png); imagedestroy($png);
} }
return \Response::png(\Storage::disk('cache')->get("avatar/$tid")); return \Response::png(\Storage::disk('cache')->get("avatar/$tid-$size"));
} }
} }

View File

@ -17,22 +17,23 @@ class CacheSkinPreview
*/ */
public function handle(GetSkinPreview $event) public function handle(GetSkinPreview $event)
{ {
$tid = $event->texture->tid; $tid = $event->texture->tid;
$size = $event->size;
if (!Storage::disk('cache')->has("preview/$tid")) { if (!Storage::disk('cache')->has("preview/$tid-$size")) {
$filename = BASE_DIR."/storage/textures/{$event->texture->hash}"; $filename = BASE_DIR."/storage/textures/{$event->texture->hash}";
if ($event->texture->type == "cape") { if ($event->texture->type == "cape") {
$png = \Minecraft::generatePreviewFromCape($filename, $event->size); $png = \Minecraft::generatePreviewFromCape($filename, $event->size);
imagepng($png, BASE_DIR."/storage/cache/preview/$tid"); imagepng($png, BASE_DIR."/storage/cache/preview/$tid-$size");
imagedestroy($png); imagedestroy($png);
} else { } else {
$png = \Minecraft::generatePreviewFromSkin($filename, $event->size); $png = \Minecraft::generatePreviewFromSkin($filename, $event->size);
imagepng($png, BASE_DIR."/storage/cache/preview/$tid"); imagepng($png, BASE_DIR."/storage/cache/preview/$tid-$size");
imagedestroy($png); imagedestroy($png);
} }
} }
return \Response::png(Storage::disk('cache')->get("preview/$tid")); return \Response::png(Storage::disk('cache')->get("preview/$tid-$size"));
} }
} }