import { BeforeRemove , Column , Entity , JoinColumn , ManyToOne , RelationId } from "typeorm" ; import { URL } from "url" ; import { deleteFile } from "../util/cdn" ; import { BaseClass } from "./BaseClass" ; @ Entity ( "attachments" ) export class Attachment extends BaseClass { @ Column ( ) filename : string ; @ Column ( ) size : number ; @ Column ( ) url : string ; @ Column ( ) proxy_url : string ; @ Column ( { nullable : true } ) height ? : number ; @ Column ( { nullable : true } ) width ? : number ; @ Column ( { nullable : true } ) content_type ? : string ; @ Column ( { nullable : true } ) @ RelationId ( ( attachment ) => attachment . message ) message_id : string ; @ JoinColumn ( { name : "message_id" } ) @ ManyToOne ( ( ) => require ( "./Message" ) . Message , ( message ) => message . attachments , { onDelete : "CASCADE" , } ) message : import ( "./Message" ) . Message ; @ BeforeRemove ( ) onDelete ( ) { return deleteFile ( new URL ( this . url ) . pathname ) ; } }