]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/models/video/video-query-builder.ts
Add permanent live support
[github/Chocobozzz/PeerTube.git] / server / models / video / video-query-builder.ts
index 984b0e6af2db32a25727f827a7fa01b906cb2b7c..25d5042b79e47174e9d50e02012e543a04258714 100644 (file)
@@ -89,7 +89,7 @@ function buildListQuery (model: typeof Model, options: BuildVideosQueryOptions)
   }
 
   // Only list public/published videos
-  if (!options.filter || options.filter !== 'all-local') {
+  if (!options.filter || (options.filter !== 'all-local' && options.filter !== 'all')) {
     and.push(
       `("video"."state" = ${VideoState.PUBLISHED} OR ` +
       `("video"."state" = ${VideoState.TO_TRANSCODE} AND "video"."waitTranscoding" IS false))`
@@ -156,7 +156,16 @@ function buildListQuery (model: typeof Model, options: BuildVideosQueryOptions)
   }
 
   if (options.withFiles === true) {
-    and.push('EXISTS (SELECT 1 FROM "videoFile" WHERE "videoFile"."videoId" = "video"."id")')
+    and.push(
+      '(' +
+      '  EXISTS (SELECT 1 FROM "videoFile" WHERE "videoFile"."videoId" = "video"."id") ' +
+      '  OR EXISTS (' +
+      '    SELECT 1 FROM "videoStreamingPlaylist" ' +
+      '    INNER JOIN "videoFile" ON "videoFile"."videoStreamingPlaylistId" = "videoStreamingPlaylist"."id" ' +
+      '    WHERE "videoStreamingPlaylist"."videoId" = "video"."id"' +
+      '  )' +
+      ')'
+    )
   }
 
   if (options.tagsOneOf) {
@@ -327,7 +336,7 @@ function buildListQuery (model: typeof Model, options: BuildVideosQueryOptions)
         attributes.push('COALESCE("video"."originallyPublishedAt", "video"."publishedAt") AS "publishedAtForOrder"')
       }
 
-      order = buildOrder(model, options.sort)
+      order = buildOrder(options.sort)
       suffix += `${order} `
     }
 
@@ -357,7 +366,7 @@ function buildListQuery (model: typeof Model, options: BuildVideosQueryOptions)
   return { query, replacements, order }
 }
 
-function buildOrder (model: typeof Model, value: string) {
+function buildOrder (value: string) {
   const { direction, field } = buildDirectionAndField(value)
   if (field.match(/^[a-zA-Z."]+$/) === null) throw new Error('Invalid sort column ' + field)
 
@@ -443,7 +452,13 @@ function wrapForAPIResults (baseQuery: string, replacements: any, options: Build
   ]
 
   if (options.withFiles) {
-    joins.push('INNER JOIN "videoFile" AS "VideoFiles" ON "VideoFiles"."videoId" = "video"."id"')
+    joins.push('LEFT JOIN "videoFile" AS "VideoFiles" ON "VideoFiles"."videoId" = "video"."id"')
+
+    joins.push('LEFT JOIN "videoStreamingPlaylist" AS "VideoStreamingPlaylists" ON "VideoStreamingPlaylists"."videoId" = "video"."id"')
+    joins.push(
+      'LEFT JOIN "videoFile" AS "VideoStreamingPlaylists->VideoFiles" ' +
+        'ON "VideoStreamingPlaylists->VideoFiles"."videoStreamingPlaylistId" = "VideoStreamingPlaylists"."id"'
+    )
 
     Object.assign(attributes, {
       '"VideoFiles"."id"': '"VideoFiles.id"',
@@ -454,7 +469,18 @@ function wrapForAPIResults (baseQuery: string, replacements: any, options: Build
       '"VideoFiles"."extname"': '"VideoFiles.extname"',
       '"VideoFiles"."infoHash"': '"VideoFiles.infoHash"',
       '"VideoFiles"."fps"': '"VideoFiles.fps"',
-      '"VideoFiles"."videoId"': '"VideoFiles.videoId"'
+      '"VideoFiles"."videoId"': '"VideoFiles.videoId"',
+
+      '"VideoStreamingPlaylists"."id"': '"VideoStreamingPlaylists.id"',
+      '"VideoStreamingPlaylists->VideoFiles"."id"': '"VideoStreamingPlaylists.VideoFiles.id"',
+      '"VideoStreamingPlaylists->VideoFiles"."createdAt"': '"VideoStreamingPlaylists.VideoFiles.createdAt"',
+      '"VideoStreamingPlaylists->VideoFiles"."updatedAt"': '"VideoStreamingPlaylists.VideoFiles.updatedAt"',
+      '"VideoStreamingPlaylists->VideoFiles"."resolution"': '"VideoStreamingPlaylists.VideoFiles.resolution"',
+      '"VideoStreamingPlaylists->VideoFiles"."size"': '"VideoStreamingPlaylists.VideoFiles.size"',
+      '"VideoStreamingPlaylists->VideoFiles"."extname"': '"VideoStreamingPlaylists.VideoFiles.extname"',
+      '"VideoStreamingPlaylists->VideoFiles"."infoHash"': '"VideoStreamingPlaylists.VideoFiles.infoHash"',
+      '"VideoStreamingPlaylists->VideoFiles"."fps"': '"VideoStreamingPlaylists.VideoFiles.fps"',
+      '"VideoStreamingPlaylists->VideoFiles"."videoId"': '"VideoStreamingPlaylists.VideoFiles.videoId"'
     })
   }