diff options
Diffstat (limited to 'server/models/video/sql/shared/video-file-query-builder.ts')
-rw-r--r-- | server/models/video/sql/shared/video-file-query-builder.ts | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/server/models/video/sql/shared/video-file-query-builder.ts b/server/models/video/sql/shared/video-file-query-builder.ts new file mode 100644 index 000000000..29b11a298 --- /dev/null +++ b/server/models/video/sql/shared/video-file-query-builder.ts | |||
@@ -0,0 +1,66 @@ | |||
1 | import { Sequelize } from 'sequelize' | ||
2 | import { BuildVideoGetQueryOptions } from '../video-model-get-query-builder' | ||
3 | import { AbstractVideosModelQueryBuilder } from './abstract-videos-model-query-builder' | ||
4 | |||
5 | /** | ||
6 | * | ||
7 | * Fetch files (webtorrent and streaming playlist) according to a video | ||
8 | * | ||
9 | */ | ||
10 | |||
11 | export class VideoFileQueryBuilder extends AbstractVideosModelQueryBuilder { | ||
12 | protected attributes: { [key: string]: string } | ||
13 | protected joins: string[] = [] | ||
14 | |||
15 | constructor (protected readonly sequelize: Sequelize) { | ||
16 | super('get') | ||
17 | } | ||
18 | |||
19 | queryWebTorrentVideos (options: BuildVideoGetQueryOptions) { | ||
20 | this.buildWebtorrentFilesQuery(options) | ||
21 | |||
22 | return this.runQuery(options.transaction, true) | ||
23 | } | ||
24 | |||
25 | queryStreamingPlaylistVideos (options: BuildVideoGetQueryOptions) { | ||
26 | this.buildVideoStreamingPlaylistFilesQuery(options) | ||
27 | |||
28 | return this.runQuery(options.transaction, true) | ||
29 | } | ||
30 | |||
31 | private buildWebtorrentFilesQuery (options: BuildVideoGetQueryOptions) { | ||
32 | this.attributes = { | ||
33 | '"video"."id"': '' | ||
34 | } | ||
35 | |||
36 | this.includeWebtorrentFiles(true) | ||
37 | |||
38 | if (options.forGetAPI === true) { | ||
39 | this.includeWebTorrentRedundancies() | ||
40 | } | ||
41 | |||
42 | this.whereId(options.id) | ||
43 | |||
44 | this.query = this.buildQuery() | ||
45 | } | ||
46 | |||
47 | private buildVideoStreamingPlaylistFilesQuery (options: BuildVideoGetQueryOptions) { | ||
48 | this.attributes = { | ||
49 | '"video"."id"': '' | ||
50 | } | ||
51 | |||
52 | this.includeStreamingPlaylistFiles(true) | ||
53 | |||
54 | if (options.forGetAPI === true) { | ||
55 | this.includeStreamingPlaylistRedundancies() | ||
56 | } | ||
57 | |||
58 | this.whereId(options.id) | ||
59 | |||
60 | this.query = this.buildQuery() | ||
61 | } | ||
62 | |||
63 | private buildQuery () { | ||
64 | return `${this.buildSelect()} FROM "video" ${this.joins.join(' ')} ${this.where}` | ||
65 | } | ||
66 | } | ||