diff --git a/app/Http/Controllers/StorageRepositoryController.php b/app/Http/Controllers/StorageRepositoryController.php index 3e0e83f4..0394b9ef 100644 --- a/app/Http/Controllers/StorageRepositoryController.php +++ b/app/Http/Controllers/StorageRepositoryController.php @@ -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 diff --git a/app/Services/StorageRepositoryService.php b/app/Services/StorageRepositoryService.php index eaaf998d..ba5367a1 100644 --- a/app/Services/StorageRepositoryService.php +++ b/app/Services/StorageRepositoryService.php @@ -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); } diff --git a/resources/views/documenti/index.blade.php b/resources/views/documenti/index.blade.php index e2a85bbd..fc3bc0f0 100644 --- a/resources/views/documenti/index.blade.php +++ b/resources/views/documenti/index.blade.php @@ -1357,7 +1357,7 @@ function toggleUploadRepo() { } // === Remote Repository AJAX Browser === -let currentRepoBrowse = null; +var currentRepoBrowse = null; function showLocalContent() { document.getElementById('localContent').style.display = ''; @@ -1401,22 +1401,43 @@ function loadRemoteContents(repoId, path) { document.getElementById('remoteLoading').style.display = 'block'; const view = localStorage.getItem('documenti_view') || 'grid'; - fetch('/storage-repositories/' + repoId + '/browse?path=' + encodeURIComponent(path), { - headers: { 'Accept': 'application/json' } + const url = '/storage-repositories/' + repoId + '/browse?path=' + encodeURIComponent(path); + console.log('Loading remote contents from:', url); + + fetch(url, { + method: 'GET', + headers: { + 'Accept': 'application/json', + 'X-Requested-With': 'XMLHttpRequest' + } + }) + .then(response => { + console.log('Response status:', response.status); + if (!response.ok) { + throw new Error('HTTP Error: ' + response.status); + } + return response.json(); }) - .then(response => response.json()) .then(data => { + console.log('Data received:', data); document.getElementById('remoteLoading').style.display = 'none'; - if (data.success && data.contents) { + if (data.success && data.contents !== undefined) { + console.log('Contents count:', data.contents.length); renderRemoteContents(data.contents, repoId, path, view); + } else if (data.contents !== undefined && data.contents.length === 0) { + document.getElementById('remoteEmpty').style.display = 'block'; + document.getElementById('remoteEmpty').querySelector('p').textContent = 'Cartella vuota'; } else { document.getElementById('remoteEmpty').style.display = 'block'; - document.getElementById('remoteEmpty').querySelector('p').textContent = 'Errore caricamento repository.'; + const msg = data.message || 'Errore caricamento repository.'; + console.error('Error response:', msg); + document.getElementById('remoteEmpty').querySelector('p').textContent = msg; } }) .catch(error => { document.getElementById('remoteLoading').style.display = 'none'; document.getElementById('remoteEmpty').style.display = 'block'; + console.error('Fetch error:', error); document.getElementById('remoteEmpty').querySelector('p').textContent = 'Errore: ' + error.message; }); } diff --git a/storage/framework/views/14ee0174ec36b16b90e353b8b794befc.php b/storage/framework/views/14ee0174ec36b16b90e353b8b794befc.php new file mode 100755 index 00000000..3558885b --- /dev/null +++ b/storage/framework/views/14ee0174ec36b16b90e353b8b794befc.php @@ -0,0 +1,720 @@ +startSection('title', 'Modifica Individuo'); ?> +startSection('page_title', 'Modifica Individuo'); ?> + +startSection('content'); ?> +
+ +