]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/models/video/video.ts
findById -> findByPk
[github/Chocobozzz/PeerTube.git] / server / models / video / video.ts
index 7022607728b105013c04abbe8e40758004d70a7a..4516b9c7b88d57b61b74dcd41903cd997c564ca9 100644 (file)
@@ -40,7 +40,7 @@ import {
   isVideoDurationValid,
   isVideoLanguageValid,
   isVideoLicenceValid,
-  isVideoNameValid,
+  isVideoNameValid, isVideoOriginallyPublishedAtValid,
   isVideoPrivacyValid,
   isVideoStateValid,
   isVideoSupportValid
@@ -106,6 +106,14 @@ const indexes: Sequelize.DefineIndexesOptions[] = [
   { fields: [ 'duration' ] },
   { fields: [ 'views' ] },
   { fields: [ 'channelId' ] },
+  {
+    fields: [ 'originallyPublishedAt' ],
+    where: {
+      originallyPublishedAt: {
+        [Sequelize.Op.ne]: null
+      }
+    }
+  },
   {
     fields: [ 'category' ], // We don't care videos with an unknown category
     where: {
@@ -715,6 +723,10 @@ export class VideoModel extends Model<VideoModel> {
   @Column
   commentsEnabled: boolean
 
+  @AllowNull(false)
+  @Column
+  downloadEnabled: boolean
+
   @AllowNull(false)
   @Column
   waitTranscoding: boolean
@@ -736,6 +748,11 @@ export class VideoModel extends Model<VideoModel> {
   @Column
   publishedAt: Date
 
+  @AllowNull(true)
+  @Default(null)
+  @Column
+  originallyPublishedAt: Date
+
   @ForeignKey(() => VideoChannelModel)
   @Column
   channelId: number
@@ -1157,6 +1174,8 @@ export class VideoModel extends Model<VideoModel> {
     sort?: string
     startDate?: string // ISO 8601
     endDate?: string // ISO 8601
+    originallyPublishedStartDate?: string
+    originallyPublishedEndDate?: string
     nsfw?: boolean
     categoryOneOf?: number[]
     licenceOneOf?: number[]
@@ -1179,6 +1198,15 @@ export class VideoModel extends Model<VideoModel> {
       whereAnd.push({ publishedAt: publishedAtRange })
     }
 
+    if (options.originallyPublishedStartDate || options.originallyPublishedEndDate) {
+      const originallyPublishedAtRange = {}
+
+      if (options.originallyPublishedStartDate) originallyPublishedAtRange[ Sequelize.Op.gte ] = options.originallyPublishedStartDate
+      if (options.originallyPublishedEndDate) originallyPublishedAtRange[ Sequelize.Op.lte ] = options.originallyPublishedEndDate
+
+      whereAnd.push({ originallyPublishedAt: originallyPublishedAtRange })
+    }
+
     if (options.durationMin || options.durationMax) {
       const durationRange = {}
 
@@ -1285,7 +1313,7 @@ export class VideoModel extends Model<VideoModel> {
 
   static loadWithFiles (id: number, t?: Sequelize.Transaction, logging?: boolean) {
     return VideoModel.scope([ ScopeNames.WITH_FILES, ScopeNames.WITH_STREAMING_PLAYLISTS ])
-                     .findById(id, { transaction: t, logging })
+                     .findByPk(id, { transaction: t, logging })
   }
 
   static loadByUUIDWithFile (uuid: string) {