added attachment cleanup in tasks
This commit is contained in:
@@ -552,6 +552,35 @@ export const cleanupNoteAttachments = async (noteId: string) => {
|
||||
}
|
||||
};
|
||||
|
||||
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 filesToDelete: string[] = [];
|
||||
for (const filename of record.attachments) {
|
||||
if (!content.includes(filename)) {
|
||||
filesToDelete.push(filename);
|
||||
}
|
||||
}
|
||||
|
||||
if (filesToDelete.length > 0) {
|
||||
await pb.collection(TASGRID_COLLECTION).update(taskId, {
|
||||
"attachments-": filesToDelete
|
||||
});
|
||||
console.log(`[CLEANUP] Deleted ${filesToDelete.length} orphaned attachment(s) for task ${taskId}`);
|
||||
}
|
||||
} catch (err) {
|
||||
console.error("[CLEANUP] Failed to clean up orphaned task attachments:", err);
|
||||
}
|
||||
};
|
||||
|
||||
const mapRecordToShareRule = (r: any): ShareRule => {
|
||||
return {
|
||||
id: r.id,
|
||||
|
||||
Reference in New Issue
Block a user