From 2e401e8575decb1d491d0db48ca1ab1eba5b2a66 Mon Sep 17 00:00:00 2001 From: kontrollanten <6680299+kontrollanten@users.noreply.github.com> Date: Tue, 21 Jun 2022 15:31:25 +0200 Subject: store uploaded video filename (#4885) * store uploaded video filename closes #4731 * dont crash if videos channel exist * migration: use raw query * video source: fixes after code review * cleanup * bump migration * updates after code review * refactor: use checkUserCanManageVideo * videoSource: add openapi doc * test(check-params/video-source): fix timeout * Styling * Correctly set original filename as source Co-authored-by: Chocobozzz --- server/models/video/video-source.ts | 55 +++++++++++++++++++++++++++++++++++++ server/models/video/video.ts | 10 +++++++ 2 files changed, 65 insertions(+) create mode 100644 server/models/video/video-source.ts (limited to 'server/models') diff --git a/server/models/video/video-source.ts b/server/models/video/video-source.ts new file mode 100644 index 000000000..e306b160d --- /dev/null +++ b/server/models/video/video-source.ts @@ -0,0 +1,55 @@ +import { Op } from 'sequelize' +import { + AllowNull, + BelongsTo, + Column, + CreatedAt, + ForeignKey, + Model, + Table, + UpdatedAt +} from 'sequelize-typescript' +import { AttributesOnly } from '@shared/typescript-utils' +import { VideoModel } from './video' + +@Table({ + tableName: 'videoSource', + indexes: [ + { + fields: [ 'videoId' ], + where: { + videoId: { + [Op.ne]: null + } + } + } + ] +}) +export class VideoSourceModel extends Model>> { + @CreatedAt + createdAt: Date + + @UpdatedAt + updatedAt: Date + + @AllowNull(false) + @Column + filename: string + + @ForeignKey(() => VideoModel) + @Column + videoId: number + + @BelongsTo(() => VideoModel) + Video: VideoModel + + static loadByVideoId (videoId) { + return VideoSourceModel.findOne({ where: { videoId } }) + } + + toFormattedJSON () { + return { + filename: this.filename + } + } +} diff --git a/server/models/video/video.ts b/server/models/video/video.ts index e6a8d3f95..08adbced6 100644 --- a/server/models/video/video.ts +++ b/server/models/video/video.ts @@ -136,6 +136,7 @@ import { VideoPlaylistElementModel } from './video-playlist-element' import { VideoShareModel } from './video-share' import { VideoStreamingPlaylistModel } from './video-streaming-playlist' import { VideoTagModel } from './video-tag' +import { VideoSourceModel } from './video-source' export enum ScopeNames { FOR_API = 'FOR_API', @@ -597,6 +598,15 @@ export class VideoModel extends Model>> { }) VideoPlaylistElements: VideoPlaylistElementModel[] + @HasOne(() => VideoSourceModel, { + foreignKey: { + name: 'videoId', + allowNull: true + }, + onDelete: 'CASCADE' + }) + VideoSource: VideoSourceModel + @HasMany(() => VideoAbuseModel, { foreignKey: { name: 'videoId', -- cgit v1.2.3