mirror of
https://github.com/spacebarchat/server.git
synced 2026-08-29 01:09:20 +00:00
Store attachment data in db
This commit is contained in:
Binary file not shown.
Binary file not shown.
+2
-2
@@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
import { MigrationInterface, QueryRunner } from "typeorm";
|
||||
|
||||
export class AttachmentMetadata1787497429170 implements MigrationInterface {
|
||||
name = "AttachmentMetadata1787497429170";
|
||||
|
||||
public async up(queryRunner: QueryRunner): Promise<void> {
|
||||
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<void> {
|
||||
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"`);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user