mirror of
https://github.com/zadam/trilium.git
synced 2025-10-02 11:35:41 +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() {
|
||||
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…
Add table
Reference in a new issue