]>
Commit | Line | Data |
---|---|---|
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 | ||
14 | constructor (protected readonly sequelize: Sequelize) { | |
15 | super('get') | |
16 | } | |
17 | ||
18 | queryWebTorrentVideos (options: BuildVideoGetQueryOptions) { | |
19 | this.buildWebtorrentFilesQuery(options) | |
20 | ||
21 | return this.runQuery(options) | |
22 | } | |
23 | ||
24 | queryStreamingPlaylistVideos (options: BuildVideoGetQueryOptions) { | |
25 | this.buildVideoStreamingPlaylistFilesQuery(options) | |
26 | ||
27 | return this.runQuery(options) | |
28 | } | |
29 | ||
30 | private buildWebtorrentFilesQuery (options: BuildVideoGetQueryOptions) { | |
31 | this.attributes = { | |
32 | '"video"."id"': '' | |
33 | } | |
34 | ||
35 | this.includeWebtorrentFiles(true) | |
36 | ||
37 | if (this.shouldIncludeRedundancies(options)) { | |
38 | this.includeWebTorrentRedundancies() | |
39 | } | |
40 | ||
41 | this.whereId(options) | |
42 | ||
43 | this.query = this.buildQuery() | |
44 | } | |
45 | ||
46 | private buildVideoStreamingPlaylistFilesQuery (options: BuildVideoGetQueryOptions) { | |
47 | this.attributes = { | |
48 | '"video"."id"': '' | |
49 | } | |
50 | ||
51 | this.includeStreamingPlaylistFiles(true) | |
52 | ||
53 | if (this.shouldIncludeRedundancies(options)) { | |
54 | this.includeStreamingPlaylistRedundancies() | |
55 | } | |
56 | ||
57 | this.whereId(options) | |
58 | ||
59 | this.query = this.buildQuery() | |
60 | } | |
61 | ||
62 | private buildQuery () { | |
63 | return `${this.buildSelect()} FROM "video" ${this.joins} ${this.where}` | |
64 | } | |
65 | ||
66 | private shouldIncludeRedundancies (options: BuildVideoGetQueryOptions) { | |
67 | return options.type === 'api' | |
68 | } | |
69 | } |