Skip to content

Commit fd4de91

Browse files
authored
Merge branch 'develop' into feature/server-transfers-actually
2 parents 5c7c1f6 + ad9194a commit fd4de91

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+1000
-37
lines changed
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
<?php
2+
3+
namespace Pterodactyl\Http\Controllers\Api\Client\Servers;
4+
5+
use Pterodactyl\Models\Server;
6+
use Pterodactyl\Services\Backups\InitiateBackupService;
7+
use Pterodactyl\Transformers\Api\Client\BackupTransformer;
8+
use Pterodactyl\Http\Controllers\Api\Client\ClientApiController;
9+
use Pterodactyl\Http\Requests\Api\Client\Servers\Backups\GetBackupsRequest;
10+
use Pterodactyl\Http\Requests\Api\Client\Servers\Backups\StoreBackupRequest;
11+
12+
class BackupController extends ClientApiController
13+
{
14+
/**
15+
* @var \Pterodactyl\Services\Backups\InitiateBackupService
16+
*/
17+
private $initiateBackupService;
18+
19+
/**
20+
* BackupController constructor.
21+
*
22+
* @param \Pterodactyl\Services\Backups\InitiateBackupService $initiateBackupService
23+
*/
24+
public function __construct(InitiateBackupService $initiateBackupService)
25+
{
26+
parent::__construct();
27+
28+
$this->initiateBackupService = $initiateBackupService;
29+
}
30+
31+
/**
32+
* Returns all of the backups for a given server instance in a paginated
33+
* result set.
34+
*
35+
* @param \Pterodactyl\Http\Requests\Api\Client\Servers\Backups\GetBackupsRequest $request
36+
* @param \Pterodactyl\Models\Server $server
37+
* @return array
38+
*/
39+
public function index(GetBackupsRequest $request, Server $server)
40+
{
41+
return $this->fractal->collection($server->backups()->paginate(20))
42+
->transformWith($this->getTransformer(BackupTransformer::class))
43+
->toArray();
44+
}
45+
46+
/**
47+
* Starts the backup process for a server.
48+
*
49+
* @param \Pterodactyl\Http\Requests\Api\Client\Servers\Backups\StoreBackupRequest $request
50+
* @param \Pterodactyl\Models\Server $server
51+
* @return array
52+
*
53+
* @throws \Exception
54+
*/
55+
public function store(StoreBackupRequest $request, Server $server)
56+
{
57+
$backup = $this->initiateBackupService
58+
->setIgnoredFiles($request->input('ignored'))
59+
->handle($server, $request->input('name'));
60+
61+
return $this->fractal->item($backup)
62+
->transformWith($this->getTransformer(BackupTransformer::class))
63+
->toArray();
64+
}
65+
66+
public function view()
67+
{
68+
}
69+
70+
public function update()
71+
{
72+
}
73+
74+
public function delete()
75+
{
76+
}
77+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
3+
namespace Pterodactyl\Http\Requests\Api\Client\Servers\Backups;
4+
5+
use Pterodactyl\Models\Permission;
6+
use Pterodactyl\Http\Requests\Api\Client\ClientApiRequest;
7+
8+
class GetBackupsRequest extends ClientApiRequest
9+
{
10+
/**
11+
* @return string
12+
*/
13+
public function permission()
14+
{
15+
return Permission::ACTION_BACKUP_READ;
16+
}
17+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
namespace Pterodactyl\Http\Requests\Api\Client\Servers\Backups;
4+
5+
use Pterodactyl\Models\Permission;
6+
use Pterodactyl\Http\Requests\Api\Client\ClientApiRequest;
7+
8+
class StoreBackupRequest extends ClientApiRequest
9+
{
10+
/**
11+
* @return string
12+
*/
13+
public function permission()
14+
{
15+
return Permission::ACTION_BACKUP_CREATE;
16+
}
17+
18+
/**
19+
* @return array
20+
*/
21+
public function rules(): array
22+
{
23+
return [
24+
'name' => 'nullable|string|max:255',
25+
'ignore' => 'nullable|string',
26+
];
27+
}
28+
}

app/Models/Allocation.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
* @property \Pterodactyl\Models\Server|null $server
1919
* @property \Pterodactyl\Models\Node $node
2020
*/
21-
class Allocation extends Validable
21+
class Allocation extends Model
2222
{
2323
/**
2424
* The resource name for this model when it is transformed into an
@@ -75,7 +75,7 @@ public function getHashidAttribute()
7575
/**
7676
* Accessor to automatically provide the IP alias if defined.
7777
*
78-
* @param null|string $value
78+
* @param string|null $value
7979
* @return string
8080
*/
8181
public function getAliasAttribute($value)
@@ -86,7 +86,7 @@ public function getAliasAttribute($value)
8686
/**
8787
* Accessor to quickly determine if this allocation has an alias.
8888
*
89-
* @param null|string $value
89+
* @param string|null $value
9090
* @return bool
9191
*/
9292
public function getHasAliasAttribute($value)

app/Models/ApiKey.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
* @property \Carbon\Carbon $created_at
1717
* @property \Carbon\Carbon $updated_at
1818
*/
19-
class ApiKey extends Validable
19+
class ApiKey extends Model
2020
{
2121
const RESOURCE_NAME = 'api_key';
2222

app/Models/Backup.php

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
<?php
2+
3+
namespace Pterodactyl\Models;
4+
5+
use Illuminate\Database\Eloquent\SoftDeletes;
6+
7+
/**
8+
* @property int $id
9+
* @property int $server_id
10+
* @property int $uuid
11+
* @property string $name
12+
* @property string $ignored_files
13+
* @property string $disk
14+
* @property string|null $sha256_hash
15+
* @property int $bytes
16+
* @property \Carbon\CarbonImmutable|null $completed_at
17+
* @property \Carbon\CarbonImmutable $created_at
18+
* @property \Carbon\CarbonImmutable $updated_at
19+
* @property \Carbon\CarbonImmutable|null $deleted_at
20+
*
21+
* @property \Pterodactyl\Models\Server $server
22+
*/
23+
class Backup extends Model
24+
{
25+
use SoftDeletes;
26+
27+
const RESOURCE_NAME = 'backup';
28+
29+
/**
30+
* @var string
31+
*/
32+
protected $table = 'backups';
33+
34+
/**
35+
* @var bool
36+
*/
37+
protected $immutableDates = true;
38+
39+
/**
40+
* @var array
41+
*/
42+
protected $casts = [
43+
'id' => 'int',
44+
'bytes' => 'int',
45+
];
46+
47+
/**
48+
* @var array
49+
*/
50+
protected $dates = [
51+
'completed_at',
52+
];
53+
54+
/**
55+
* @var array
56+
*/
57+
protected $attributes = [
58+
'sha256_hash' => null,
59+
'bytes' => 0,
60+
];
61+
62+
/**
63+
* @var array
64+
*/
65+
public static $validationRules = [
66+
'server_id' => 'bail|required|numeric|exists:servers,id',
67+
'uuid' => 'required|uuid',
68+
'name' => 'required|string',
69+
'ignored_files' => 'string',
70+
'disk' => 'required|string',
71+
'sha256_hash' => 'nullable|string',
72+
'bytes' => 'numeric',
73+
];
74+
75+
/**
76+
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
77+
*/
78+
public function server()
79+
{
80+
return $this->belongsTo(Server::class);
81+
}
82+
}

app/Models/DaemonKey.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
use Znck\Eloquent\Traits\BelongsToThrough;
66

7-
class DaemonKey extends Validable
7+
class DaemonKey extends Model
88
{
99
use BelongsToThrough;
1010

app/Models/Database.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
namespace Pterodactyl\Models;
44

5-
class Database extends Validable
5+
class Database extends Model
66
{
77
/**
88
* The resource name for this model when it is transformed into an

app/Models/DatabaseHost.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
namespace Pterodactyl\Models;
44

5-
class DatabaseHost extends Validable
5+
class DatabaseHost extends Model
66
{
77
/**
88
* The resource name for this model when it is transformed into an

app/Models/Egg.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
* @property \Pterodactyl\Models\Egg|null $scriptFrom
4040
* @property \Pterodactyl\Models\Egg|null $configFrom
4141
*/
42-
class Egg extends Validable
42+
class Egg extends Model
4343
{
4444
/**
4545
* The resource name for this model when it is transformed into an

0 commit comments

Comments
 (0)