- this.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"' +
- ' )' +
- ')'
- )
+ this.and.push(`(${this.buildWebTorrentFileExistsQuery(true)} OR ${this.buildHLSFileExistsQuery(true)})`)
+ }
+
+ private whereWebTorrentFileExists (exists: boolean) {
+ this.and.push(this.buildWebTorrentFileExistsQuery(exists))
+ }
+
+ private whereHLSFileExists (exists: boolean) {
+ this.and.push(this.buildHLSFileExistsQuery(exists))
+ }
+
+ private buildWebTorrentFileExistsQuery (exists: boolean) {
+ const prefix = exists ? '' : 'NOT '
+
+ return prefix + 'EXISTS (SELECT 1 FROM "videoFile" WHERE "videoFile"."videoId" = "video"."id")'
+ }
+
+ private buildHLSFileExistsQuery (exists: boolean) {
+ const prefix = exists ? '' : 'NOT '
+
+ return prefix + 'EXISTS (' +
+ ' SELECT 1 FROM "videoStreamingPlaylist" ' +
+ ' INNER JOIN "videoFile" ON "videoFile"."videoStreamingPlaylistId" = "videoStreamingPlaylist"."id" ' +
+ ' WHERE "videoStreamingPlaylist"."videoId" = "video"."id"' +
+ ')'