Skip to content

Commit 1476104

Browse files
DaneEverittxcgc
andcommitted
Fix inability to download files from the panel; closes pterodactyl#3151
Co-Authored-By: xcgc <74693042+xcgc@users.noreply.github.com>
1 parent 7e0efbd commit 1476104

File tree

3 files changed

+15
-10
lines changed

3 files changed

+15
-10
lines changed

app/Http/Controllers/Api/Client/Servers/BackupController.php

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ public function delete(Request $request, Server $server, Backup $backup): JsonRe
149149
* will be streamed back through the Panel. For AWS S3 files, a signed URL will be generated
150150
* which the user is redirected to.
151151
*
152+
* @throws \Throwable
152153
* @throws \Illuminate\Auth\Access\AuthorizationException
153154
*/
154155
public function download(Request $request, Server $server, Backup $backup): JsonResponse
@@ -157,16 +158,19 @@ public function download(Request $request, Server $server, Backup $backup): Json
157158
throw new AuthorizationException();
158159
}
159160

160-
switch ($backup->disk) {
161-
case Backup::ADAPTER_WINGS:
162-
case Backup::ADAPTER_AWS_S3:
163-
return new JsonResponse([
164-
'object' => 'signed_url',
165-
'attributes' => ['url' => ''],
166-
]);
167-
default:
168-
throw new BadRequestHttpException();
161+
if ($backup->disk !== Backup::ADAPTER_AWS_S3 && $backup->disk !== Backup::ADAPTER_WINGS) {
162+
throw new BadRequestHttpException('The backup requested references an unknown disk driver type and cannot be downloaded.');
169163
}
164+
165+
$url = $this->downloadLinkService->handle($backup, $request->user());
166+
$server->audit(AuditLog::SERVER__BACKUP_DOWNLOADED, function (AuditLog $audit) use ($backup) {
167+
$audit->metadata = ['backup_uuid' => $backup->uuid];
168+
});
169+
170+
return new JsonResponse([
171+
'object' => 'signed_url',
172+
'attributes' => ['url' => $url],
173+
]);
170174
}
171175

172176
/**

app/Models/AuditLog.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ class AuditLog extends Model
3535
public const SERVER__BACKUP_FAILED = 'server:backup.failed';
3636
public const SERVER__BACKUP_COMPELTED = 'server:backup.completed';
3737
public const SERVER__BACKUP_DELETED = 'server:backup.deleted';
38+
public const SERVER__BACKUP_DOWNLOADED = 'server:backup.downloaded';
3839
public const SERVER__BACKUP_RESTORE_STARTED = 'server:backup.restore.started';
3940
public const SERVER__BACKUP_RESTORE_COMPLETED = 'server:backup.restore.completed';
4041
public const SERVER__BACKUP_RESTORE_FAILED = 'server:backup.restore.failed';

app/Services/Backups/DownloadLinkService.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public function handle(Backup $backup, User $user): string
4747
])
4848
->handle($backup->server->node, $user->id . $backup->server->uuid);
4949

50-
return sprintf('%s/download/backup?token=%s', $backup->server->node->getConnectionAddress(), $token->__toString());
50+
return sprintf('%s/download/backup?token=%s', $backup->server->node->getConnectionAddress(), $token->toString());
5151
}
5252

5353
/**

0 commit comments

Comments
 (0)