summary refs log tree commit diff
path: root/src/util/entities/CloudAttachment.ts
blob: 57d2b79054b37137cc35e66a27a63862dde8e895 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
/*
	Spacebar: A FOSS re-implementation and extension of the Discord.com backend.
	Copyright (C) 2023 Spacebar and Spacebar Contributors

	This program is free software: you can redistribute it and/or modify
	it under the terms of the GNU Affero General Public License as published
	by the Free Software Foundation, either version 3 of the License, or
	(at your option) any later version.

	This program is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU Affero General Public License for more details.

	You should have received a copy of the GNU Affero General Public License
	along with this program.  If not, see <https://www.gnu.org/licenses/>.
*/

import { Column, Entity, JoinColumn, ManyToOne, RelationId } from "typeorm";
import { BaseClass } from "./BaseClass";
import type { User } from "./User";
import type { Channel } from "./Channel";

@Entity({
    name: "cloud_attachments",
})
export class CloudAttachment extends BaseClass {
    // Internal tracking metadata
    @Column({ name: "user_id", nullable: true })
    @RelationId((att: CloudAttachment) => att.user)
    userId: string;

    @JoinColumn({ name: "user_id" })
    @ManyToOne(() => require("./User").User, { nullable: true, onDelete: "SET NULL" })
    user?: User;

    @Column({ name: "channel_id", nullable: true })
    @RelationId((att: CloudAttachment) => att.channel)
    channelId?: string; // channel the file is uploaded to

    @JoinColumn({ name: "channel_id" })
    @ManyToOne(() => require("./Channel").Channel, { nullable: true, onDelete: "SET NULL" })
    channel?: Channel; // channel the file is uploaded to

    @Column({ name: "upload_filename" })
    uploadFilename: string;

    // User-provided info
    @Column({ name: "user_attachment_id", nullable: true })
    userAttachmentId?: string;

    @Column({ name: "user_filename" })
    userFilename: string; // name of file attached

    @Column({ name: "user_file_size", nullable: true })
    userFileSize?: number; // size of file in bytes

    @Column({ name: "user_original_content_type", nullable: true })
    userOriginalContentType?: string;

    @Column({ name: "user_is_clip", nullable: true })
    userIsClip?: boolean; // whether the file is a clip

    // Actual file info, initialised after upload
    @Column({ nullable: true })
    size?: number; // size of file in bytes

    @Column({ nullable: true })
    height?: number; // height of file (if image)

    @Column({ nullable: true })
    width?: number; // width of file (if image)

    @Column({ name: "content_type", nullable: true })
    contentType?: string;

    // @BeforeRemove()
    // onDelete() {
    // 	return deleteFile(new URL(this.url).pathname);
    // }
}