diff options
author | Flam3rboy <34555296+Flam3rboy@users.noreply.github.com> | 2021-09-19 18:46:22 +0200 |
---|---|---|
committer | Flam3rboy <34555296+Flam3rboy@users.noreply.github.com> | 2021-09-19 18:46:22 +0200 |
commit | 313696d237cc614cca8f68d8a63ad3039d00baf9 (patch) | |
tree | ffee7dd8d0bcfd4fda2ad5c14238003d49b74f68 /util/src | |
parent | :bug: fix bundle debug (diff) | |
download | server-313696d237cc614cca8f68d8a63ad3039d00baf9.tar.xz |
:art: remove deleteMessageAttachments and move to entity
Diffstat (limited to 'util/src')
-rw-r--r-- | util/src/entities/Attachment.ts | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/util/src/entities/Attachment.ts b/util/src/entities/Attachment.ts index ca893400..82c5ecf5 100644 --- a/util/src/entities/Attachment.ts +++ b/util/src/entities/Attachment.ts @@ -1,4 +1,6 @@ -import { Column, Entity, JoinColumn, ManyToOne, RelationId } from "typeorm"; +import { BeforeRemove, Column, Entity, JoinColumn, ManyToOne, RelationId } from "typeorm"; +import { URL } from "url"; +import { deleteFile } from "../util/cdn"; import { BaseClass } from "./BaseClass"; @Entity("attachments") @@ -31,4 +33,9 @@ export class Attachment extends BaseClass { @JoinColumn({ name: "message_id" }) @ManyToOne(() => require("./Message").Message, (message: import("./Message").Message) => message.attachments) message: import("./Message").Message; + + @BeforeRemove() + onDelete() { + return deleteFile(new URL(this.url).pathname); + } } |