mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2024-11-25 11:16:31 -05:00
Add MediaUpload entity & Media module
Signed-off-by: David Mehren <git@herrmehren.de>
This commit is contained in:
parent
5cc20707dc
commit
617f46f32f
3 changed files with 75 additions and 0 deletions
|
@ -10,6 +10,7 @@ import { NotesModule } from './notes/notes.module';
|
|||
import { PermissionsModule } from './permissions/permissions.module';
|
||||
import { RevisionsModule } from './revisions/revisions.module';
|
||||
import { UsersModule } from './users/users.module';
|
||||
import { MediaModule } from './media/media.module';
|
||||
|
||||
@Module({
|
||||
imports: [
|
||||
|
@ -29,6 +30,7 @@ import { UsersModule } from './users/users.module';
|
|||
PermissionsModule,
|
||||
GroupsModule,
|
||||
LoggerModule,
|
||||
MediaModule,
|
||||
],
|
||||
controllers: [],
|
||||
providers: [],
|
||||
|
|
65
src/media/media-upload.entity.ts
Normal file
65
src/media/media-upload.entity.ts
Normal file
|
@ -0,0 +1,65 @@
|
|||
import * as crypto from 'crypto';
|
||||
import {
|
||||
Column,
|
||||
CreateDateColumn,
|
||||
Entity,
|
||||
ManyToOne,
|
||||
PrimaryColumn,
|
||||
} from 'typeorm';
|
||||
import { Note } from '../notes/note.entity';
|
||||
import { User } from '../users/user.entity';
|
||||
|
||||
@Entity()
|
||||
export class MediaUpload {
|
||||
@PrimaryColumn()
|
||||
id: string;
|
||||
|
||||
@ManyToOne(_ => Note, { nullable: false })
|
||||
note: Note;
|
||||
|
||||
@ManyToOne(_ => User, { nullable: false })
|
||||
user: User;
|
||||
|
||||
@Column({
|
||||
nullable: false,
|
||||
})
|
||||
extension: string;
|
||||
|
||||
@Column({
|
||||
nullable: false,
|
||||
})
|
||||
backendType: string;
|
||||
|
||||
@Column({
|
||||
nullable: true,
|
||||
})
|
||||
backendData: string | null;
|
||||
|
||||
@CreateDateColumn()
|
||||
createdAt: Date;
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
||||
private constructor() {}
|
||||
|
||||
public static create(
|
||||
note: Note,
|
||||
user: User,
|
||||
extension: string,
|
||||
backendType: string,
|
||||
backendData?: string,
|
||||
): MediaUpload {
|
||||
const upload = new MediaUpload();
|
||||
const randomBytes = crypto.randomBytes(16);
|
||||
upload.id = randomBytes.toString('hex');
|
||||
upload.note = note;
|
||||
upload.user = user;
|
||||
upload.extension = extension;
|
||||
upload.backendType = backendType;
|
||||
if (backendData) {
|
||||
upload.backendData = backendData;
|
||||
} else {
|
||||
upload.backendData = null;
|
||||
}
|
||||
return upload;
|
||||
}
|
||||
}
|
8
src/media/media.module.ts
Normal file
8
src/media/media.module.ts
Normal file
|
@ -0,0 +1,8 @@
|
|||
import { Module } from '@nestjs/common';
|
||||
import { TypeOrmModule } from '@nestjs/typeorm';
|
||||
import { MediaUpload } from './media-upload.entity';
|
||||
|
||||
@Module({
|
||||
imports: [TypeOrmModule.forFeature([MediaUpload])],
|
||||
})
|
||||
export class MediaModule {}
|
Loading…
Reference in a new issue