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 {