file attachment fix
This commit is contained in:
+12
-10
@@ -626,16 +626,18 @@ export const cleanupNoteAttachments = async (noteId: string) => {
|
||||
if (!pb.authStore.isValid) return;
|
||||
|
||||
try {
|
||||
const note = store.notes.find(n => n.id === noteId);
|
||||
if (!note) return;
|
||||
|
||||
const record = await pb.collection(NOTES_COLLECTION).getOne(noteId);
|
||||
if (!record.attachments || record.attachments.length === 0) return;
|
||||
|
||||
const content = note.content || "";
|
||||
const content = record.content || "";
|
||||
const filesToDelete: string[] = [];
|
||||
|
||||
// Also check decoded content just in case of encoding mismatches
|
||||
const decodedContent = decodeURIComponent(content);
|
||||
|
||||
for (const filename of record.attachments) {
|
||||
if (!content.includes(filename)) {
|
||||
// Check for literal filename OR the part of the URL that includes the filename
|
||||
if (!content.includes(filename) && !decodedContent.includes(filename)) {
|
||||
filesToDelete.push(filename);
|
||||
}
|
||||
}
|
||||
@@ -655,16 +657,16 @@ export const cleanupTaskAttachments = async (taskId: string) => {
|
||||
if (!pb.authStore.isValid) return;
|
||||
|
||||
try {
|
||||
const task = store.tasks.find(t => t.id === taskId);
|
||||
if (!task) return;
|
||||
|
||||
const record = await pb.collection(TASGRID_COLLECTION).getOne(taskId);
|
||||
if (!record.attachments || record.attachments.length === 0) return;
|
||||
|
||||
const content = task.content || "";
|
||||
const content = record.content || "";
|
||||
const filesToDelete: string[] = [];
|
||||
|
||||
const decodedContent = decodeURIComponent(content);
|
||||
|
||||
for (const filename of record.attachments) {
|
||||
if (!content.includes(filename)) {
|
||||
if (!content.includes(filename) && !decodedContent.includes(filename)) {
|
||||
filesToDelete.push(filename);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user