From aac6d2eb462065d72491fad230e888059e370e71 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Leon=20B=C3=B6sche?= Date: Fri, 9 Jan 2026 23:01:11 +0100 Subject: [PATCH] Refactor file download URL construction to use ApiClient's base URL and ensure consistent remote path for user files --- b0esche_cloud/lib/pages/file_explorer.dart | 5 ++--- b0esche_cloud/lib/services/api_client.dart | 2 ++ b0esche_cloud/lib/services/file_service.dart | 2 ++ go_cloud/internal/http/routes.go | 6 ++++-- 4 files changed, 10 insertions(+), 5 deletions(-) diff --git a/b0esche_cloud/lib/pages/file_explorer.dart b/b0esche_cloud/lib/pages/file_explorer.dart index 128a9da..8c010d5 100644 --- a/b0esche_cloud/lib/pages/file_explorer.dart +++ b/b0esche_cloud/lib/pages/file_explorer.dart @@ -271,9 +271,8 @@ class _FileExplorerState extends State { file.path, ); - // For web, use the download URL with the base URL - final baseUrl = 'https://go.b0esche.cloud'; // Should come from config - final fullUrl = '$baseUrl$downloadUrl'; + // For web, use the download URL with the ApiClient base URL (from DI) + final fullUrl = '${fileService.baseUrl}$downloadUrl'; // Trigger download via anchor element html.AnchorElement(href: fullUrl) diff --git a/b0esche_cloud/lib/services/api_client.dart b/b0esche_cloud/lib/services/api_client.dart index 97da197..bfb4ad4 100644 --- a/b0esche_cloud/lib/services/api_client.dart +++ b/b0esche_cloud/lib/services/api_client.dart @@ -38,6 +38,8 @@ class ApiClient { ); } + String get baseUrl => _dio.options.baseUrl; + String? _getCurrentToken() { // Get from SessionBloc state final state = _sessionBloc.state; diff --git a/b0esche_cloud/lib/services/file_service.dart b/b0esche_cloud/lib/services/file_service.dart index 8711428..fe1812b 100644 --- a/b0esche_cloud/lib/services/file_service.dart +++ b/b0esche_cloud/lib/services/file_service.dart @@ -10,6 +10,8 @@ class FileService { FileService(this._apiClient); + String get baseUrl => _apiClient.baseUrl; + Future> getFiles(String orgId, String path) async { if (path.isEmpty) { throw Exception('Path cannot be empty'); diff --git a/go_cloud/internal/http/routes.go b/go_cloud/internal/http/routes.go index d12da6f..f3f6a7e 100644 --- a/go_cloud/internal/http/routes.go +++ b/go_cloud/internal/http/routes.go @@ -1234,7 +1234,8 @@ func deleteUserFileHandler(w http.ResponseWriter, r *http.Request, db *database. // Delete from Nextcloud if configured if storageClient != nil { rel := strings.TrimPrefix(req.Path, "/") - remotePath := path.Join("/user", userID.String(), rel) + // Keep remote user workspace path consistent with uploads: "/users//" + remotePath := path.Join("/users", userID.String(), rel) if err := storageClient.Delete(r.Context(), remotePath); err != nil { errors.LogError(r, err, "Failed to delete from Nextcloud (continuing anyway)") } @@ -1314,7 +1315,8 @@ func downloadUserFileHandler(w http.ResponseWriter, r *http.Request, db *databas // Try to download from Nextcloud first if storageClient != nil { rel := strings.TrimPrefix(filePath, "/") - remotePath := path.Join("/user", userID.String(), rel) + // Keep remote user workspace path consistent with uploads: "/users//" + remotePath := path.Join("/users", userID.String(), rel) reader, size, err := storageClient.Download(r.Context(), remotePath) if err == nil {