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 }
14 constructor (protected readonly sequelize: Sequelize) {
18 queryWebTorrentVideos (options: BuildVideoGetQueryOptions) {
19 this.buildWebtorrentFilesQuery(options)
21 return this.runQuery(options)
24 queryStreamingPlaylistVideos (options: BuildVideoGetQueryOptions) {
25 this.buildVideoStreamingPlaylistFilesQuery(options)
27 return this.runQuery(options)
30 private buildWebtorrentFilesQuery (options: BuildVideoGetQueryOptions) {
35 this.includeWebtorrentFiles()
37 if (this.shouldIncludeRedundancies(options)) {
38 this.includeWebTorrentRedundancies()
43 this.query = this.buildQuery()
46 private buildVideoStreamingPlaylistFilesQuery (options: BuildVideoGetQueryOptions) {
51 this.includeStreamingPlaylistFiles()
53 if (this.shouldIncludeRedundancies(options)) {
54 this.includeStreamingPlaylistRedundancies()
59 this.query = this.buildQuery()
62 private buildQuery () {
63 return `${this.buildSelect()} FROM "video" ${this.joins} ${this.where}`
66 private shouldIncludeRedundancies (options: BuildVideoGetQueryOptions) {
67 return options.type === 'api'