Skip to content

An open-source, self-hostable PaaS alternative to Vercel, Heroku & Netlify that lets you easily deploy static sites, databases, full-stack applications and 360+ one-click services on your own servers.

Update download_file method name in backup-executions.blade.php

Andras Bacsai605a630411f6
diff --git a/resources/views/livewire/project/database/backup-executions.blade.php b/resources/views/livewire/project/database/backup-executions.blade.php
index a361eb8d3a..c9be822e3c 100644
--- a/resources/views/livewire/project/database/backup-executions.blade.php
+++ b/resources/views/livewire/project/database/backup-executions.blade.php
@@ -24,7 +24,7 @@
<div class="flex-1"></div>
@if (data_get($execution, 'status') === 'success')
<x-forms.button class=" dark:hover:bg-coolgray-400"
- wire:click="download({{ data_get($execution, 'id') }})">Download</x-forms.button>
+ wire:click="download_file({{ data_get($execution, 'id') }})">Download</x-forms.button>
@endif
<x-modal-confirmation isErrorButton action="deleteBackup({{ data_get($execution, 'id') }})">
<x-slot:button-title>
diff --git a/routes/web.php b/routes/web.php
index c33e3b0eb4..ecc9d19984 100644
--- a/routes/web.php
+++ b/routes/web.php
@@ -46,7 +46,6 @@ use App\Livewire\Project\Application\Deployment\Show as DeploymentShow;
use App\Livewire\Project\Database\Configuration as DatabaseConfiguration;
use App\Livewire\Project\Database\Backup\Index as DatabaseBackupIndex;
use App\Livewire\Project\Database\Backup\Execution as DatabaseBackupExecution;
-
use App\Livewire\Project\Service\Configuration as ServiceConfiguration;
use App\Livewire\Project\Service\Index as ServiceIndex;
@@ -77,10 +76,62 @@ use App\Livewire\Tags\Show as TagsShow;
use App\Livewire\TeamSharedVariablesIndex;
use App\Livewire\Waitlist\Index as WaitlistIndex;
+use App\Models\ScheduledDatabaseBackupExecution;
+use Illuminate\Support\Facades\Storage;
+use Symfony\Component\HttpFoundation\StreamedResponse;
if (isDev()) {
Route::get('/dev/compose', Compose::class)->name('dev.compose');
}
+
+Route::get('/download/backup/{executionId}', function () {
+ try {
+ $team = auth()->user()->currentTeam();
+ $exeuctionId = request()->route('executionId');
+ $execution = ScheduledDatabaseBackupExecution::where('id', $exeuctionId)->firstOrFail();
+ // get team
+ if ($team->id !== $execution->scheduledDatabaseBackup->database->team()->id) {
+ abort(403);
+ }
+ if (is_null($execution)) {
+ $this->dispatch('error', 'Backup execution not found.');
+ return;
+ }
+ $filename = data_get($execution, 'filename');
+ if ($execution->scheduledDatabaseBackup->database->getMorphClass() === 'App\Models\ServiceDatabase') {
+ $server = $execution->scheduledDatabaseBackup->database->service->destination->server;
+ } else {
+ $server = $execution->scheduledDatabaseBackup->database->destination->server;
+ }
+ $privateKeyLocation = savePrivateKeyToFs($server);
+ $disk = Storage::build([
+ 'driver' => 'sftp',
+ 'host' => $server->ip,
+ 'port' => $server->port,
+ 'username' => $server->user,
+ 'privateKey' => $privateKeyLocation,
+ ]);
+ return new StreamedResponse(function () use ($disk, $filename) {
+ if (ob_get_level()) ob_end_clean();
+ $stream = $disk->readStream($filename);
+ if ($stream === false) {
+ abort(500, 'Failed to open stream for the requested file.');
+ }
+ while (!feof($stream)) {
+ echo fread($stream, 2048);
+ flush();
+ }
+
+ fclose($stream);
+ }, 200, [
+ 'Content-Type' => 'application/octet-stream',
+ 'Content-Disposition' => 'attachment; filename="' . basename($filename) . '"',
+ ]);
+ } catch (\Throwable $e) {
+ throw $e;
+ }
+})->name('download.backup');
+
Route::get('/admin', AdminIndex::class)->name('admin.index');
Route::post('/forgot-password', [Controller::class, 'forgot_password'])->name('password.forgot');