Refactor file download URL construction to use ApiClient's base URL and ensure consistent remote path for user files
This commit is contained in:
@@ -271,9 +271,8 @@ class _FileExplorerState extends State<FileExplorer> {
|
||||
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)
|
||||
|
||||
@@ -38,6 +38,8 @@ class ApiClient {
|
||||
);
|
||||
}
|
||||
|
||||
String get baseUrl => _dio.options.baseUrl;
|
||||
|
||||
String? _getCurrentToken() {
|
||||
// Get from SessionBloc state
|
||||
final state = _sessionBloc.state;
|
||||
|
||||
@@ -10,6 +10,8 @@ class FileService {
|
||||
|
||||
FileService(this._apiClient);
|
||||
|
||||
String get baseUrl => _apiClient.baseUrl;
|
||||
|
||||
Future<List<FileItem>> getFiles(String orgId, String path) async {
|
||||
if (path.isEmpty) {
|
||||
throw Exception('Path cannot be empty');
|
||||
|
||||
@@ -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/<userID>/<rel>"
|
||||
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/<userID>/<rel>"
|
||||
remotePath := path.Join("/users", userID.String(), rel)
|
||||
|
||||
reader, size, err := storageClient.Download(r.Context(), remotePath)
|
||||
if err == nil {
|
||||
|
||||
Reference in New Issue
Block a user