]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/models/video/video-playlist.ts
Add user adminFlags
[github/Chocobozzz/PeerTube.git] / server / models / video / video-playlist.ts
index 4d2ea0a666ad11600238af46b51f68706bb4e734..0725b752a9432e22ceacfd54e421bda535d36874 100644 (file)
@@ -17,7 +17,7 @@ import {
 } from 'sequelize-typescript'
 import * as Sequelize from 'sequelize'
 import { VideoPlaylistPrivacy } from '../../../shared/models/videos/playlist/video-playlist-privacy.model'
-import { buildServerIdsFollowedBy, buildWhereIdOrUUID, getSort, throwIfNotValid } from '../utils'
+import { buildServerIdsFollowedBy, buildWhereIdOrUUID, getSort, isOutdated, throwIfNotValid } from '../utils'
 import {
   isVideoPlaylistDescriptionValid,
   isVideoPlaylistNameValid,
@@ -25,13 +25,14 @@ import {
 } from '../../helpers/custom-validators/video-playlists'
 import { isActivityPubUrlValid } from '../../helpers/custom-validators/activitypub/misc'
 import {
-  CONFIG,
+  ACTIVITY_PUB,
   CONSTRAINTS_FIELDS,
   STATIC_PATHS,
   THUMBNAILS_SIZE,
   VIDEO_PLAYLIST_PRIVACIES,
-  VIDEO_PLAYLIST_TYPES
-} from '../../initializers'
+  VIDEO_PLAYLIST_TYPES,
+  WEBSERVER
+} from '../../initializers/constants'
 import { VideoPlaylist } from '../../../shared/models/videos/playlist/video-playlist.model'
 import { AccountModel, ScopeNames as AccountScopeNames } from '../account/account'
 import { ScopeNames as VideoChannelScopeNames, VideoChannelModel } from './video-channel'
@@ -42,6 +43,7 @@ import { activityPubCollectionPagination } from '../../helpers/activitypub'
 import { remove } from 'fs-extra'
 import { logger } from '../../helpers/logger'
 import { VideoPlaylistType } from '../../../shared/models/videos/playlist/video-playlist-type.model'
+import { CONFIG } from '../../initializers/config'
 
 enum ScopeNames {
   AVAILABLE_FOR_LIST = 'AVAILABLE_FOR_LIST',
@@ -301,13 +303,14 @@ export class VideoPlaylistModel extends Model<VideoPlaylistModel> {
       })
   }
 
-  static listUrlsOfForAP (accountId: number, start: number, count: number) {
+  static listPublicUrlsOfForAP (accountId: number, start: number, count: number) {
     const query = {
       attributes: [ 'url' ],
       offset: start,
       limit: count,
       where: {
-        ownerAccountId: accountId
+        ownerAccountId: accountId,
+        privacy: VideoPlaylistPrivacy.PUBLIC
       }
     }
 
@@ -317,6 +320,29 @@ export class VideoPlaylistModel extends Model<VideoPlaylistModel> {
                              })
   }
 
+  static listPlaylistIdsOf (accountId: number, videoIds: number[]) {
+    const query = {
+      attributes: [ 'id' ],
+      where: {
+        ownerAccountId: accountId
+      },
+      include: [
+        {
+          attributes: [ 'videoId', 'startTimestamp', 'stopTimestamp' ],
+          model: VideoPlaylistElementModel.unscoped(),
+          where: {
+            videoId: {
+              [Sequelize.Op.any]: videoIds
+            }
+          },
+          required: true
+        }
+      ]
+    }
+
+    return VideoPlaylistModel.findAll(query)
+  }
+
   static doesPlaylistExist (url: string) {
     const query = {
       attributes: [],
@@ -392,7 +418,7 @@ export class VideoPlaylistModel extends Model<VideoPlaylistModel> {
   }
 
   getThumbnailUrl () {
-    return CONFIG.WEBSERVER.URL + STATIC_PATHS.THUMBNAILS + this.getThumbnailName()
+    return WEBSERVER.URL + STATIC_PATHS.THUMBNAILS + this.getThumbnailName()
   }
 
   getThumbnailStaticPath () {
@@ -405,10 +431,22 @@ export class VideoPlaylistModel extends Model<VideoPlaylistModel> {
       .catch(err => logger.warn('Cannot delete thumbnail %s.', thumbnailPath, { err }))
   }
 
+  setAsRefreshed () {
+    this.changed('updatedAt', true)
+
+    return this.save()
+  }
+
   isOwned () {
     return this.OwnerAccount.isOwned()
   }
 
+  isOutdated () {
+    if (this.isOwned()) return false
+
+    return isOutdated(this, ACTIVITY_PUB.VIDEO_PLAYLIST_REFRESH_INTERVAL)
+  }
+
   toFormattedJSON (): VideoPlaylist {
     return {
       id: this.id,