]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/models/video/video-query-builder.ts
Add live notification tests
[github/Chocobozzz/PeerTube.git] / server / models / video / video-query-builder.ts
index 466890364522889f5c9074f18961b0fedb5f6eb0..b14bb16d693cde242d54db9293d338d933f6768f 100644 (file)
@@ -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) {
@@ -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"'
     })
   }