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.
This commit is contained in:
drelich
2026-03-26 10:02:36 +01:00
parent b31f974411
commit 1d15a39b4c

View File

@@ -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 {