mirror of
https://github.com/zadam/trilium.git
synced 2025-10-09 15:08:14 +08:00
feat(views): delete duplicate attachments
This commit is contained in:
parent
7b1c058d29
commit
ce33dfb003
1 changed files with 6 additions and 5 deletions
|
@ -26,17 +26,18 @@ export default class ViewModeStorage<T extends object> {
|
||||||
}
|
}
|
||||||
|
|
||||||
async restore() {
|
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) {
|
if (existingAttachments.length === 0) {
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
const attachment = existingAttachments
|
if (existingAttachments.length > 1) {
|
||||||
.find(a => a.title === this.attachmentName);
|
// Clean up duplicates.
|
||||||
if (!attachment) {
|
await Promise.all(existingAttachments.slice(1).map(async a => await server.remove(`attachments/${a.attachmentId}`)));
|
||||||
return undefined;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const attachment = existingAttachments[0];
|
||||||
const attachmentData = await server.get<{ content: string } | null>(`attachments/${attachment.attachmentId}/blob`);
|
const attachmentData = await server.get<{ content: string } | null>(`attachments/${attachment.attachmentId}/blob`);
|
||||||
return JSON.parse(attachmentData?.content ?? "{}") as T;
|
return JSON.parse(attachmentData?.content ?? "{}") as T;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue