mirror of
https://github.com/vitodeploy/vito.git
synced 2025-07-02 14:36:17 +00:00
local storage driver & some icon fixes (#187)
This commit is contained in:
@ -7,4 +7,6 @@ final class StorageProvider
|
||||
const DROPBOX = 'dropbox';
|
||||
|
||||
const FTP = 'ftp';
|
||||
|
||||
const LOCAL = 'local';
|
||||
}
|
||||
|
@ -78,6 +78,13 @@ public function destroyFile(Server $server, Backup $backup, BackupFile $backupFi
|
||||
|
||||
$backupFile->delete();
|
||||
|
||||
$backupFile
|
||||
->backup
|
||||
->storage
|
||||
->provider()
|
||||
->ssh($server)
|
||||
->delete($backupFile->storagePath());
|
||||
|
||||
Toast::success('Backup file deleted successfully.');
|
||||
|
||||
return back();
|
||||
|
@ -159,7 +159,7 @@ public function runBackup(BackupFile $backupFile): void
|
||||
);
|
||||
|
||||
// cleanup
|
||||
$this->service->server->ssh()->exec('rm '.$backupFile->name.'.zip');
|
||||
$this->service->server->ssh()->exec('rm '.$backupFile->path());
|
||||
|
||||
$backupFile->size = $upload['size'];
|
||||
$backupFile->save();
|
||||
|
@ -44,4 +44,12 @@ public function download(string $src, string $dest): void
|
||||
'download-from-dropbox'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @TODO Implement delete method
|
||||
*/
|
||||
public function delete(string $path): void
|
||||
{
|
||||
//
|
||||
}
|
||||
}
|
||||
|
@ -45,4 +45,12 @@ public function download(string $src, string $dest): void
|
||||
'download-from-ftp'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @TODO Implement delete method
|
||||
*/
|
||||
public function delete(string $path): void
|
||||
{
|
||||
//
|
||||
}
|
||||
}
|
||||
|
49
app/SSH/Storage/Local.php
Normal file
49
app/SSH/Storage/Local.php
Normal file
@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
namespace App\SSH\Storage;
|
||||
|
||||
use App\SSH\HasScripts;
|
||||
|
||||
class Local extends AbstractStorage
|
||||
{
|
||||
use HasScripts;
|
||||
|
||||
public function upload(string $src, string $dest): array
|
||||
{
|
||||
$destDir = dirname($this->storageProvider->credentials['path'].$dest);
|
||||
$destFile = basename($this->storageProvider->credentials['path'].$dest);
|
||||
$this->server->ssh()->exec(
|
||||
$this->getScript('local/upload.sh', [
|
||||
'src' => $src,
|
||||
'dest_dir' => $destDir,
|
||||
'dest_file' => $destFile,
|
||||
]),
|
||||
'upload-to-local'
|
||||
);
|
||||
|
||||
return [
|
||||
'size' => null,
|
||||
];
|
||||
}
|
||||
|
||||
public function download(string $src, string $dest): void
|
||||
{
|
||||
$this->server->ssh()->exec(
|
||||
$this->getScript('local/download.sh', [
|
||||
'src' => $this->storageProvider->credentials['path'].$src,
|
||||
'dest' => $dest,
|
||||
]),
|
||||
'download-from-local'
|
||||
);
|
||||
}
|
||||
|
||||
public function delete(string $path): void
|
||||
{
|
||||
$this->server->ssh()->exec(
|
||||
$this->getScript('local/delete.sh', [
|
||||
'path' => $this->storageProvider->credentials['path'].$path,
|
||||
]),
|
||||
'delete-from-local'
|
||||
);
|
||||
}
|
||||
}
|
@ -7,4 +7,6 @@ interface Storage
|
||||
public function upload(string $src, string $dest): array;
|
||||
|
||||
public function download(string $src, string $dest): void;
|
||||
|
||||
public function delete(string $path): void;
|
||||
}
|
||||
|
1
app/SSH/Storage/scripts/local/delete.sh
Normal file
1
app/SSH/Storage/scripts/local/delete.sh
Normal file
@ -0,0 +1 @@
|
||||
rm __path__
|
1
app/SSH/Storage/scripts/local/download.sh
Normal file
1
app/SSH/Storage/scripts/local/download.sh
Normal file
@ -0,0 +1 @@
|
||||
cp __src__ __dest__
|
2
app/SSH/Storage/scripts/local/upload.sh
Normal file
2
app/SSH/Storage/scripts/local/upload.sh
Normal file
@ -0,0 +1,2 @@
|
||||
mkdir -p __dest_dir__
|
||||
cp __src__ __dest_dir__/__dest_file__
|
38
app/StorageProviders/Local.php
Normal file
38
app/StorageProviders/Local.php
Normal file
@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
namespace App\StorageProviders;
|
||||
|
||||
use App\Models\Server;
|
||||
use App\SSH\Storage\Storage;
|
||||
|
||||
class Local extends AbstractStorageProvider
|
||||
{
|
||||
public function validationRules(): array
|
||||
{
|
||||
return [
|
||||
'path' => 'required',
|
||||
];
|
||||
}
|
||||
|
||||
public function credentialData(array $input): array
|
||||
{
|
||||
return [
|
||||
'path' => $input['path'],
|
||||
];
|
||||
}
|
||||
|
||||
public function connect(): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public function ssh(Server $server): Storage
|
||||
{
|
||||
return new \App\SSH\Storage\Local($server, $this->storageProvider);
|
||||
}
|
||||
|
||||
public function delete(array $paths): void
|
||||
{
|
||||
//
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user