mirror of
https://github.com/zadam/trilium.git
synced 2025-10-20 07:08:55 +02:00
feat(views): delete duplicate attachments
This commit is contained in:
parent
7b1c058d29
commit
ce33dfb003
@ -26,17 +26,18 @@ export default class ViewModeStorage<T extends object> {
|
||||
}
|
||||
|
||||
async restore() {
|
||||
const existingAttachments = await this.note.getAttachmentsByRole(ATTACHMENT_ROLE);
|
||||
const existingAttachments = (await this.note.getAttachmentsByRole(ATTACHMENT_ROLE))
|
||||
.filter(a => a.title === this.attachmentName);
|
||||
if (existingAttachments.length === 0) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
const attachment = existingAttachments
|
||||
.find(a => a.title === this.attachmentName);
|
||||
if (!attachment) {
|
||||
return undefined;
|
||||
if (existingAttachments.length > 1) {
|
||||
// Clean up duplicates.
|
||||
await Promise.all(existingAttachments.slice(1).map(async a => await server.remove(`attachments/${a.attachmentId}`)));
|
||||
}
|
||||
|
||||
const attachment = existingAttachments[0];
|
||||
const attachmentData = await server.get<{ content: string } | null>(`attachments/${attachment.attachmentId}/blob`);
|
||||
return JSON.parse(attachmentData?.content ?? "{}") as T;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user