diff --git a/src/util/entities/CloudAttachment.ts b/src/util/entities/CloudAttachment.ts
new file mode 100644
index 00000000..02c52743
--- /dev/null
+++ b/src/util/entities/CloudAttachment.ts
@@ -0,0 +1,85 @@
+/*
+ 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 { BeforeRemove, Column, Entity, JoinColumn, ManyToOne, OneToOne, RelationId } from "typeorm";
+import { URL } from "url";
+import { deleteFile } from "../util/cdn";
+import { BaseClass } from "./BaseClass";
+import { dbEngine } from "../util/Database";
+import { User } from "./User";
+import { Channel } from "./Channel";
+
+@Entity({
+ name: "cloud_attachments",
+ engine: dbEngine,
+})
+export class CloudAttachment extends BaseClass {
+ // Internal tracking metadata
+ @Column({ name: "user_id", nullable: true })
+ @RelationId((att: CloudAttachment) => att.user)
+ userId: string;
+
+ @JoinColumn({ name: "userId" })
+ @ManyToOne(() => 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: "channelId" })
+ @ManyToOne(() => 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);
+ // }
+}
diff --git a/src/util/migration/postgres/1758654246197-CloudAttachments.ts b/src/util/migration/postgres/1758654246197-CloudAttachments.ts
new file mode 100644
index 00000000..03f745b2
--- /dev/null
+++ b/src/util/migration/postgres/1758654246197-CloudAttachments.ts
@@ -0,0 +1,18 @@
+import { MigrationInterface, QueryRunner } from "typeorm";
+
+export class CloudAttachments1758654246197 implements MigrationInterface {
+ name = 'CloudAttachments1758654246197'
+
+ public async up(queryRunner: QueryRunner): Promise<void> {
+ await queryRunner.query(`CREATE TABLE "cloud_attachments" ("id" character varying NOT NULL, "user_id" character varying, "channel_id" character varying, "upload_filename" character varying NOT NULL, "user_attachment_id" character varying, "user_filename" character varying NOT NULL, "user_file_size" integer, "user_original_content_type" character varying, "user_is_clip" boolean, "size" integer, "height" integer, "width" integer, "content_type" character varying, "userId" character varying, "channelId" character varying, CONSTRAINT "PK_5794827a3ee7c9318612dcb70c8" PRIMARY KEY ("id"))`);
+ await queryRunner.query(`ALTER TABLE "cloud_attachments" ADD CONSTRAINT "FK_e6b32df2004e8ad0f488b4a2019" FOREIGN KEY ("userId") REFERENCES "users"("id") ON DELETE SET NULL ON UPDATE NO ACTION`);
+ await queryRunner.query(`ALTER TABLE "cloud_attachments" ADD CONSTRAINT "FK_cab965a18f8ca30293bff3d50a8" FOREIGN KEY ("channelId") REFERENCES "channels"("id") ON DELETE SET NULL ON UPDATE NO ACTION`);
+ }
+
+ public async down(queryRunner: QueryRunner): Promise<void> {
+ await queryRunner.query(`ALTER TABLE "cloud_attachments" DROP CONSTRAINT "FK_cab965a18f8ca30293bff3d50a8"`);
+ await queryRunner.query(`ALTER TABLE "cloud_attachments" DROP CONSTRAINT "FK_e6b32df2004e8ad0f488b4a2019"`);
+ await queryRunner.query(`DROP TABLE "cloud_attachments"`);
+ }
+
+}
diff --git a/src/util/schemas/UploadAttachmentRequestSchema.ts b/src/util/schemas/UploadAttachmentRequestSchema.ts
new file mode 100644
index 00000000..06cb65f1
--- /dev/null
+++ b/src/util/schemas/UploadAttachmentRequestSchema.ts
@@ -0,0 +1,30 @@
+/*
+ Spacebar: A FOSS re-implementation and extension of the Discord.com backend.
+ Copyright (C) 2024 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/>.
+*/
+
+
+export interface UploadAttachmentRequestSchema {
+ files: UploadAttachmentRequest[];
+}
+
+export interface UploadAttachmentRequest {
+ id: string;
+ filename: string;
+ file_size: number;
+ is_clip?: boolean;
+ original_content_type?: string;
+}
diff --git a/src/util/schemas/index.ts b/src/util/schemas/index.ts
index 9bba9cb4..39710425 100644
--- a/src/util/schemas/index.ts
+++ b/src/util/schemas/index.ts
@@ -81,6 +81,7 @@ export * from "./TemplateModifySchema";
export * from "./TotpDisableSchema";
export * from "./TotpEnableSchema";
export * from "./TotpSchema";
+export * from "./UploadAttachmentRequestSchema";
export * from "./UserDeleteSchema";
export * from "./UserGuildSettingsSchema";
export * from "./UserModifySchema";
diff --git a/src/util/schemas/responses/UploadAttachmentResponseSchema.ts b/src/util/schemas/responses/UploadAttachmentResponseSchema.ts
new file mode 100644
index 00000000..322137da
--- /dev/null
+++ b/src/util/schemas/responses/UploadAttachmentResponseSchema.ts
@@ -0,0 +1,28 @@
+/*
+ Spacebar: A FOSS re-implementation and extension of the Discord.com backend.
+ Copyright (C) 2024 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/>.
+*/
+
+
+export interface UploadAttachmentResponseSchema {
+ attachments: UploadAttachmentResponse[];
+}
+
+export interface UploadAttachmentResponse {
+ id?: string;
+ upload_url: string;
+ upload_filename: string;
+}
diff --git a/src/util/schemas/responses/index.ts b/src/util/schemas/responses/index.ts
index 8ca6fc61..561af184 100644
--- a/src/util/schemas/responses/index.ts
+++ b/src/util/schemas/responses/index.ts
@@ -58,6 +58,7 @@ export * from "./Tenor";
export * from "./TokenResponse";
export * from "./TypedResponses";
export * from "./UpdatesResponse";
+export * from "./UploadAttachmentResponseSchema";
export * from "./UserNoteResponse";
export * from "./UserProfileResponse";
export * from "./UserRelationshipsResponse";
diff --git a/src/util/util/Permissions.ts b/src/util/util/Permissions.ts
index 53a4c4f0..440be9df 100644
--- a/src/util/util/Permissions.ts
+++ b/src/util/util/Permissions.ts
@@ -20,7 +20,7 @@ export class Permissions extends BitField {
constructor(bits: BitFieldResolvable = 0) {
super(bits);
if (this.bitfield & Permissions.FLAGS.ADMINISTRATOR) {
- this.bitfield = ALL_PERMISSIONS;
+ this.bitfield = Permissions.ALL_PERMISSIONS;
}
}
@@ -73,6 +73,11 @@ export class Permissions extends BitField {
// CUSTOM_PERMISSION: BigInt(1) << BigInt(0) + CUSTOM_PERMISSION_OFFSET
};
+ static ALL_PERMISSIONS = Object.values(Permissions.FLAGS).reduce(
+ (total, val) => total | val,
+ BigInt(0),
+ );
+
any(permission: PermissionResolvable, checkAdmin = true) {
return (
(checkAdmin && super.any(Permissions.FLAGS.ADMINISTRATOR)) ||
@@ -207,11 +212,6 @@ export class Permissions extends BitField {
));
}
-const ALL_PERMISSIONS = Object.values(Permissions.FLAGS).reduce(
- (total, val) => total | val,
- BigInt(0),
-);
-
export type PermissionCache = {
channel?: Channel | undefined;
member?: Member | undefined;
|