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:
@@ -512,12 +512,17 @@ export class NextcloudAPI {
|
|||||||
// Move attachment folder if it exists
|
// Move attachment folder if it exists
|
||||||
const noteIdStr = String(note.id);
|
const noteIdStr = String(note.id);
|
||||||
const justFilename = noteIdStr.split('/').pop() || noteIdStr;
|
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 attachmentFolder = `.attachments.${sanitizedNoteId}`;
|
||||||
|
|
||||||
const oldAttachmentPath = `/remote.php/dav/files/${this.username}/Notes${oldCategoryPath}/${attachmentFolder}`;
|
const oldAttachmentPath = `/remote.php/dav/files/${this.username}/Notes${oldCategoryPath}/${attachmentFolder}`;
|
||||||
const newAttachmentPath = `/remote.php/dav/files/${this.username}/Notes${newCategoryPath}/${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 {
|
try {
|
||||||
const attachmentResponse = await tauriFetch(`${this.serverURL}${oldAttachmentPath}`, {
|
const attachmentResponse = await tauriFetch(`${this.serverURL}${oldAttachmentPath}`, {
|
||||||
method: 'MOVE',
|
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) {
|
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) {
|
} catch (e) {
|
||||||
// Attachment folder might not exist, that's okay
|
console.log(`✗ Error moving attachment folder:`, e);
|
||||||
console.log(`No attachment folder to move for note: ${note.filename}`);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|||||||
Reference in New Issue
Block a user