From 1d15a39b4c53b3f3b9ed797e82c22ed647526663 Mon Sep 17 00:00:00 2001 From: drelich Date: Thu, 26 Mar 2026 10:02:36 +0100 Subject: [PATCH] Fix attachment folder sanitization to match upload logic The sanitization regex was inconsistent between uploadAttachment and moveNoteWebDAV. Upload uses /[^a-zA-Z0-9_-]/g which replaces spaces with underscores, but move was using /[^\w\s-]/g which kept spaces. This caused 404 errors when trying to move attachment folders. --- src/api/nextcloud.ts | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/api/nextcloud.ts b/src/api/nextcloud.ts index 8d00132..6c03367 100644 --- a/src/api/nextcloud.ts +++ b/src/api/nextcloud.ts @@ -512,12 +512,17 @@ export class NextcloudAPI { // Move attachment folder if it exists const noteIdStr = String(note.id); const justFilename = noteIdStr.split('/').pop() || noteIdStr; - const sanitizedNoteId = justFilename.replace(/\.(md|txt)$/, '').replace(/[^\w\s-]/g, '_'); + const filenameWithoutExt = justFilename.replace(/\.(md|txt)$/, ''); + const sanitizedNoteId = filenameWithoutExt.replace(/[^a-zA-Z0-9_-]/g, '_'); const attachmentFolder = `.attachments.${sanitizedNoteId}`; const oldAttachmentPath = `/remote.php/dav/files/${this.username}/Notes${oldCategoryPath}/${attachmentFolder}`; const newAttachmentPath = `/remote.php/dav/files/${this.username}/Notes${newCategoryPath}/${attachmentFolder}`; + console.log(`Attempting to move attachment folder:`); + console.log(` From: ${oldAttachmentPath}`); + console.log(` To: ${newAttachmentPath}`); + try { const attachmentResponse = await tauriFetch(`${this.serverURL}${oldAttachmentPath}`, { method: 'MOVE', @@ -527,12 +532,15 @@ export class NextcloudAPI { }, }); + console.log(`Attachment folder MOVE response status: ${attachmentResponse.status}`); + if (attachmentResponse.ok || attachmentResponse.status === 201 || attachmentResponse.status === 204) { - console.log(`Moved attachment folder: ${attachmentFolder}`); + console.log(`✓ Successfully moved attachment folder: ${attachmentFolder}`); + } else { + console.log(`✗ Failed to move attachment folder (status ${attachmentResponse.status})`); } } catch (e) { - // Attachment folder might not exist, that's okay - console.log(`No attachment folder to move for note: ${note.filename}`); + console.log(`✗ Error moving attachment folder:`, e); } return {