fix checking file exists

This commit is contained in:
printempw 2016-09-10 18:50:04 +08:00
parent 0fe1391750
commit 35c978697b
4 changed files with 10 additions and 7 deletions

View File

@ -2,6 +2,7 @@
namespace App\Listeners;
use Storage;
use App\Models\Texture;
use App\Events\GetAvatarPreview;
use Illuminate\Queue\InteractsWithQueue;
@ -23,12 +24,12 @@ class CacheAvatarPreview
$path = BASE_DIR."/storage/textures/$hash";
if (!\Storage::disk('cache')->has("avatar/$tid-$size")) {
if (!Storage::disk('cache')->has("avatar/$tid-$size")) {
$png = \Minecraft::generateAvatarFromSkin($path, $event->size);
imagepng($png, BASE_DIR."/storage/cache/avatar/$tid-$size");
imagedestroy($png);
}
return \Response::png(\Storage::disk('cache')->get("avatar/$tid-$size"));
return \Response::png(Storage::disk('cache')->get("avatar/$tid-$size"));
}
}

View File

@ -2,6 +2,7 @@
namespace App\Listeners;
use Storage;
use App\Models\PlayerModel;
use App\Events\CheckPlayerExists;
use Illuminate\Queue\InteractsWithQueue;
@ -19,9 +20,9 @@ class CachePlayerExists
{
$player_name = $event->player_name;
if (!\Storage::disk('cache')->has("notfound/$player_name")) {
if ($player_name && !Storage::disk('cache')->has("notfound/$player_name")) {
if (PlayerModel::where('player_name', $player_name)->get()->isEmpty()) {
\Storage::disk('cache')->put("notfound/$player_name", '');
Storage::disk('cache')->put("notfound/$player_name", '');
}
} else {
abort(404, '角色不存在');

View File

@ -26,6 +26,6 @@ class CachePlayerJson
Storage::disk('cache')->put($filename, $player->generateJsonProfile($api_type));
}
return \Storage::disk('cache')->get($filename);
return Storage::disk('cache')->get($filename);
}
}

View File

@ -2,6 +2,7 @@
namespace App\Listeners;
use Storage;
use App\Events\PlayerWasAdded;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
@ -18,8 +19,8 @@ class FreshNotFoundCache
{
$player_name = $event->player->player_name;
if (\Storage::disk('cache')->has("notfound/$player_name")) {
\Storage::disk('cache')->delete("notfound/$player_name", '');
if ($player_name && Storage::disk('cache')->has("notfound/$player_name")) {
Storage::disk('cache')->delete("notfound/$player_name", '');
}
}
}