]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/models/video/sql/video/shared/video-file-query-builder.ts
Feature/Add replay privacy (#5692)
[github/Chocobozzz/PeerTube.git] / server / models / video / sql / video / shared / video-file-query-builder.ts
1 import { Sequelize, Transaction } from 'sequelize'
2 import { AbstractVideoQueryBuilder } from './abstract-video-query-builder'
3
4 export type FileQueryOptions = {
5 id?: string | number
6 url?: string
7
8 includeRedundancy: boolean
9
10 transaction?: Transaction
11
12 logging?: boolean
13 }
14
15 /**
16 *
17 * Fetch files (webtorrent and streaming playlist) according to a video
18 *
19 */
20
21 export class VideoFileQueryBuilder extends AbstractVideoQueryBuilder {
22 protected attributes: { [key: string]: string }
23
24 constructor (protected readonly sequelize: Sequelize) {
25 super(sequelize, 'get')
26 }
27
28 queryWebTorrentVideos (options: FileQueryOptions) {
29 this.buildWebtorrentFilesQuery(options)
30
31 return this.runQuery(options)
32 }
33
34 queryStreamingPlaylistVideos (options: FileQueryOptions) {
35 this.buildVideoStreamingPlaylistFilesQuery(options)
36
37 return this.runQuery(options)
38 }
39
40 private buildWebtorrentFilesQuery (options: FileQueryOptions) {
41 this.attributes = {
42 '"video"."id"': ''
43 }
44
45 this.includeWebtorrentFiles()
46
47 if (options.includeRedundancy) {
48 this.includeWebTorrentRedundancies()
49 }
50
51 this.whereId(options)
52
53 this.query = this.buildQuery()
54 }
55
56 private buildVideoStreamingPlaylistFilesQuery (options: FileQueryOptions) {
57 this.attributes = {
58 '"video"."id"': ''
59 }
60
61 this.includeStreamingPlaylistFiles()
62
63 if (options.includeRedundancy) {
64 this.includeStreamingPlaylistRedundancies()
65 }
66
67 this.whereId(options)
68
69 this.query = this.buildQuery()
70 }
71
72 private buildQuery () {
73 return `${this.buildSelect()} FROM "video" ${this.joins} ${this.where}`
74 }
75 }