diff --git a/assets/openapi.json b/assets/openapi.json index ab7f45532..b147fc36a 100644 Binary files a/assets/openapi.json and b/assets/openapi.json differ diff --git a/assets/schemas.json b/assets/schemas.json index 77309deaf..fa1337109 100644 Binary files a/assets/schemas.json and b/assets/schemas.json differ diff --git a/package.json b/package.json index 5693a2a3a..0622a0dc3 100644 --- a/package.json +++ b/package.json @@ -19,7 +19,7 @@ "sync:db": "npm run build && node -r dotenv/config -r module-alias/register --enable-source-maps scripts/syncronise.js", "generate:rights": "node -r dotenv/config -r module-alias/register --enable-source-maps scripts/rights.js", "generate:schema": "node -r dotenv/config -r module-alias/register --enable-source-maps scripts/schema.js", - "generate:migration": "node-r dotenv/config -r module-alias/register --enable-source-maps node_modules/typeorm/cli.js migration:generate -d dist/database/Database.js", + "generate:migration": "node -r dotenv/config -r module-alias/register --enable-source-maps node_modules/typeorm/cli.js migration:generate -d dist/database/Database.js", "generate:openapi": "node -r dotenv/config -r module-alias/register --enable-source-maps scripts/openapi.js", "add:license": "node -r dotenv/config -r module-alias/register --enable-source-maps scripts/license.js", "node:tests": "npm run build:src && node -r dotenv/config -r module-alias/register --enable-source-maps --test --experimental-test-coverage dist/**/*.test.js", @@ -152,4 +152,4 @@ "bcrypt@6.0.0": true, "cbor-extract@2.2.2": true } -} +} \ No newline at end of file diff --git a/src/database/entities/Attachment.ts b/src/database/entities/Attachment.ts index f0163499d..da3df2d42 100644 --- a/src/database/entities/Attachment.ts +++ b/src/database/entities/Attachment.ts @@ -19,7 +19,7 @@ import { BeforeRemove, Column, Entity, JoinColumn, ManyToOne, RelationId } from "typeorm"; import { Config, deleteFile } from "@spacebar/util/util"; import { getUrlSignature, NewUrlUserSignatureData, NewUrlSignatureData } from "@spacebar/util/Signing"; -import type { PublicAttachment } from "@spacebar/schemas/api/messages/Attachments"; +import { AttachmentFlags, PublicAttachment } from "@spacebar/schemas/api/messages/Attachments"; import { BaseClass } from "./BaseClass"; @Entity({ @@ -61,19 +61,46 @@ export class Attachment extends BaseClass { }) channel: import("./Channel").Channel; + @Column({ nullable: true, type: "character varying" }) + description?: string; + + @Column({ nullable: true, type: "int2" }) + flags?: AttachmentFlags; + + @Column({ nullable: true, type: "int2" }) + content_scan_version?: number; + + @Column({ nullable: true, type: "int2" }) + placeholder_version?: number; + + @Column({ nullable: true, type: "character varying" }) + placeholder?: string; + + @Column({ nullable: true, type: "float8" }) + duration_secs?: number; + + @Column({ nullable: true, type: "character varying" }) + waveform?: string; + + @Column({ nullable: true, type: "character varying" }) + title?: string; + + @Column({ nullable: true, type: "timestamp with time zone" }) + clip_created_at?: Date; + @BeforeRemove() onDelete() { return deleteFile(new URL(this.toJSON().url).pathname); } - toJSON() { + toJSON(): PublicAttachment { const channelId = this.channel_id ?? this.channel?.id ?? this.message?.channel_id; const messageId = this.message_id ?? this.message?.id; return { ...this, url: `${Config.get().cdn.endpointPublic}/attachments/${channelId}/${messageId}/${this.filename}`, proxy_url: `${Config.get().cdn.endpointPublic}/attachments/${channelId}/${messageId}/${this.filename}`, - }; + } satisfies PublicAttachment; } signUrls(data: NewUrlUserSignatureData): PublicAttachment { const att = Attachment.prototype.toJSON.apply(this); diff --git a/src/database/migration/postgres/1787497429170-AttachmentMetadata.ts b/src/database/migration/postgres/1787497429170-AttachmentMetadata.ts new file mode 100644 index 000000000..074686a52 --- /dev/null +++ b/src/database/migration/postgres/1787497429170-AttachmentMetadata.ts @@ -0,0 +1,29 @@ +import { MigrationInterface, QueryRunner } from "typeorm"; + +export class AttachmentMetadata1787497429170 implements MigrationInterface { + name = "AttachmentMetadata1787497429170"; + + public async up(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE "attachments" ADD "description" character varying`); + await queryRunner.query(`ALTER TABLE "attachments" ADD "flags" smallint`); + await queryRunner.query(`ALTER TABLE "attachments" ADD "content_scan_version" smallint`); + await queryRunner.query(`ALTER TABLE "attachments" ADD "placeholder_version" smallint`); + await queryRunner.query(`ALTER TABLE "attachments" ADD "placeholder" character varying`); + await queryRunner.query(`ALTER TABLE "attachments" ADD "duration_secs" double precision`); + await queryRunner.query(`ALTER TABLE "attachments" ADD "waveform" character varying`); + await queryRunner.query(`ALTER TABLE "attachments" ADD "title" character varying`); + await queryRunner.query(`ALTER TABLE "attachments" ADD "clip_created_at" TIMESTAMP WITH TIME ZONE`); + } + + public async down(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE "attachments" DROP COLUMN "clip_created_at"`); + await queryRunner.query(`ALTER TABLE "attachments" DROP COLUMN "title"`); + await queryRunner.query(`ALTER TABLE "attachments" DROP COLUMN "waveform"`); + await queryRunner.query(`ALTER TABLE "attachments" DROP COLUMN "duration_secs"`); + await queryRunner.query(`ALTER TABLE "attachments" DROP COLUMN "placeholder"`); + await queryRunner.query(`ALTER TABLE "attachments" DROP COLUMN "placeholder_version"`); + await queryRunner.query(`ALTER TABLE "attachments" DROP COLUMN "content_scan_version"`); + await queryRunner.query(`ALTER TABLE "attachments" DROP COLUMN "flags"`); + await queryRunner.query(`ALTER TABLE "attachments" DROP COLUMN "description"`); + } +}