Skip to content

Commit f241938

Browse files
committed
Add endpoint for triggering restoration completion
1 parent e700b4d commit f241938

File tree

3 files changed

+40
-2
lines changed

3 files changed

+40
-2
lines changed

app/Http/Controllers/Api/Remote/Backups/BackupStatusController.php

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
namespace Pterodactyl\Http\Controllers\Api\Remote\Backups;
44

55
use Carbon\CarbonImmutable;
6+
use Illuminate\Http\Request;
67
use Pterodactyl\Models\Backup;
8+
use Pterodactyl\Models\Server;
79
use Pterodactyl\Models\AuditLog;
810
use Illuminate\Http\JsonResponse;
911
use League\Flysystem\AwsS3v3\AwsS3Adapter;
@@ -47,7 +49,7 @@ public function __construct(BackupRepository $repository, BackupManager $backupM
4749
*
4850
* @throws \Throwable
4951
*/
50-
public function __invoke(ReportBackupCompleteRequest $request, string $backup)
52+
public function index(ReportBackupCompleteRequest $request, string $backup)
5153
{
5254
/** @var \Pterodactyl\Models\Backup $model */
5355
$model = Backup::query()->where('uuid', $backup)->firstOrFail();
@@ -63,6 +65,7 @@ public function __invoke(ReportBackupCompleteRequest $request, string $backup)
6365
: AuditLog::SERVER__BACKUP_FAILED;
6466

6567
$model->server->audit($action, function (AuditLog $audit) use ($model, $request) {
68+
$audit->is_system = true;
6669
$audit->metadata = ['backup_uuid' => $model->uuid];
6770

6871
$successful = $request->input('successful') ? true : false;
@@ -84,6 +87,39 @@ public function __invoke(ReportBackupCompleteRequest $request, string $backup)
8487
return new JsonResponse([], JsonResponse::HTTP_NO_CONTENT);
8588
}
8689

90+
/**
91+
* Handles toggling the restoration status of a server. The server status field should be
92+
* set back to null, even if the restoration failed. This is not an unsolvable state for
93+
* the server, and the user can keep trying to restore, or just use the reinstall button.
94+
*
95+
* The only thing the successful field does is update the entry value for the audit logs
96+
* table tracking for this restoration.
97+
*
98+
* @param \Illuminate\Http\Request $request
99+
* @param string $backup
100+
* @return \Illuminate\Http\JsonResponse
101+
*
102+
* @throws \Throwable
103+
*/
104+
public function restore(Request $request, string $backup)
105+
{
106+
/** @var \Pterodactyl\Models\Backup $model */
107+
$model = Backup::query()->where('uuid', $backup)->firstOrFail();
108+
$action = $request->get('successful')
109+
? AuditLog::SERVER__BACKUP_RESTORE_COMPLETED
110+
: AuditLog::SERVER__BACKUP_RESTORE_FAILED;
111+
112+
// Just create a new audit entry for this event and update the server state
113+
// so that power actions, file management, and backups can resume as normal.
114+
$model->server->audit($action, function (AuditLog $audit, Server $server) use ($backup, $request) {
115+
$audit->is_system = true;
116+
$audit->metadata = ['backup_uuid' => $backup];
117+
$server->update(['status' => null]);
118+
});
119+
120+
return new JsonResponse([], JsonResponse::HTTP_NO_CONTENT);
121+
}
122+
87123
/**
88124
* Marks a multipart upload in a given S3-compatiable instance as failed or successful for
89125
* the given backup.

resources/scripts/api/transformers.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ export const rawDataToFileObject = (data: FractalResponseData): FileObject => ({
3232
'application/x-br', // .tar.br
3333
'application/x-bzip2', // .tar.bz2, .bz2
3434
'application/gzip', // .tar.gz, .gz
35+
'application/x-gzip',
3536
'application/x-lzip', // .tar.lz4, .lz4 (not sure if this mime type is correct)
3637
'application/x-sz', // .tar.sz, .sz (not sure if this mime type is correct)
3738
'application/x-xz', // .tar.xz, .xz

routes/api-remote.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,6 @@
1919

2020
Route::group(['prefix' => '/backups'], function () {
2121
Route::get('/{backup}', 'Backups\BackupRemoteUploadController');
22-
Route::post('/{backup}', 'Backups\BackupStatusController');
22+
Route::post('/{backup}', 'Backups\BackupStatusController@index');
23+
Route::post('/{backup}/restore', 'Backups\BackupStatusController@restore');
2324
});

0 commit comments

Comments
 (0)