mirror of
https://github.com/bs-community/blessing-skin-server.git
synced 2025-01-18 13:54:01 +08:00
Move Player::getBinaryTexture method to TextureController
This commit is contained in:
parent
815fef7f3d
commit
3d9478a75c
@ -73,7 +73,7 @@ class TextureController extends Controller
|
||||
$model_preference = ($player->getPreference() == "default") ? "steve" : "alex";
|
||||
$model = ($model == "") ? $model_preference : $model;
|
||||
|
||||
return $player->getBinaryTexture($model);
|
||||
return $this->getBinaryTextureFromPlayer($player_name, $model);
|
||||
}
|
||||
|
||||
public function skinWithModel($model, $player_name)
|
||||
@ -82,10 +82,35 @@ class TextureController extends Controller
|
||||
}
|
||||
|
||||
public function cape($player_name)
|
||||
{
|
||||
return $this->getBinaryTextureFromPlayer($player_name, 'cape');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the texture image of given type and player.
|
||||
*
|
||||
* @param string $player_name
|
||||
* @param string $type "steve" or "alex" or "cape".
|
||||
* @return void|Response
|
||||
*/
|
||||
protected function getBinaryTextureFromPlayer($player_name, $type)
|
||||
{
|
||||
$player = $this->getPlayerInstance($player_name);
|
||||
|
||||
return $player->getBinaryTexture('cape');
|
||||
if ($hash = $player->getTexture($type)) {
|
||||
if (Storage::disk('textures')->has($hash)) {
|
||||
// Cache friendly
|
||||
return Response::png(Storage::disk('textures')->read($hash), 200, [
|
||||
'Last-Modified' => $player->getLastModified(),
|
||||
'Accept-Ranges' => 'bytes',
|
||||
'Content-Length' => Storage::disk('textures')->size($hash),
|
||||
]);
|
||||
} else {
|
||||
abort(404, trans('general.texture-deleted'));
|
||||
}
|
||||
} else {
|
||||
abort(404, trans('general.texture-not-uploaded', ['type' => $type]));
|
||||
}
|
||||
}
|
||||
|
||||
public function avatar($base64_email, UserRepository $users, $size = 128)
|
||||
|
@ -4,14 +4,12 @@ namespace App\Models;
|
||||
|
||||
use Event;
|
||||
use Utils;
|
||||
use Storage;
|
||||
use Response;
|
||||
use App\Models\User;
|
||||
use App\Events\GetPlayerJson;
|
||||
use App\Events\PlayerProfileUpdated;
|
||||
use App\Exceptions\PrettyPageException;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
||||
|
||||
class Player extends Model
|
||||
{
|
||||
@ -151,32 +149,6 @@ class Player extends Model
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get binary texture by type.
|
||||
*
|
||||
* @param string $type steve|alex|cape
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function getBinaryTexture($type)
|
||||
{
|
||||
if ($this->getTexture($type)) {
|
||||
$hash = $this->getTexture($type);
|
||||
|
||||
if (Storage::disk('textures')->has($hash)) {
|
||||
// Cache friendly
|
||||
return Response::png(Storage::disk('textures')->get($hash), 200, [
|
||||
'Last-Modified' => $this->getLastModified(),
|
||||
'Accept-Ranges' => 'bytes',
|
||||
'Content-Length' => Storage::disk('textures')->size($hash),
|
||||
]);
|
||||
} else {
|
||||
throw new NotFoundHttpException(trans('general.texture-deleted'));
|
||||
}
|
||||
} else {
|
||||
throw new NotFoundHttpException(trans('general.texture-not-uploaded', ['type' => $type]));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set preferred model for the player.
|
||||
*
|
||||
|
Loading…
Reference in New Issue
Block a user