forked from pterodactyl/panel
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFileObjectTransformer.php
More file actions
53 lines (47 loc) · 1.38 KB
/
FileObjectTransformer.php
File metadata and controls
53 lines (47 loc) · 1.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
<?php
namespace Pterodactyl\Transformers\Daemon;
use Carbon\Carbon;
use Illuminate\Support\Arr;
class FileObjectTransformer extends BaseDaemonTransformer
{
/**
* An array of files we allow editing in the Panel.
*
* @var array
*/
private $editable = [];
/**
* FileObjectTransformer constructor.
*/
public function __construct()
{
$this->editable = config('pterodactyl.files.editable', []);
}
/**
* Transform a file object response from the daemon into a standardized response.
*
* @param array $item
* @return array
*/
public function transform(array $item)
{
return [
'name' => Arr::get($item, 'name'),
'mode' => Arr::get($item, 'mode'),
'size' => Arr::get($item, 'size'),
'is_file' => Arr::get($item, 'file', true),
'is_symlink' => Arr::get($item, 'symlink', false),
'is_editable' => in_array(Arr::get($item, 'mime', ''), $this->editable),
'mimetype' => Arr::get($item, 'mime'),
'created_at' => Carbon::parse(Arr::get($item, 'created', ''))->toIso8601String(),
'modified_at' => Carbon::parse(Arr::get($item, 'modified', ''))->toIso8601String(),
];
}
/**
* @return string
*/
public function getResourceName(): string
{
return 'file_object';
}
}