Very basic implemention of frontend logic required to display backups and create a new one
This commit is contained in:
parent
17ec4efd3b
commit
9991989f89
16 changed files with 431 additions and 2 deletions
54
app/Http/Controllers/Api/Client/Servers/BackupController.php
Normal file
54
app/Http/Controllers/Api/Client/Servers/BackupController.php
Normal file
|
@ -0,0 +1,54 @@
|
|||
<?php
|
||||
|
||||
namespace Pterodactyl\Http\Controllers\Api\Client\Servers;
|
||||
|
||||
use Pterodactyl\Models\Server;
|
||||
use Pterodactyl\Transformers\Api\Client\BackupTransformer;
|
||||
use Pterodactyl\Http\Controllers\Api\Client\ClientApiController;
|
||||
use Pterodactyl\Http\Requests\Api\Client\Servers\Backups\GetBackupsRequest;
|
||||
use Pterodactyl\Http\Requests\Api\Client\Servers\Backups\StoreBackupRequest;
|
||||
|
||||
class BackupController extends ClientApiController
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns all of the backups for a given server instance in a paginated
|
||||
* result set.
|
||||
*
|
||||
* @param \Pterodactyl\Http\Requests\Api\Client\Servers\Backups\GetBackupsRequest $request
|
||||
* @param \Pterodactyl\Models\Server $server
|
||||
* @return array
|
||||
*/
|
||||
public function index(GetBackupsRequest $request, Server $server)
|
||||
{
|
||||
return $this->fractal->collection($server->backups()->paginate(20))
|
||||
->transformWith($this->getTransformer(BackupTransformer::class))
|
||||
->toArray();
|
||||
}
|
||||
|
||||
/**
|
||||
* Starts the backup process for a server.
|
||||
*
|
||||
* @param \Pterodactyl\Http\Requests\Api\Client\Servers\Backups\StoreBackupRequest $request
|
||||
* @param \Pterodactyl\Models\Server $server
|
||||
*/
|
||||
public function store(StoreBackupRequest $request, Server $server)
|
||||
{
|
||||
}
|
||||
|
||||
public function view()
|
||||
{
|
||||
}
|
||||
|
||||
public function update()
|
||||
{
|
||||
}
|
||||
|
||||
public function delete()
|
||||
{
|
||||
}
|
||||
}
|
|
@ -0,0 +1,17 @@
|
|||
<?php
|
||||
|
||||
namespace Pterodactyl\Http\Requests\Api\Client\Servers\Backups;
|
||||
|
||||
use Pterodactyl\Models\Permission;
|
||||
use Pterodactyl\Http\Requests\Api\Client\ClientApiRequest;
|
||||
|
||||
class GetBackupsRequest extends ClientApiRequest
|
||||
{
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function permission()
|
||||
{
|
||||
return Permission::ACTION_BACKUP_READ;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,28 @@
|
|||
<?php
|
||||
|
||||
namespace Pterodactyl\Http\Requests\Api\Client\Servers\Backups;
|
||||
|
||||
use Pterodactyl\Models\Permission;
|
||||
use Pterodactyl\Http\Requests\Api\Client\ClientApiRequest;
|
||||
|
||||
class StoreBackupRequest extends ClientApiRequest
|
||||
{
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function permission()
|
||||
{
|
||||
return Permission::ACTION_BACKUP_CREATE;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'name' => 'nullable|string|max:255',
|
||||
'ignore' => 'nullable|string',
|
||||
];
|
||||
}
|
||||
}
|
|
@ -6,9 +6,10 @@ use Illuminate\Database\Eloquent\SoftDeletes;
|
|||
|
||||
/**
|
||||
* @property int $id
|
||||
* @property int $server_id
|
||||
* @property int $uuid
|
||||
* @property string $name
|
||||
* @property string $contents
|
||||
* @property string $ignore
|
||||
* @property string $disk
|
||||
* @property string|null $sha256_hash
|
||||
* @property int $bytes
|
||||
|
@ -16,11 +17,15 @@ use Illuminate\Database\Eloquent\SoftDeletes;
|
|||
* @property \Carbon\CarbonImmutable $created_at
|
||||
* @property \Carbon\CarbonImmutable $updated_at
|
||||
* @property \Carbon\CarbonImmutable|null $deleted_at
|
||||
*
|
||||
* @property \Pterodactyl\Models\Server $server
|
||||
*/
|
||||
class Backup extends Model
|
||||
{
|
||||
use SoftDeletes;
|
||||
|
||||
const RESOURCE_NAME = 'backup';
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
|
@ -56,4 +61,12 @@ class Backup extends Model
|
|||
{
|
||||
return $this->asImmutableDateTime($value);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
*/
|
||||
public function server()
|
||||
{
|
||||
return $this->belongsTo(Server::class);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -37,6 +37,12 @@ class Permission extends Model
|
|||
const ACTION_USER_UPDATE = 'user.update';
|
||||
const ACTION_USER_DELETE = 'user.delete';
|
||||
|
||||
const ACTION_BACKUP_READ = 'backup.read';
|
||||
const ACTION_BACKUP_CREATE = 'backup.create';
|
||||
const ACTION_BACKUP_UPDATE = 'backup.update';
|
||||
const ACTION_BACKUP_DELETE = 'backup.delete';
|
||||
const ACTION_BACKUP_DOWNLOAD = 'backup.download';
|
||||
|
||||
const ACTION_ALLOCATION_READ = 'allocation.read';
|
||||
const ACTION_ALLOCIATION_UPDATE = 'allocation.update';
|
||||
|
||||
|
@ -135,6 +141,17 @@ class Permission extends Model
|
|||
],
|
||||
],
|
||||
|
||||
'backup' => [
|
||||
'description' => 'Permissions that control a user\'s ability to generate and manage server backups.',
|
||||
'keys' => [
|
||||
'create' => 'Allows a user to create new backups for this server.',
|
||||
'read' => 'Allows a user to view all backups that exist for this server.',
|
||||
'update' => '',
|
||||
'delete' => 'Allows a user to remove backups from the system.',
|
||||
'download' => 'Allows a user to download backups.',
|
||||
],
|
||||
],
|
||||
|
||||
// Controls permissions for editing or viewing a server's allocations.
|
||||
'allocation' => [
|
||||
'description' => 'Permissions that control a user\'s ability to modify the port allocations for this server.',
|
||||
|
|
|
@ -51,6 +51,7 @@ use Znck\Eloquent\Traits\BelongsToThrough;
|
|||
* @property \Pterodactyl\Models\Location $location
|
||||
* @property \Pterodactyl\Models\DaemonKey $key
|
||||
* @property \Pterodactyl\Models\DaemonKey[]|\Illuminate\Database\Eloquent\Collection $keys
|
||||
* @property \Pterodactyl\Models\Backup[]|\Illuminate\Database\Eloquent\Collection $backups
|
||||
*/
|
||||
class Server extends Model
|
||||
{
|
||||
|
@ -339,4 +340,12 @@ class Server extends Model
|
|||
{
|
||||
return $this->hasMany(DaemonKey::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Illuminate\Database\Eloquent\Relations\HasMany
|
||||
*/
|
||||
public function backups()
|
||||
{
|
||||
return $this->hasMany(Backup::class);
|
||||
}
|
||||
}
|
||||
|
|
33
app/Transformers/Api/Client/BackupTransformer.php
Normal file
33
app/Transformers/Api/Client/BackupTransformer.php
Normal file
|
@ -0,0 +1,33 @@
|
|||
<?php
|
||||
|
||||
namespace Pterodactyl\Transformers\Api\Client;
|
||||
|
||||
use Pterodactyl\Models\Backup;
|
||||
|
||||
class BackupTransformer extends BaseClientTransformer
|
||||
{
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getResourceName(): string
|
||||
{
|
||||
return Backup::RESOURCE_NAME;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Pterodactyl\Models\Backup $backup
|
||||
* @return array
|
||||
*/
|
||||
public function transform(Backup $backup)
|
||||
{
|
||||
return [
|
||||
'uuid' => $backup->uuid,
|
||||
'name' => $backup->name,
|
||||
'ignore' => $backup->ignore,
|
||||
'sha256_hash' => $backup->sha256_hash,
|
||||
'bytes' => $backup->bytes,
|
||||
'created_at' => $backup->created_at->toIso8601String(),
|
||||
'completed_at' => $backup->completed_at->toIso8601String(),
|
||||
];
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue