add migration and entities for uploads upload_zk upload_hotlink.

This commit is contained in:
2026-10-05 22:14:26 +02:00
parent 64041aa9a8
commit fb1cb1d6b0
8 changed files with 132 additions and 1 deletions
@@ -0,0 +1,10 @@
import { Module } from '@nestjs/common';
import { TypeOrmModule } from '@nestjs/typeorm';
import { Upload } from './entities/Upload';
import { UploadHotlink } from './entities/UploadHotlink';
import { UploadZk } from './entities/UploadZk';
@Module({
imports: [TypeOrmModule.forFeature([Upload, UploadZk, UploadHotlink])]
})
export class UploadModule {}
@@ -0,0 +1,43 @@
import { Column, CreateDateColumn, Entity, OneToOne, PrimaryGeneratedColumn } from 'typeorm';
import { UploadMode } from '../types/UploadMode';
import { UploadHotlink } from './UploadHotlink';
import { UploadZk } from './UploadZk';
@Entity('uploads')
export class Upload {
@PrimaryGeneratedColumn('uuid')
id: string;
@Column({ type: 'enum', enum: UploadMode })
mode: UploadMode;
@Column({ type: 'text' })
storagePath: string;
@Column({ type: 'bytea' })
iv: Buffer;
@Column({ type: 'int', nullable: true })
maxViews: number | null;
@Column({ type: 'int', default: 0 })
viewCount: number;
@Column()
deleteTokenHash: string;
@OneToOne(() => UploadZk, zk => zk.upload)
zk: UploadZk | null;
@OneToOne(() => UploadHotlink, hotlink => hotlink.upload)
hotlink: UploadHotlink | null;
@Column({ type: 'timestamptz', nullable: true })
lastViewedAt: Date | null;
@Column({ type: 'timestamptz', nullable: true })
expiresAt: Date | null;
@CreateDateColumn({ type: 'timestamptz' })
createdAt: Date;
}
@@ -0,0 +1,15 @@
import { Column, Entity, JoinColumn, OneToOne, PrimaryGeneratedColumn } from 'typeorm';
import { Upload } from './Upload';
@Entity('upload_hotlink')
export class UploadHotlink {
@PrimaryGeneratedColumn('uuid')
id: string;
@Column()
mimeType: string;
@OneToOne(() => Upload, upload => upload.hotlink, { onDelete: 'CASCADE' })
@JoinColumn()
upload: Upload;
}
@@ -0,0 +1,24 @@
import { Column, Entity, JoinColumn, OneToOne, PrimaryGeneratedColumn } from 'typeorm';
import { Upload } from './Upload';
@Entity('upload_zk')
export class UploadZk {
@PrimaryGeneratedColumn('uuid')
id: string;
@Column({ type: 'boolean', default: false })
passwordProtected: boolean;
@Column({ type: 'bytea', nullable: true })
wrappedDek: Buffer | null;
@Column({ type: 'bytea', nullable: true })
wrapIv: Buffer | null;
@Column({ type: 'bytea', nullable: true })
salt: Buffer | null;
@OneToOne(() => Upload, upload => upload.zk, { onDelete: 'CASCADE' })
@JoinColumn()
upload: Upload;
}
@@ -0,0 +1,4 @@
export enum UploadMode {
Zk = 'zk',
Hotlink = 'hotlink'
}