PeerTube/server/models/video/sql/shared/video-file-query-builder.ts

70 lines
1.7 KiB
TypeScript
Raw Normal View History

2021-06-10 09:57:13 -05:00
import { Sequelize } from 'sequelize'
import { BuildVideoGetQueryOptions } from '../video-model-get-query-builder'
2021-11-02 05:00:40 -05:00
import { AbstractVideoQueryBuilder } from './abstract-video-query-builder'
2021-06-10 09:57:13 -05:00
/**
*
* Fetch files (webtorrent and streaming playlist) according to a video
*
*/
2021-11-02 05:00:40 -05:00
export class VideoFileQueryBuilder extends AbstractVideoQueryBuilder {
2021-06-10 09:57:13 -05:00
protected attributes: { [key: string]: string }
constructor (protected readonly sequelize: Sequelize) {
super('get')
}
queryWebTorrentVideos (options: BuildVideoGetQueryOptions) {
this.buildWebtorrentFilesQuery(options)
2021-06-11 07:09:33 -05:00
return this.runQuery(options)
2021-06-10 09:57:13 -05:00
}
queryStreamingPlaylistVideos (options: BuildVideoGetQueryOptions) {
this.buildVideoStreamingPlaylistFilesQuery(options)
2021-06-11 07:09:33 -05:00
return this.runQuery(options)
2021-06-10 09:57:13 -05:00
}
private buildWebtorrentFilesQuery (options: BuildVideoGetQueryOptions) {
this.attributes = {
'"video"."id"': ''
}
2021-06-11 09:02:26 -05:00
this.includeWebtorrentFiles()
2021-06-10 09:57:13 -05:00
2021-06-11 07:09:33 -05:00
if (this.shouldIncludeRedundancies(options)) {
2021-06-10 09:57:13 -05:00
this.includeWebTorrentRedundancies()
}
2021-06-11 07:09:33 -05:00
this.whereId(options)
2021-06-10 09:57:13 -05:00
this.query = this.buildQuery()
}
private buildVideoStreamingPlaylistFilesQuery (options: BuildVideoGetQueryOptions) {
this.attributes = {
'"video"."id"': ''
}
2021-06-11 09:02:26 -05:00
this.includeStreamingPlaylistFiles()
2021-06-10 09:57:13 -05:00
2021-06-11 07:09:33 -05:00
if (this.shouldIncludeRedundancies(options)) {
2021-06-10 09:57:13 -05:00
this.includeStreamingPlaylistRedundancies()
}
2021-06-11 07:09:33 -05:00
this.whereId(options)
2021-06-10 09:57:13 -05:00
this.query = this.buildQuery()
}
private buildQuery () {
2021-06-11 04:27:45 -05:00
return `${this.buildSelect()} FROM "video" ${this.joins} ${this.where}`
2021-06-10 09:57:13 -05:00
}
2021-06-11 07:09:33 -05:00
private shouldIncludeRedundancies (options: BuildVideoGetQueryOptions) {
return options.type === 'api'
}
2021-06-10 09:57:13 -05:00
}