mirror of
https://github.com/hcengineering/platform.git
synced 2025-04-13 11:50:56 +00:00
Prevent saving the same attachment twice (#5850)
Signed-off-by: Vyacheslav Tumanov <me@slavatumanov.me>
This commit is contained in:
parent
1c8bdb81f7
commit
e76316f18b
@ -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) {
|
||||
|
Loading…
Reference in New Issue
Block a user