]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/models/video/video.ts
Add blacklist reason field
[github/Chocobozzz/PeerTube.git] / server / models / video / video.ts
index 39fe2100789b94b9e2ea768cadbebd72bffd12b5..f3a900bc981e9a1863f7bb77cb3de5c40d64cbd6 100644 (file)
@@ -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<VideoModel> {
   })
   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<VideoModel> {
     })
   }
 
-  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<VideoModel> = {
       offset: start,
       limit: count,
@@ -777,6 +787,10 @@ export class VideoModel extends Model<VideoModel> {
         {
           model: ScheduleVideoUpdateModel,
           required: false
+        },
+        {
+          model: VideoBlacklistModel,
+          required: false
         }
       ]
     }
@@ -788,12 +802,6 @@ export class VideoModel extends Model<VideoModel> {
       })
     }
 
-    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<VideoModel> {
     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<VideoModel> {
           privacy: this.ScheduleVideoUpdate.privacy || undefined
         }
       }
+
+      if (options.additionalAttributes.blacklistInfo === true) {
+        videoObject.blacklisted = !!this.VideoBlacklist
+        videoObject.blacklistedReason = this.VideoBlacklist ? this.VideoBlacklist.reason : null
+      }
     }
 
     return videoObject