]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/models/video/video.ts
Merge branch 'release/1.4.0' into develop
[github/Chocobozzz/PeerTube.git] / server / models / video / video.ts
index 7b1f0bc316b698cc8403b8725079cbfa46c72a9f..6856dcd9f057baa5f7d0f7c895afee3d7df8e43f 100644 (file)
@@ -121,18 +121,23 @@ import { createTorrentPromise } from '../../helpers/webtorrent'
 import { VideoStreamingPlaylistType } from '../../../shared/models/videos/video-streaming-playlist.type'
 import {
   MChannel,
-  MChannelActorAccountDefault,
+  MChannelAccountDefault,
   MChannelId,
   MUserAccountId,
   MUserId,
-  MVideoAccountAllFiles,
   MVideoAccountLight,
+  MVideoAccountLightBlacklistAllFiles,
+  MVideoAP,
   MVideoDetails,
+  MVideoFormattable,
+  MVideoFormattableDetails,
+  MVideoForUser,
   MVideoFullLight,
   MVideoIdThumbnail,
   MVideoThumbnail,
+  MVideoThumbnailBlacklist,
   MVideoWithAllFiles,
-  MVideoWithBlacklistThumbnailScheduled,
+  MVideoWithFile,
   MVideoWithRights
 } from '../../typings/models'
 import { MVideoFile, MVideoFileRedundanciesOpt } from '../../typings/models/video/video-file'
@@ -463,13 +468,15 @@ export type AvailableForListIDsOptions = {
     // FIXME: issues with sequelize count when making a join on n:m relation, so we just make a IN()
     if (options.tagsAllOf || options.tagsOneOf) {
       if (options.tagsOneOf) {
+        const tagsOneOfLower = options.tagsOneOf.map(t => t.toLowerCase())
+
         whereAnd.push({
           id: {
             [ Op.in ]: Sequelize.literal(
               '(' +
               'SELECT "videoId" FROM "videoTag" ' +
               'INNER JOIN "tag" ON "tag"."id" = "videoTag"."tagId" ' +
-              'WHERE "tag"."name" IN (' + createSafeIn(VideoModel, options.tagsOneOf) + ')' +
+              'WHERE lower("tag"."name") IN (' + createSafeIn(VideoModel, tagsOneOfLower) + ')' +
               ')'
             )
           }
@@ -477,14 +484,16 @@ export type AvailableForListIDsOptions = {
       }
 
       if (options.tagsAllOf) {
+        const tagsAllOfLower = options.tagsAllOf.map(t => t.toLowerCase())
+
         whereAnd.push({
           id: {
             [ Op.in ]: Sequelize.literal(
               '(' +
               'SELECT "videoId" FROM "videoTag" ' +
               'INNER JOIN "tag" ON "tag"."id" = "videoTag"."tagId" ' +
-              'WHERE "tag"."name" IN (' + createSafeIn(VideoModel, options.tagsAllOf) + ')' +
-              'GROUP BY "videoTag"."videoId" HAVING COUNT(*) = ' + options.tagsAllOf.length +
+              'WHERE lower("tag"."name") IN (' + createSafeIn(VideoModel, tagsAllOfLower) + ')' +
+              'GROUP BY "videoTag"."videoId" HAVING COUNT(*) = ' + tagsAllOfLower.length +
               ')'
             )
           }
@@ -1015,7 +1024,7 @@ export class VideoModel extends Model<VideoModel> {
             AccountModel
           ],
           transaction: options.transaction
-        }) as MChannelActorAccountDefault
+        }) as MChannelAccountDefault
       }
 
       return sendDeleteVideo(instance, options.transaction)
@@ -1209,10 +1218,10 @@ export class VideoModel extends Model<VideoModel> {
 
     return Promise.all([
       VideoModel.count(countQuery),
-      VideoModel.scope(findScopes).findAll(findQuery)
+      VideoModel.scope(findScopes).findAll<MVideoForUser>(findQuery)
     ]).then(([ count, rows ]) => {
       return {
-        data: rows as MVideoWithBlacklistThumbnailScheduled[],
+        data: rows,
         total: count
       }
     })
@@ -1405,6 +1414,19 @@ export class VideoModel extends Model<VideoModel> {
     return VideoModel.scope(ScopeNames.WITH_THUMBNAILS).findOne(options)
   }
 
+  static loadWithBlacklist (id: number | string, t?: Transaction): Bluebird<MVideoThumbnailBlacklist> {
+    const where = buildWhereIdOrUUID(id)
+    const options = {
+      where,
+      transaction: t
+    }
+
+    return VideoModel.scope([
+      ScopeNames.WITH_THUMBNAILS,
+      ScopeNames.WITH_BLACKLISTED
+    ]).findOne(options)
+  }
+
   static loadWithRights (id: number | string, t?: Transaction): Bluebird<MVideoWithRights> {
     const where = buildWhereIdOrUUID(id)
     const options = {
@@ -1468,7 +1490,7 @@ export class VideoModel extends Model<VideoModel> {
     return VideoModel.scope(ScopeNames.WITH_THUMBNAILS).findOne(query)
   }
 
-  static loadByUrlAndPopulateAccount (url: string, transaction?: Transaction): Bluebird<MVideoAccountAllFiles> {
+  static loadByUrlAndPopulateAccount (url: string, transaction?: Transaction): Bluebird<MVideoAccountLightBlacklistAllFiles> {
     const query: FindOptions = {
       where: {
         url
@@ -1765,14 +1787,14 @@ export class VideoModel extends Model<VideoModel> {
       this.VideoChannel.Account.isBlocked()
   }
 
-  getOriginalFile () {
+  getOriginalFile <T extends MVideoWithFile> (this: T) {
     if (Array.isArray(this.VideoFiles) === false) return undefined
 
     // The original file is the file that have the higher resolution
     return maxBy(this.VideoFiles, file => file.resolution)
   }
 
-  getFile (resolution: number) {
+  getFile <T extends MVideoWithFile> (this: T, resolution: number) {
     if (Array.isArray(this.VideoFiles) === false) return undefined
 
     return this.VideoFiles.find(f => f.resolution === resolution)
@@ -1878,11 +1900,11 @@ export class VideoModel extends Model<VideoModel> {
     return join(LAZY_STATIC_PATHS.PREVIEWS, preview.filename)
   }
 
-  toFormattedJSON (options?: VideoFormattingJSONOptions): Video {
+  toFormattedJSON (this: MVideoFormattable, options?: VideoFormattingJSONOptions): Video {
     return videoModelToFormattedJSON(this, options)
   }
 
-  toFormattedDetailsJSON (): VideoDetails {
+  toFormattedDetailsJSON (this: MVideoFormattableDetails): VideoDetails {
     return videoModelToFormattedDetailsJSON(this)
   }
 
@@ -1890,7 +1912,7 @@ export class VideoModel extends Model<VideoModel> {
     return videoFilesModelToFormattedJSON(this, this.VideoFiles)
   }
 
-  toActivityPubObject (): VideoTorrentObject {
+  toActivityPubObject (this: MVideoAP): VideoTorrentObject {
     return videoModelToActivityPubObject(this)
   }