FIX: Simplify move handler and fix API call

This commit is contained in:
Leon Bösche
2026-01-11 23:39:15 +01:00
parent 60df1a38ff
commit 1680914017
2 changed files with 5 additions and 7 deletions

View File

@@ -161,13 +161,11 @@ class FileService {
String sourcePath,
String targetPath,
) async {
final response = await apiClient.post(
await _apiClient.post(
'/orgs/$orgId/files/move',
data: {'sourcePath': sourcePath, 'targetPath': targetPath},
fromJson: (d) => null,
);
if (response.statusCode != 200) {
throw Exception('Failed to move file: ${response.statusCode}');
}
}
Future<void> renameFile(String orgId, String path, String newName) async {

View File

@@ -1297,18 +1297,18 @@ func moveOrgFileHandler(w http.ResponseWriter, r *http.Request, db *database.DB,
// Get or create user's WebDAV client and move in Nextcloud
storageClient, err := getUserWebDAVClient(r.Context(), db, userID, cfg.NextcloudURL, cfg.NextcloudUser, cfg.NextcloudPass)
if err != nil {
errors.LogError(r, err, "Failed to get user WebDAV client (continuing with database move)")
errors.LogError(r, err, "Failed to get user WebDAV client (continuing with database operation)")
} else {
sourceRel := strings.TrimPrefix(req.SourcePath, "/")
sourcePath := path.Join("/orgs", orgID.String(), sourceRel)
targetRel := strings.TrimPrefix(req.TargetPath, "/")
targetPath := path.Join("/orgs", orgID.String(), targetRel)
if err := storageClient.Move(r.Context(), sourcePath, targetPath); err != nil {
errors.LogError(r, err, "Failed to move in Nextcloud (continuing with database move)")
errors.LogError(r, err, "Failed to move in Nextcloud (continuing with database operation)")
}
}
// Delete old file record from database - next sync will recreate with new path
// Delete old file record from database - file will be synced with new path from storage
if err := db.DeleteFileByPath(r.Context(), &orgID, nil, req.SourcePath); err != nil {
errors.LogError(r, err, "Failed to delete old file record")
}