]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/models/video/video.ts
Add admin view to manage comments
[github/Chocobozzz/PeerTube.git] / server / models / video / video.ts
index aba8c8cf4d604d1ffdd3f07cddc6a5a123bb8b81..f3055a494a4fab81de5c5e73555ff9723631785c 100644 (file)
@@ -25,7 +25,7 @@ import {
   UpdatedAt
 } from 'sequelize-typescript'
 import { buildNSFWFilter } from '@server/helpers/express-utils'
-import { getPrivaciesForFederation, isPrivacyForFederation } from '@server/helpers/video'
+import { getPrivaciesForFederation, isPrivacyForFederation, isStateForFederation } from '@server/helpers/video'
 import { LiveManager } from '@server/lib/live-manager'
 import { getHLSDirectory, getTorrentFileName, getTorrentFilePath, getVideoFilename, getVideoFilePath } from '@server/lib/video-paths'
 import { getServerActor } from '@server/models/application/application'
@@ -249,7 +249,7 @@ export type AvailableForListIDsOptions = {
   [ScopeNames.WITH_LIVE]: {
     include: [
       {
-        model: VideoLiveModel,
+        model: VideoLiveModel.unscoped(),
         required: false
       }
     ]
@@ -823,6 +823,8 @@ export class VideoModel extends Model<VideoModel> {
   static stopLiveIfNeeded (instance: VideoModel) {
     if (!instance.isLive) return
 
+    logger.info('Stopping live of video %s after video deletion.', instance.uuid)
+
     return LiveManager.Instance.stopSessionOf(instance.id)
   }
 
@@ -962,7 +964,7 @@ export class VideoModel extends Model<VideoModel> {
             }
           ]
         },
-        VideoLiveModel,
+        VideoLiveModel.unscoped(),
         VideoFileModel,
         TagModel
       ]
@@ -986,6 +988,19 @@ export class VideoModel extends Model<VideoModel> {
     })
   }
 
+  static listPublishedLiveIds () {
+    const options = {
+      attributes: [ 'id' ],
+      where: {
+        isLive: true,
+        state: VideoState.PUBLISHED
+      }
+    }
+
+    return VideoModel.findAll(options)
+      .map(v => v.id)
+  }
+
   static listUserVideosForApi (
     accountId: number,
     start: number,
@@ -1655,13 +1670,6 @@ export class VideoModel extends Model<VideoModel> {
         videoFilesDone.add(row.VideoFiles.id)
       }
 
-      if (row.VideoFiles?.id && !videoFilesDone.has(row.VideoFiles.id)) {
-        const videoFileModel = new VideoFileModel(pick(row.VideoFiles, videoFileKeys))
-        videoModel.VideoFiles.push(videoFileModel)
-
-        videoFilesDone.add(row.VideoFiles.id)
-      }
-
       if (row.VideoStreamingPlaylists?.id && !videoStreamingPlaylistMemo[row.VideoStreamingPlaylists.id]) {
         const streamingPlaylist = new VideoStreamingPlaylistModel(pick(row.VideoStreamingPlaylists, videoStreamingPlaylistKeys))
         streamingPlaylist.VideoFiles = []
@@ -1921,6 +1929,10 @@ export class VideoModel extends Model<VideoModel> {
     return isPrivacyForFederation(this.privacy)
   }
 
+  hasStateForFederation () {
+    return isStateForFederation(this.state)
+  }
+
   isNewVideo (newPrivacy: VideoPrivacy) {
     return this.hasPrivacyForFederation() === false && isPrivacyForFederation(newPrivacy) === true
   }