refactoring (#116)

- refactoring architecture
- fix incomplete ssh logs
- code editor for scripts in the app
- remove Jobs and SSHCommands
This commit is contained in:
Saeed Vaziry
2024-03-14 20:03:43 +01:00
committed by GitHub
parent cee4a70c3c
commit 428140b931
472 changed files with 24110 additions and 8159 deletions

View 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)
{
}
}

View File

@ -0,0 +1,45 @@
<?php
namespace App\SSH\Storage;
use App\Exceptions\SSHCommandError;
use App\SSH\HasScripts;
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'])) {
throw new SSHCommandError('Failed to upload to Dropbox '.$data['error']);
}
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
View 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'
);
}
}

View 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;
}

View 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__'

View 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__'

View File

@ -0,0 +1 @@
curl __passive__ -u "__username__:__password__" ftp__ssl__://__host__:__port__/__src__ -o "__dest__"

View File

@ -0,0 +1 @@
curl __passive__ -T "__src__" -u "__username__:__password__" ftp__ssl__://__host__:__port__/__dest__