modifica - da terminare gestioen doc remoti - resto ok

This commit is contained in:
2026-05-28 13:25:47 +02:00
parent f2b0833b90
commit 4a3051faff
122 changed files with 445 additions and 15819 deletions
+41 -11
View File
@@ -33,6 +33,14 @@ class StorageRepositoryService
public function testConnection(StorageRepository $repo): array
{
try {
$config = $repo->getDecryptedConfig();
if ($repo->tipo === 'google_drive') {
if (empty($config['client_id']) || empty($config['client_secret']) || empty($config['refresh_token'])) {
return ['success' => false, 'message' => 'Configurazione incompleta: client_id, client_secret e refresh_token sono necessari per Google Drive.'];
}
}
$filesystem = $this->buildFilesystem($repo);
if (!$filesystem) {
return ['success' => false, 'message' => 'Impossibile costruire il filesystem per questo tipo di repository.'];
@@ -49,12 +57,21 @@ class StorageRepositoryService
public function listContents(StorageRepository $repo, string $path = '/'): array
{
$filesystem = $this->buildFilesystem($repo);
if (!$filesystem) {
return [];
}
try {
$config = $repo->getDecryptedConfig();
if ($repo->tipo === 'google_drive') {
if (empty($config['client_id']) || empty($config['client_secret']) || empty($config['refresh_token'])) {
Log::warning("StorageRepository: listContents failed for repo #{$repo->id} ({$repo->nome}): credenziali Google Drive mancanti");
return [];
}
}
$filesystem = $this->buildFilesystem($repo);
if (!$filesystem) {
return [];
}
$normalizedPath = $this->normalizePath($path);
$items = $filesystem->listContents($normalizedPath, false)->toArray();
$result = [];
@@ -76,7 +93,7 @@ class StorageRepositoryService
}
}
public function encryptSensitiveConfig(array $config, string $tipo): array
public function encryptSensitiveConfig(array $config, string $tipo, array $existingConfig = []): array
{
$sensitiveFields = match ($tipo) {
'webdav' => ['password'],
@@ -87,6 +104,8 @@ class StorageRepositoryService
foreach ($sensitiveFields as $field) {
if (!empty($config[$field]) && !$this->isEncrypted($config[$field])) {
$config[$field] = Crypt::encryptString($config[$field]);
} elseif (empty($config[$field]) && !empty($existingConfig[$field])) {
$config[$field] = $existingConfig[$field];
}
}
@@ -100,7 +119,7 @@ class StorageRepositoryService
return '';
}
if ($path === '/') {
return '/';
return '';
}
return ltrim($path, '/\\');
}
@@ -112,11 +131,18 @@ class StorageRepositoryService
private function buildWebDAV(array $config): ?Filesystem
{
$authType = match ($config['auth_type'] ?? 'basic') {
'basic' => WebDAVClient::AUTH_BASIC,
'digest' => WebDAVClient::AUTH_DIGEST,
'ntlm' => WebDAVClient::AUTH_NTLM,
default => WebDAVClient::AUTH_BASIC,
};
$client = new WebDAVClient([
'baseUri' => rtrim($config['base_uri'] ?? '', '/') . '/',
'userName' => $config['username'] ?? '',
'password' => $config['password'] ?? '',
'authType' => $config['auth_type'] ?? 'basic',
'authType' => $authType,
]);
$root = ltrim($config['root'] ?? '/', '/');
@@ -127,10 +153,14 @@ class StorageRepositoryService
private function buildGoogleDrive(array $config): ?Filesystem
{
if (empty($config['client_id']) || empty($config['client_secret']) || empty($config['refresh_token'])) {
throw new \InvalidArgumentException('Google Drive richiede client_id, client_secret e refresh_token per l\'autenticazione.');
}
$client = new \Google_Client();
$client->setClientId($config['client_id'] ?? '');
$client->setClientSecret($config['client_secret'] ?? '');
$client->refreshToken($config['refresh_token'] ?? '');
$client->setClientId($config['client_id']);
$client->setClientSecret($config['client_secret']);
$client->refreshToken($config['refresh_token']);
$client->addScope(\Google_Service_Drive::DRIVE);
$service = new \Google_Service_Drive($client);