1 import { Sequelize, Transaction } from 'sequelize'
2 import { AbstractVideoQueryBuilder } from './abstract-video-query-builder'
4 export type FileQueryOptions = {
8 includeRedundancy: boolean
10 transaction?: Transaction
17 * Fetch files (webtorrent and streaming playlist) according to a video
21 export class VideoFileQueryBuilder extends AbstractVideoQueryBuilder {
22 protected attributes: { [key: string]: string }
24 constructor (protected readonly sequelize: Sequelize) {
25 super(sequelize, 'get')
28 queryWebTorrentVideos (options: FileQueryOptions) {
29 this.buildWebtorrentFilesQuery(options)
31 return this.runQuery(options)
34 queryStreamingPlaylistVideos (options: FileQueryOptions) {
35 this.buildVideoStreamingPlaylistFilesQuery(options)
37 return this.runQuery(options)
40 private buildWebtorrentFilesQuery (options: FileQueryOptions) {
45 this.includeWebtorrentFiles()
47 if (options.includeRedundancy) {
48 this.includeWebTorrentRedundancies()
53 this.query = this.buildQuery()
56 private buildVideoStreamingPlaylistFilesQuery (options: FileQueryOptions) {
61 this.includeStreamingPlaylistFiles()
63 if (options.includeRedundancy) {
64 this.includeStreamingPlaylistRedundancies()
69 this.query = this.buildQuery()
72 private buildQuery () {
73 return `${this.buildSelect()} FROM "video" ${this.joins} ${this.where}`