1 import { Sequelize } from 'sequelize'
2 import { BuildVideoGetQueryOptions } from '../video-model-get-query-builder'
3 import { AbstractVideosModelQueryBuilder } from './abstract-videos-model-query-builder'
7 * Fetch files (webtorrent and streaming playlist) according to a video
11 export class VideoFileQueryBuilder extends AbstractVideosModelQueryBuilder {
12 protected attributes: { [key: string]: string }
13 protected joins: string[] = []
15 constructor (protected readonly sequelize: Sequelize) {
19 queryWebTorrentVideos (options: BuildVideoGetQueryOptions) {
20 this.buildWebtorrentFilesQuery(options)
22 return this.runQuery(options.transaction, true)
25 queryStreamingPlaylistVideos (options: BuildVideoGetQueryOptions) {
26 this.buildVideoStreamingPlaylistFilesQuery(options)
28 return this.runQuery(options.transaction, true)
31 private buildWebtorrentFilesQuery (options: BuildVideoGetQueryOptions) {
36 this.includeWebtorrentFiles(true)
38 if (options.forGetAPI === true) {
39 this.includeWebTorrentRedundancies()
42 this.whereId(options.id)
44 this.query = this.buildQuery()
47 private buildVideoStreamingPlaylistFilesQuery (options: BuildVideoGetQueryOptions) {
52 this.includeStreamingPlaylistFiles(true)
54 if (options.forGetAPI === true) {
55 this.includeStreamingPlaylistRedundancies()
58 this.whereId(options.id)
60 this.query = this.buildQuery()
63 private buildQuery () {
64 return `${this.buildSelect()} FROM "video" ${this.joins.join(' ')} ${this.where}`