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,
|
file.path,
|
||||||
);
|
);
|
||||||
|
|
||||||
// For web, use the download URL with the base URL
|
// For web, use the download URL with the ApiClient base URL (from DI)
|
||||||
final baseUrl = 'https://go.b0esche.cloud'; // Should come from config
|
final fullUrl = '${fileService.baseUrl}$downloadUrl';
|
||||||
final fullUrl = '$baseUrl$downloadUrl';
|
|
||||||
|
|
||||||
// Trigger download via anchor element
|
// Trigger download via anchor element
|
||||||
html.AnchorElement(href: fullUrl)
|
html.AnchorElement(href: fullUrl)
|
||||||
|
|||||||
@@ -38,6 +38,8 @@ class ApiClient {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
String get baseUrl => _dio.options.baseUrl;
|
||||||
|
|
||||||
String? _getCurrentToken() {
|
String? _getCurrentToken() {
|
||||||
// Get from SessionBloc state
|
// Get from SessionBloc state
|
||||||
final state = _sessionBloc.state;
|
final state = _sessionBloc.state;
|
||||||
|
|||||||
@@ -10,6 +10,8 @@ class FileService {
|
|||||||
|
|
||||||
FileService(this._apiClient);
|
FileService(this._apiClient);
|
||||||
|
|
||||||
|
String get baseUrl => _apiClient.baseUrl;
|
||||||
|
|
||||||
Future<List<FileItem>> getFiles(String orgId, String path) async {
|
Future<List<FileItem>> getFiles(String orgId, String path) async {
|
||||||
if (path.isEmpty) {
|
if (path.isEmpty) {
|
||||||
throw Exception('Path cannot be empty');
|
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
|
// Delete from Nextcloud if configured
|
||||||
if storageClient != nil {
|
if storageClient != nil {
|
||||||
rel := strings.TrimPrefix(req.Path, "/")
|
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 {
|
if err := storageClient.Delete(r.Context(), remotePath); err != nil {
|
||||||
errors.LogError(r, err, "Failed to delete from Nextcloud (continuing anyway)")
|
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
|
// Try to download from Nextcloud first
|
||||||
if storageClient != nil {
|
if storageClient != nil {
|
||||||
rel := strings.TrimPrefix(filePath, "/")
|
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)
|
reader, size, err := storageClient.Download(r.Context(), remotePath)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
|
|||||||
Reference in New Issue
Block a user