From 26b7305a232e547709f433a6edf700bf495935d8 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Mon, 13 Aug 2018 16:57:13 +0200 Subject: Add blacklist reason field --- server/models/video/video.ts | 30 ++++++++++++++++++++++-------- 1 file changed, 22 insertions(+), 8 deletions(-) (limited to 'server/models/video/video.ts') diff --git a/server/models/video/video.ts b/server/models/video/video.ts index 39fe21007..f3a900bc9 100644 --- a/server/models/video/video.ts +++ b/server/models/video/video.ts @@ -93,6 +93,7 @@ import { VideoShareModel } from './video-share' import { VideoTagModel } from './video-tag' import { ScheduleVideoUpdateModel } from './schedule-video-update' import { VideoCaptionModel } from './video-caption' +import { VideoBlacklistModel } from './video-blacklist' // FIXME: Define indexes here because there is an issue with TS and Sequelize.literal when called directly in the annotation const indexes: Sequelize.DefineIndexesOptions[] = [ @@ -581,6 +582,15 @@ export class VideoModel extends Model { }) ScheduleVideoUpdate: ScheduleVideoUpdateModel + @HasOne(() => VideoBlacklistModel, { + foreignKey: { + name: 'videoId', + allowNull: false + }, + onDelete: 'cascade' + }) + VideoBlacklist: VideoBlacklistModel + @HasMany(() => VideoCaptionModel, { foreignKey: { name: 'videoId', @@ -755,7 +765,7 @@ export class VideoModel extends Model { }) } - static listUserVideosForApi (accountId: number, start: number, count: number, sort: string, hideNSFW: boolean, withFiles = false) { + static listUserVideosForApi (accountId: number, start: number, count: number, sort: string, withFiles = false) { const query: IFindOptions = { offset: start, limit: count, @@ -777,6 +787,10 @@ export class VideoModel extends Model { { model: ScheduleVideoUpdateModel, required: false + }, + { + model: VideoBlacklistModel, + required: false } ] } @@ -788,12 +802,6 @@ export class VideoModel extends Model { }) } - if (hideNSFW === true) { - query.where = { - nsfw: false - } - } - return VideoModel.findAndCountAll(query).then(({ rows, count }) => { return { data: rows, @@ -1177,7 +1185,8 @@ export class VideoModel extends Model { additionalAttributes: { state?: boolean, waitTranscoding?: boolean, - scheduledUpdate?: boolean + scheduledUpdate?: boolean, + blacklistInfo?: boolean } }): Video { const formattedAccount = this.VideoChannel.Account.toFormattedJSON() @@ -1254,6 +1263,11 @@ export class VideoModel extends Model { privacy: this.ScheduleVideoUpdate.privacy || undefined } } + + if (options.additionalAttributes.blacklistInfo === true) { + videoObject.blacklisted = !!this.VideoBlacklist + videoObject.blacklistedReason = this.VideoBlacklist ? this.VideoBlacklist.reason : null + } } return videoObject -- cgit v1.2.3