mirror of
https://github.com/vitodeploy/vito.git
synced 2025-07-05 07:52:34 +00:00
Merge (#127)
This commit is contained in:
13
app/SSH/Storage/AbstractStorage.php
Normal file
13
app/SSH/Storage/AbstractStorage.php
Normal file
@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
namespace App\SSH\Storage;
|
||||
|
||||
use App\Models\Server;
|
||||
use App\Models\StorageProvider;
|
||||
|
||||
abstract class AbstractStorage implements Storage
|
||||
{
|
||||
public function __construct(protected Server $server, protected StorageProvider $storageProvider)
|
||||
{
|
||||
}
|
||||
}
|
47
app/SSH/Storage/Dropbox.php
Normal file
47
app/SSH/Storage/Dropbox.php
Normal file
@ -0,0 +1,47 @@
|
||||
<?php
|
||||
|
||||
namespace App\SSH\Storage;
|
||||
|
||||
use App\Exceptions\SSHCommandError;
|
||||
use App\SSH\HasScripts;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
class Dropbox extends AbstractStorage
|
||||
{
|
||||
use HasScripts;
|
||||
|
||||
public function upload(string $src, string $dest): array
|
||||
{
|
||||
$upload = $this->server->ssh()->exec(
|
||||
$this->getScript('dropbox/upload.sh', [
|
||||
'src' => $src,
|
||||
'dest' => $dest,
|
||||
'token' => $this->storageProvider->credentials['token'],
|
||||
]),
|
||||
'upload-to-dropbox'
|
||||
);
|
||||
|
||||
$data = json_decode($upload, true);
|
||||
|
||||
if (isset($data['error'])) {
|
||||
Log::error('Failed to upload to Dropbox', $data);
|
||||
throw new SSHCommandError('Failed to upload to Dropbox');
|
||||
}
|
||||
|
||||
return [
|
||||
'size' => $data['size'] ?? null,
|
||||
];
|
||||
}
|
||||
|
||||
public function download(string $src, string $dest): void
|
||||
{
|
||||
$this->server->ssh()->exec(
|
||||
$this->getScript('dropbox/download.sh', [
|
||||
'src' => $src,
|
||||
'dest' => $dest,
|
||||
'token' => $this->storageProvider->credentials['token'],
|
||||
]),
|
||||
'download-from-dropbox'
|
||||
);
|
||||
}
|
||||
}
|
48
app/SSH/Storage/FTP.php
Normal file
48
app/SSH/Storage/FTP.php
Normal file
@ -0,0 +1,48 @@
|
||||
<?php
|
||||
|
||||
namespace App\SSH\Storage;
|
||||
|
||||
use App\SSH\HasScripts;
|
||||
|
||||
class FTP extends AbstractStorage
|
||||
{
|
||||
use HasScripts;
|
||||
|
||||
public function upload(string $src, string $dest): array
|
||||
{
|
||||
$this->server->ssh()->exec(
|
||||
$this->getScript('ftp/upload.sh', [
|
||||
'src' => $src,
|
||||
'dest' => $this->storageProvider->credentials['path'].'/'.$dest,
|
||||
'host' => $this->storageProvider->credentials['host'],
|
||||
'port' => $this->storageProvider->credentials['port'],
|
||||
'username' => $this->storageProvider->credentials['username'],
|
||||
'password' => $this->storageProvider->credentials['password'],
|
||||
'ssl' => $this->storageProvider->credentials['ssl'],
|
||||
'passive' => $this->storageProvider->credentials['passive'],
|
||||
]),
|
||||
'upload-to-ftp'
|
||||
);
|
||||
|
||||
return [
|
||||
'size' => null,
|
||||
];
|
||||
}
|
||||
|
||||
public function download(string $src, string $dest): void
|
||||
{
|
||||
$this->server->ssh()->exec(
|
||||
$this->getScript('ftp/download.sh', [
|
||||
'src' => $this->storageProvider->credentials['path'].'/'.$src,
|
||||
'dest' => $dest,
|
||||
'host' => $this->storageProvider->credentials['host'],
|
||||
'port' => $this->storageProvider->credentials['port'],
|
||||
'username' => $this->storageProvider->credentials['username'],
|
||||
'password' => $this->storageProvider->credentials['password'],
|
||||
'ssl' => $this->storageProvider->credentials['ssl'],
|
||||
'passive' => $this->storageProvider->credentials['passive'],
|
||||
]),
|
||||
'download-from-ftp'
|
||||
);
|
||||
}
|
||||
}
|
10
app/SSH/Storage/Storage.php
Normal file
10
app/SSH/Storage/Storage.php
Normal file
@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
namespace App\SSH\Storage;
|
||||
|
||||
interface Storage
|
||||
{
|
||||
public function upload(string $src, string $dest): array;
|
||||
|
||||
public function download(string $src, string $dest): void;
|
||||
}
|
4
app/SSH/Storage/scripts/dropbox/download.sh
Normal file
4
app/SSH/Storage/scripts/dropbox/download.sh
Normal file
@ -0,0 +1,4 @@
|
||||
curl -o __dest__ --location --request POST 'https://content.dropboxapi.com/2/files/download' \
|
||||
--header 'Accept: application/json' \
|
||||
--header 'Dropbox-API-Arg: {"path":"__src__"}' \
|
||||
--header 'Authorization: Bearer __token__'
|
6
app/SSH/Storage/scripts/dropbox/upload.sh
Normal file
6
app/SSH/Storage/scripts/dropbox/upload.sh
Normal file
@ -0,0 +1,6 @@
|
||||
curl -sb --location --request POST 'https://content.dropboxapi.com/2/files/upload' \
|
||||
--header 'Accept: application/json' \
|
||||
--header 'Dropbox-API-Arg: {"path":"__dest__"}' \
|
||||
--header 'Content-Type: text/plain; charset=dropbox-cors-hack' \
|
||||
--header 'Authorization: Bearer __token__' \
|
||||
--data-binary '@__src__'
|
1
app/SSH/Storage/scripts/ftp/download.sh
Normal file
1
app/SSH/Storage/scripts/ftp/download.sh
Normal file
@ -0,0 +1 @@
|
||||
curl __passive__ -u "__username__:__password__" ftp__ssl__://__host__:__port__/__src__ -o "__dest__"
|
1
app/SSH/Storage/scripts/ftp/upload.sh
Normal file
1
app/SSH/Storage/scripts/ftp/upload.sh
Normal file
@ -0,0 +1 @@
|
||||
curl __passive__ -T "__src__" -u "__username__:__password__" ftp__ssl__://__host__:__port__/__dest__
|
Reference in New Issue
Block a user