diff options
author | Chocobozzz <me@florianbigard.com> | 2018-08-13 16:57:13 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2018-08-14 09:27:18 +0200 |
commit | 26b7305a232e547709f433a6edf700bf495935d8 (patch) | |
tree | b5676090c61df72f864735bcc881d5ee256cffbd /server/models/video/video.ts | |
parent | efc9e8450a8bbeeef9cd18e3ad6037abc0f815c3 (diff) | |
download | PeerTube-26b7305a232e547709f433a6edf700bf495935d8.tar.gz PeerTube-26b7305a232e547709f433a6edf700bf495935d8.tar.zst PeerTube-26b7305a232e547709f433a6edf700bf495935d8.zip |
Add blacklist reason field
Diffstat (limited to 'server/models/video/video.ts')
-rw-r--r-- | server/models/video/video.ts | 30 |
1 files changed, 22 insertions, 8 deletions
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' | |||
93 | import { VideoTagModel } from './video-tag' | 93 | import { VideoTagModel } from './video-tag' |
94 | import { ScheduleVideoUpdateModel } from './schedule-video-update' | 94 | import { ScheduleVideoUpdateModel } from './schedule-video-update' |
95 | import { VideoCaptionModel } from './video-caption' | 95 | import { VideoCaptionModel } from './video-caption' |
96 | import { VideoBlacklistModel } from './video-blacklist' | ||
96 | 97 | ||
97 | // FIXME: Define indexes here because there is an issue with TS and Sequelize.literal when called directly in the annotation | 98 | // FIXME: Define indexes here because there is an issue with TS and Sequelize.literal when called directly in the annotation |
98 | const indexes: Sequelize.DefineIndexesOptions[] = [ | 99 | const indexes: Sequelize.DefineIndexesOptions[] = [ |
@@ -581,6 +582,15 @@ export class VideoModel extends Model<VideoModel> { | |||
581 | }) | 582 | }) |
582 | ScheduleVideoUpdate: ScheduleVideoUpdateModel | 583 | ScheduleVideoUpdate: ScheduleVideoUpdateModel |
583 | 584 | ||
585 | @HasOne(() => VideoBlacklistModel, { | ||
586 | foreignKey: { | ||
587 | name: 'videoId', | ||
588 | allowNull: false | ||
589 | }, | ||
590 | onDelete: 'cascade' | ||
591 | }) | ||
592 | VideoBlacklist: VideoBlacklistModel | ||
593 | |||
584 | @HasMany(() => VideoCaptionModel, { | 594 | @HasMany(() => VideoCaptionModel, { |
585 | foreignKey: { | 595 | foreignKey: { |
586 | name: 'videoId', | 596 | name: 'videoId', |
@@ -755,7 +765,7 @@ export class VideoModel extends Model<VideoModel> { | |||
755 | }) | 765 | }) |
756 | } | 766 | } |
757 | 767 | ||
758 | static listUserVideosForApi (accountId: number, start: number, count: number, sort: string, hideNSFW: boolean, withFiles = false) { | 768 | static listUserVideosForApi (accountId: number, start: number, count: number, sort: string, withFiles = false) { |
759 | const query: IFindOptions<VideoModel> = { | 769 | const query: IFindOptions<VideoModel> = { |
760 | offset: start, | 770 | offset: start, |
761 | limit: count, | 771 | limit: count, |
@@ -777,6 +787,10 @@ export class VideoModel extends Model<VideoModel> { | |||
777 | { | 787 | { |
778 | model: ScheduleVideoUpdateModel, | 788 | model: ScheduleVideoUpdateModel, |
779 | required: false | 789 | required: false |
790 | }, | ||
791 | { | ||
792 | model: VideoBlacklistModel, | ||
793 | required: false | ||
780 | } | 794 | } |
781 | ] | 795 | ] |
782 | } | 796 | } |
@@ -788,12 +802,6 @@ export class VideoModel extends Model<VideoModel> { | |||
788 | }) | 802 | }) |
789 | } | 803 | } |
790 | 804 | ||
791 | if (hideNSFW === true) { | ||
792 | query.where = { | ||
793 | nsfw: false | ||
794 | } | ||
795 | } | ||
796 | |||
797 | return VideoModel.findAndCountAll(query).then(({ rows, count }) => { | 805 | return VideoModel.findAndCountAll(query).then(({ rows, count }) => { |
798 | return { | 806 | return { |
799 | data: rows, | 807 | data: rows, |
@@ -1177,7 +1185,8 @@ export class VideoModel extends Model<VideoModel> { | |||
1177 | additionalAttributes: { | 1185 | additionalAttributes: { |
1178 | state?: boolean, | 1186 | state?: boolean, |
1179 | waitTranscoding?: boolean, | 1187 | waitTranscoding?: boolean, |
1180 | scheduledUpdate?: boolean | 1188 | scheduledUpdate?: boolean, |
1189 | blacklistInfo?: boolean | ||
1181 | } | 1190 | } |
1182 | }): Video { | 1191 | }): Video { |
1183 | const formattedAccount = this.VideoChannel.Account.toFormattedJSON() | 1192 | const formattedAccount = this.VideoChannel.Account.toFormattedJSON() |
@@ -1254,6 +1263,11 @@ export class VideoModel extends Model<VideoModel> { | |||
1254 | privacy: this.ScheduleVideoUpdate.privacy || undefined | 1263 | privacy: this.ScheduleVideoUpdate.privacy || undefined |
1255 | } | 1264 | } |
1256 | } | 1265 | } |
1266 | |||
1267 | if (options.additionalAttributes.blacklistInfo === true) { | ||
1268 | videoObject.blacklisted = !!this.VideoBlacklist | ||
1269 | videoObject.blacklistedReason = this.VideoBlacklist ? this.VideoBlacklist.reason : null | ||
1270 | } | ||
1257 | } | 1271 | } |
1258 | 1272 | ||
1259 | return videoObject | 1273 | return videoObject |