PhyrePanel-mirror/web/app/BackupStorage.php

48 lines
1.2 KiB
PHP
Raw Normal View History

2024-05-02 14:51:26 +00:00
<?php
namespace App;
use App\Models\Domain;
use Illuminate\Support\Facades\Storage;
use Illuminate\Support\Facades\URL;
use Illuminate\Support\Str;
class BackupStorage
{
public static function getPath()
{
2024-05-02 16:33:47 +00:00
$rootPath = '/var/lib/phyre/backups/system';
2024-05-02 14:51:26 +00:00
$customBackupPath = setting('general.backup_path');
if (!empty($customBackupPath)) {
$rootPath = $customBackupPath;
}
return $rootPath;
}
2024-05-02 15:38:42 +00:00
public static function getInstance($path = false)
2024-05-02 14:51:26 +00:00
{
$rootPath = self::getPath();
2024-05-02 15:38:42 +00:00
if ($path) {
$rootPath = $path;
}
2024-05-02 14:51:26 +00:00
$storageBuild = Storage::build([
'driver' => 'local',
'throw' => false,
'root' => $rootPath,
]);
2024-05-02 15:38:42 +00:00
$storageBuild->buildTemporaryUrlsUsing(function ($path, $expiration, $options) use($rootPath) {
2024-05-02 14:51:26 +00:00
return URL::temporarySignedRoute(
'backup.download',
$expiration,
2024-05-02 15:38:42 +00:00
array_merge($options, [
'path' => $path,
'root_path' => $rootPath,
])
2024-05-02 14:51:26 +00:00
);
});
return $storageBuild;
}
}