nextcloud connessione ok gdrive no
This commit is contained in:
@@ -9,6 +9,7 @@ use App\Services\StorageRepositoryService;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Illuminate\View\View;
|
||||
use Symfony\Component\HttpFoundation\StreamedResponse;
|
||||
|
||||
@@ -112,18 +113,36 @@ class StorageRepositoryController extends Controller
|
||||
$this->authorizeRead('documenti');
|
||||
|
||||
$path = $request->get('path', '/');
|
||||
$contents = $this->repoService->listContents($storageRepository, $path);
|
||||
|
||||
try {
|
||||
if (!$storageRepository->is_active) {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Repository non attivo',
|
||||
'contents' => []
|
||||
], 400);
|
||||
}
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'contents' => $contents,
|
||||
'path' => $path,
|
||||
'repository' => [
|
||||
'id' => $storageRepository->id,
|
||||
'nome' => $storageRepository->nome,
|
||||
'tipo' => $storageRepository->tipo,
|
||||
],
|
||||
]);
|
||||
$contents = $this->repoService->listContents($storageRepository, $path);
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'contents' => $contents,
|
||||
'path' => $path,
|
||||
'repository' => [
|
||||
'id' => $storageRepository->id,
|
||||
'nome' => $storageRepository->nome,
|
||||
'tipo' => $storageRepository->tipo,
|
||||
],
|
||||
]);
|
||||
} catch (\Exception $e) {
|
||||
Log::error("StorageRepository browse failed for repo #{$storageRepository->id}: " . $e->getMessage());
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Errore: ' . $e->getMessage(),
|
||||
'contents' => []
|
||||
], 500);
|
||||
}
|
||||
}
|
||||
|
||||
public function reorder(Request $request): JsonResponse
|
||||
|
||||
@@ -18,6 +18,12 @@ class StorageRepositoryService
|
||||
{
|
||||
try {
|
||||
$config = $repo->getDecryptedConfig();
|
||||
// Log only the keys of the config (avoid sensitive values)
|
||||
try {
|
||||
Log::debug("StorageRepository: config keys for repo #{$repo->id}: " . json_encode(array_keys($config)));
|
||||
} catch (\Exception) {
|
||||
// ignore logging errors
|
||||
}
|
||||
|
||||
return match ($repo->tipo) {
|
||||
'webdav' => $this->buildWebDAV($config),
|
||||
@@ -76,16 +82,27 @@ class StorageRepositoryService
|
||||
$items = $filesystem->listContents($normalizedPath, false)->toArray();
|
||||
$result = [];
|
||||
foreach ($items as $item) {
|
||||
$path = method_exists($item, 'path') ? $item->path() : (is_array($item) && isset($item['path']) ? $item['path'] : null);
|
||||
$type = method_exists($item, 'type') ? $item->type() : (is_array($item) && isset($item['type']) ? $item['type'] : null);
|
||||
$basename = $path ? basename($path) : '';
|
||||
$lastModified = method_exists($item, 'lastModified') ? $item->lastModified() : (is_array($item) && isset($item['lastmodified']) ? $item['lastmodified'] : null);
|
||||
$fileSize = method_exists($item, 'fileSize') ? $item->fileSize() : (is_array($item) && isset($item['filesize']) ? $item['filesize'] : null);
|
||||
$mimeType = method_exists($item, 'mimeType') ? $item->mimeType() : (is_array($item) && isset($item['mimetype']) ? $item['mimetype'] : null);
|
||||
|
||||
$result[] = [
|
||||
'path' => $item->path(),
|
||||
'type' => $item->type(),
|
||||
'basename' => basename($item->path()),
|
||||
'lastModified' => $item->lastModified(),
|
||||
'fileSize' => $item->fileSize(),
|
||||
'mimeType' => $item->mimeType(),
|
||||
'path' => $path,
|
||||
'type' => $type,
|
||||
'basename' => $basename,
|
||||
'lastModified' => $lastModified,
|
||||
'fileSize' => $fileSize,
|
||||
'mimeType' => $mimeType,
|
||||
];
|
||||
}
|
||||
usort($result, fn($a, $b) => $a['type'] === 'dir' && $b['type'] !== 'dir' ? -1 : ($b['type'] === 'dir' && $a['type'] !== 'dir' ? 1 : strcasecmp($a['basename'], $b['basename'])));
|
||||
|
||||
usort($result, fn($a, $b) => ($a['type'] === 'dir' && $b['type'] !== 'dir') ? -1 : (($b['type'] === 'dir' && $a['type'] !== 'dir') ? 1 : strcasecmp($a['basename'], $b['basename'])));
|
||||
|
||||
Log::debug("StorageRepository: listContents repo #{$repo->id} tipo={$repo->tipo} path='{$normalizedPath}' results=" . count($result));
|
||||
|
||||
return $result;
|
||||
} catch (\Exception $e) {
|
||||
Log::error("StorageRepository: listContents failed for repo #{$repo->id} path '{$path}': " . $e->getMessage());
|
||||
@@ -160,12 +177,16 @@ class StorageRepositoryService
|
||||
$client = new \Google_Client();
|
||||
$client->setClientId($config['client_id']);
|
||||
$client->setClientSecret($config['client_secret']);
|
||||
$client->refreshToken($config['refresh_token']);
|
||||
$client->addScope(\Google_Service_Drive::DRIVE);
|
||||
|
||||
// Refresh token per ottenere un access token valido
|
||||
$token = $client->refreshToken($config['refresh_token']);
|
||||
$client->setAccessToken($token);
|
||||
|
||||
$service = new \Google_Service_Drive($client);
|
||||
|
||||
$adapter = new GoogleDriveAdapter($service, $config['root_folder_id'] ?? 'root');
|
||||
$rootFolderId = $config['root_folder_id'] ?? 'root';
|
||||
$adapter = new GoogleDriveAdapter($service, $rootFolderId);
|
||||
|
||||
return new Filesystem($adapter);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user