summary refs log tree commit diff
path: root/api/src/util/Attachments.ts
diff options
context:
space:
mode:
authorFlam3rboy <34555296+Flam3rboy@users.noreply.github.com>2021-09-14 13:18:32 +0200
committerFlam3rboy <34555296+Flam3rboy@users.noreply.github.com>2021-09-14 13:18:32 +0200
commit6c11224f69feb21bc909e7848f8a67ccda007f0a (patch)
tree32c4200457078cd6b2f46935ccccbc2d14dd1b0d /api/src/util/Attachments.ts
parent:bug: fix fosscord.js (diff)
parentMerge pull request #360 from AlTech98/invite (diff)
downloadserver-6c11224f69feb21bc909e7848f8a67ccda007f0a.tar.xz
Merge branch 'master' of https://github.com/fosscord/fosscord-api
Diffstat (limited to 'api/src/util/Attachments.ts')
-rw-r--r--api/src/util/Attachments.ts12
1 files changed, 12 insertions, 0 deletions
diff --git a/api/src/util/Attachments.ts b/api/src/util/Attachments.ts
new file mode 100644

index 00000000..addda97f --- /dev/null +++ b/api/src/util/Attachments.ts
@@ -0,0 +1,12 @@ +import { Attachment } from "@fosscord/util"; +import { deleteFile } from "@fosscord/api"; +import { URL } from "url"; + +export async function deleteMessageAttachments(messageId: string, keep?: Attachment[]) { + let attachments = await Attachment.find({ message_id: messageId }); + if (keep) + attachments = attachments.filter(x => !keep.map(k => k.id).includes(x.id)); + await Promise.all(attachments.map(a => a.remove())); + + attachments.forEach(a => deleteFile((new URL(a.url)).pathname)); //We don't need to await since this is done on the cdn +}