diff options
author | Chocobozzz <me@florianbigard.com> | 2021-11-03 11:32:41 +0100 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2021-11-03 11:32:41 +0100 |
commit | d324756edb836672f12284cd18e642a658b273d8 (patch) | |
tree | 3b323682bd7380491ad904daaeaea10be606e0f9 /server/models/video/sql | |
parent | d5d9c5b79edf613e97a752a3d59062fb42045275 (diff) | |
download | PeerTube-d324756edb836672f12284cd18e642a658b273d8.tar.gz PeerTube-d324756edb836672f12284cd18e642a658b273d8.tar.zst PeerTube-d324756edb836672f12284cd18e642a658b273d8.zip |
Add ability to filter by file type
Diffstat (limited to 'server/models/video/sql')
-rw-r--r-- | server/models/video/sql/videos-id-list-query-builder.ts | 45 |
1 files changed, 35 insertions, 10 deletions
diff --git a/server/models/video/sql/videos-id-list-query-builder.ts b/server/models/video/sql/videos-id-list-query-builder.ts index 5064afafe..4a882e790 100644 --- a/server/models/video/sql/videos-id-list-query-builder.ts +++ b/server/models/video/sql/videos-id-list-query-builder.ts | |||
@@ -44,6 +44,8 @@ export type BuildVideosListQueryOptions = { | |||
44 | uuids?: string[] | 44 | uuids?: string[] |
45 | 45 | ||
46 | hasFiles?: boolean | 46 | hasFiles?: boolean |
47 | hasHLSFiles?: boolean | ||
48 | hasWebtorrentFiles?: boolean | ||
47 | 49 | ||
48 | accountId?: number | 50 | accountId?: number |
49 | videoChannelId?: number | 51 | videoChannelId?: number |
@@ -169,6 +171,14 @@ export class VideosIdListQueryBuilder extends AbstractRunQuery { | |||
169 | this.whereFileExists() | 171 | this.whereFileExists() |
170 | } | 172 | } |
171 | 173 | ||
174 | if (exists(options.hasWebtorrentFiles)) { | ||
175 | this.whereWebTorrentFileExists(options.hasWebtorrentFiles) | ||
176 | } | ||
177 | |||
178 | if (exists(options.hasHLSFiles)) { | ||
179 | this.whereHLSFileExists(options.hasHLSFiles) | ||
180 | } | ||
181 | |||
172 | if (options.tagsOneOf) { | 182 | if (options.tagsOneOf) { |
173 | this.whereTagsOneOf(options.tagsOneOf) | 183 | this.whereTagsOneOf(options.tagsOneOf) |
174 | } | 184 | } |
@@ -371,16 +381,31 @@ export class VideosIdListQueryBuilder extends AbstractRunQuery { | |||
371 | } | 381 | } |
372 | 382 | ||
373 | private whereFileExists () { | 383 | private whereFileExists () { |
374 | this.and.push( | 384 | this.and.push(`(${this.buildWebTorrentFileExistsQuery(true)} OR ${this.buildHLSFileExistsQuery(true)})`) |
375 | '(' + | 385 | } |
376 | ' EXISTS (SELECT 1 FROM "videoFile" WHERE "videoFile"."videoId" = "video"."id") ' + | 386 | |
377 | ' OR EXISTS (' + | 387 | private whereWebTorrentFileExists (exists: boolean) { |
378 | ' SELECT 1 FROM "videoStreamingPlaylist" ' + | 388 | this.and.push(this.buildWebTorrentFileExistsQuery(exists)) |
379 | ' INNER JOIN "videoFile" ON "videoFile"."videoStreamingPlaylistId" = "videoStreamingPlaylist"."id" ' + | 389 | } |
380 | ' WHERE "videoStreamingPlaylist"."videoId" = "video"."id"' + | 390 | |
381 | ' )' + | 391 | private whereHLSFileExists (exists: boolean) { |
382 | ')' | 392 | this.and.push(this.buildHLSFileExistsQuery(exists)) |
383 | ) | 393 | } |
394 | |||
395 | private buildWebTorrentFileExistsQuery (exists: boolean) { | ||
396 | const prefix = exists ? '' : 'NOT ' | ||
397 | |||
398 | return prefix + 'EXISTS (SELECT 1 FROM "videoFile" WHERE "videoFile"."videoId" = "video"."id")' | ||
399 | } | ||
400 | |||
401 | private buildHLSFileExistsQuery (exists: boolean) { | ||
402 | const prefix = exists ? '' : 'NOT ' | ||
403 | |||
404 | return prefix + 'EXISTS (' + | ||
405 | ' SELECT 1 FROM "videoStreamingPlaylist" ' + | ||
406 | ' INNER JOIN "videoFile" ON "videoFile"."videoStreamingPlaylistId" = "videoStreamingPlaylist"."id" ' + | ||
407 | ' WHERE "videoStreamingPlaylist"."videoId" = "video"."id"' + | ||
408 | ')' | ||
384 | } | 409 | } |
385 | 410 | ||
386 | private whereTagsOneOf (tagsOneOf: string[]) { | 411 | private whereTagsOneOf (tagsOneOf: string[]) { |