|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Minepic\Http\Controllers\Api; |
|
6
|
|
|
|
|
7
|
|
|
use Illuminate\Http\Response; |
|
8
|
|
|
use Laravel\Lumen\Http\ResponseFactory; |
|
9
|
|
|
use Laravel\Lumen\Routing\Controller as BaseController; |
|
10
|
|
|
use Minepic\Helpers\Storage\Files\SkinsStorage; |
|
11
|
|
|
use Minepic\Image\Sections\Skin; |
|
12
|
|
|
use Minepic\Minecraft\MinecraftDefaults; |
|
13
|
|
|
use Minepic\Resolvers\UuidResolver; |
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* Class BaseApiController. |
|
17
|
|
|
*/ |
|
18
|
|
|
class DownloadTextureController extends BaseController |
|
19
|
|
|
{ |
|
20
|
|
|
/** |
|
21
|
|
|
* @var UuidResolver |
|
22
|
|
|
*/ |
|
23
|
|
|
protected UuidResolver $uuidResolver; |
|
24
|
|
|
|
|
25
|
|
|
/** @var ResponseFactory */ |
|
26
|
|
|
protected ResponseFactory $responseFactory; |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* Api constructor. |
|
30
|
|
|
* |
|
31
|
|
|
* @param UuidResolver $uuidResolver |
|
32
|
|
|
* @param ResponseFactory $responseFactory |
|
33
|
|
|
*/ |
|
34
|
|
|
public function __construct( |
|
35
|
|
|
UuidResolver $uuidResolver, |
|
36
|
|
|
ResponseFactory $responseFactory |
|
37
|
|
|
) { |
|
38
|
|
|
$this->uuidResolver = $uuidResolver; |
|
39
|
|
|
$this->responseFactory = $responseFactory; |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* Download user texture. |
|
44
|
|
|
* |
|
45
|
|
|
* @param string $uuid User UUID or Username |
|
46
|
|
|
* |
|
47
|
|
|
* @throws \Minepic\Image\Exceptions\ImageCreateFromPngFailedException |
|
48
|
|
|
* |
|
49
|
|
|
* @return \Illuminate\Http\Response |
|
50
|
|
|
*/ |
|
51
|
|
|
public function serve(string $uuid = ''): Response |
|
52
|
|
|
{ |
|
53
|
|
|
$headers = [ |
|
54
|
|
|
'Content-Disposition' => 'Attachment;filename='.$uuid.'.png', |
|
55
|
|
|
'Content-Type' => 'image/png', |
|
56
|
|
|
]; |
|
57
|
|
|
$this->uuidResolver->resolve($uuid); |
|
58
|
|
|
|
|
59
|
|
|
$skinPath = $this->uuidResolver->resolve($uuid) ? |
|
60
|
|
|
SkinsStorage::getPath($this->uuidResolver->getUuid()) : |
|
61
|
|
|
SkinsStorage::getPath(MinecraftDefaults::STEVE_DEFAULT_SKIN_NAME); |
|
62
|
|
|
|
|
63
|
|
|
$userSkin = new Skin($skinPath); |
|
64
|
|
|
$userSkin->prepareTextureDownload(); |
|
65
|
|
|
|
|
66
|
|
|
return $this->responseFactory->make($userSkin, 200, $headers); |
|
67
|
|
|
} |
|
68
|
|
|
} |
|
69
|
|
|
|