Prevent saving the same attachment twice (#5850)

Signed-off-by: Vyacheslav Tumanov <me@slavatumanov.me>
This commit is contained in:
Vyacheslav Tumanov 2024-06-19 18:48:07 +05:00 committed by GitHub
parent 1c8bdb81f7
commit e76316f18b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -143,8 +143,25 @@
}
}
const existingAttachmentsQuery = createQuery()
let existingAttachments: Ref<Attachment>[] = []
$: existingAttachmentsQuery.query(
attachment.class.Attachment,
{
space,
attachedTo: objectId,
attachedToClass: _class,
_id: { $in: Array.from(attachments.keys()) }
},
(res) => {
existingAttachments = res.map((p) => p._id)
}
)
async function saveAttachment (doc: Attachment): Promise<void> {
await client.addCollection(attachment.class.Attachment, space, objectId, _class, 'attachments', doc, doc._id)
if (!existingAttachments.includes(doc._id)) {
await client.addCollection(attachment.class.Attachment, space, objectId, _class, 'attachments', doc, doc._id)
}
}
async function fileSelected (): Promise<void> {
@ -209,6 +226,9 @@
}
})
}
if (!saved && shouldSaveDraft) {
void createAttachments()
}
})
export function removeDraft (removeFiles: boolean) {