aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/models
diff options
context:
space:
mode:
Diffstat (limited to 'server/models')
-rw-r--r--server/models/video/sql/shared/abstract-run-query.ts (renamed from server/models/video/sql/shared/abstract-videos-query-builder.ts)2
-rw-r--r--server/models/video/sql/shared/abstract-video-query-builder.ts (renamed from server/models/video/sql/shared/abstract-videos-model-query-builder.ts)10
-rw-r--r--server/models/video/sql/shared/video-file-query-builder.ts4
-rw-r--r--server/models/video/sql/shared/video-model-builder.ts4
-rw-r--r--server/models/video/sql/shared/video-table-attributes.ts (renamed from server/models/video/sql/shared/video-tables.ts)32
-rw-r--r--server/models/video/sql/video-model-get-query-builder.ts11
-rw-r--r--server/models/video/sql/videos-id-list-query-builder.ts6
-rw-r--r--server/models/video/sql/videos-model-list-query-builder.ts10
8 files changed, 39 insertions, 40 deletions
diff --git a/server/models/video/sql/shared/abstract-videos-query-builder.ts b/server/models/video/sql/shared/abstract-run-query.ts
index 09776bcb0..8e7a7642d 100644
--- a/server/models/video/sql/shared/abstract-videos-query-builder.ts
+++ b/server/models/video/sql/shared/abstract-run-query.ts
@@ -6,7 +6,7 @@ import { QueryTypes, Sequelize, Transaction } from 'sequelize'
6 * 6 *
7 */ 7 */
8 8
9export class AbstractVideosQueryBuilder { 9export class AbstractRunQuery {
10 protected sequelize: Sequelize 10 protected sequelize: Sequelize
11 11
12 protected query: string 12 protected query: string
diff --git a/server/models/video/sql/shared/abstract-videos-model-query-builder.ts b/server/models/video/sql/shared/abstract-video-query-builder.ts
index 29827db2a..a6afb04e4 100644
--- a/server/models/video/sql/shared/abstract-videos-model-query-builder.ts
+++ b/server/models/video/sql/shared/abstract-video-query-builder.ts
@@ -1,8 +1,8 @@
1import { createSafeIn } from '@server/models/utils' 1import { createSafeIn } from '@server/models/utils'
2import { MUserAccountId } from '@server/types/models' 2import { MUserAccountId } from '@server/types/models'
3import validator from 'validator' 3import validator from 'validator'
4import { AbstractVideosQueryBuilder } from './abstract-videos-query-builder' 4import { AbstractRunQuery } from './abstract-run-query'
5import { VideoTables } from './video-tables' 5import { VideoTableAttributes } from './video-table-attributes'
6 6
7/** 7/**
8 * 8 *
@@ -10,18 +10,18 @@ import { VideoTables } from './video-tables'
10 * 10 *
11 */ 11 */
12 12
13export class AbstractVideosModelQueryBuilder extends AbstractVideosQueryBuilder { 13export class AbstractVideoQueryBuilder extends AbstractRunQuery {
14 protected attributes: { [key: string]: string } = {} 14 protected attributes: { [key: string]: string } = {}
15 15
16 protected joins = '' 16 protected joins = ''
17 protected where: string 17 protected where: string
18 18
19 protected tables: VideoTables 19 protected tables: VideoTableAttributes
20 20
21 constructor (protected readonly mode: 'list' | 'get') { 21 constructor (protected readonly mode: 'list' | 'get') {
22 super() 22 super()
23 23
24 this.tables = new VideoTables(this.mode) 24 this.tables = new VideoTableAttributes(this.mode)
25 } 25 }
26 26
27 protected buildSelect () { 27 protected buildSelect () {
diff --git a/server/models/video/sql/shared/video-file-query-builder.ts b/server/models/video/sql/shared/video-file-query-builder.ts
index 6b15c3b69..3eb3dc07d 100644
--- a/server/models/video/sql/shared/video-file-query-builder.ts
+++ b/server/models/video/sql/shared/video-file-query-builder.ts
@@ -1,6 +1,6 @@
1import { Sequelize } from 'sequelize' 1import { Sequelize } from 'sequelize'
2import { BuildVideoGetQueryOptions } from '../video-model-get-query-builder' 2import { BuildVideoGetQueryOptions } from '../video-model-get-query-builder'
3import { AbstractVideosModelQueryBuilder } from './abstract-videos-model-query-builder' 3import { AbstractVideoQueryBuilder } from './abstract-video-query-builder'
4 4
5/** 5/**
6 * 6 *
@@ -8,7 +8,7 @@ import { AbstractVideosModelQueryBuilder } from './abstract-videos-model-query-b
8 * 8 *
9 */ 9 */
10 10
11export class VideoFileQueryBuilder extends AbstractVideosModelQueryBuilder { 11export class VideoFileQueryBuilder extends AbstractVideoQueryBuilder {
12 protected attributes: { [key: string]: string } 12 protected attributes: { [key: string]: string }
13 13
14 constructor (protected readonly sequelize: Sequelize) { 14 constructor (protected readonly sequelize: Sequelize) {
diff --git a/server/models/video/sql/shared/video-model-builder.ts b/server/models/video/sql/shared/video-model-builder.ts
index 0eac95661..7751d8e68 100644
--- a/server/models/video/sql/shared/video-model-builder.ts
+++ b/server/models/video/sql/shared/video-model-builder.ts
@@ -18,7 +18,7 @@ import { VideoChannelModel } from '../../video-channel'
18import { VideoFileModel } from '../../video-file' 18import { VideoFileModel } from '../../video-file'
19import { VideoLiveModel } from '../../video-live' 19import { VideoLiveModel } from '../../video-live'
20import { VideoStreamingPlaylistModel } from '../../video-streaming-playlist' 20import { VideoStreamingPlaylistModel } from '../../video-streaming-playlist'
21import { VideoTables } from './video-tables' 21import { VideoTableAttributes } from './video-table-attributes'
22 22
23type SQLRow = { [id: string]: string | number } 23type SQLRow = { [id: string]: string | number }
24 24
@@ -51,7 +51,7 @@ export class VideoModelBuilder {
51 51
52 constructor ( 52 constructor (
53 readonly mode: 'get' | 'list', 53 readonly mode: 'get' | 'list',
54 readonly tables: VideoTables 54 readonly tables: VideoTableAttributes
55 ) { 55 ) {
56 56
57 } 57 }
diff --git a/server/models/video/sql/shared/video-tables.ts b/server/models/video/sql/shared/video-table-attributes.ts
index 042b9d5da..8a8d2073a 100644
--- a/server/models/video/sql/shared/video-tables.ts
+++ b/server/models/video/sql/shared/video-table-attributes.ts
@@ -4,7 +4,7 @@
4 * Class to build video attributes/join names we want to fetch from the database 4 * Class to build video attributes/join names we want to fetch from the database
5 * 5 *
6 */ 6 */
7export class VideoTables { 7export class VideoTableAttributes {
8 8
9 constructor (readonly mode: 'get' | 'list') { 9 constructor (readonly mode: 'get' | 'list') {
10 10
@@ -93,22 +93,20 @@ export class VideoTables {
93 } 93 }
94 94
95 getStreamingPlaylistAttributes () { 95 getStreamingPlaylistAttributes () {
96 let playlistKeys = [ 'id', 'playlistUrl', 'playlistFilename', 'type' ] 96 return [
97 97 'id',
98 if (this.mode === 'get') { 98 'playlistUrl',
99 playlistKeys = playlistKeys.concat([ 99 'playlistFilename',
100 'p2pMediaLoaderInfohashes', 100 'type',
101 'p2pMediaLoaderPeerVersion', 101 'p2pMediaLoaderInfohashes',
102 'segmentsSha256Filename', 102 'p2pMediaLoaderPeerVersion',
103 'segmentsSha256Url', 103 'segmentsSha256Filename',
104 'videoId', 104 'segmentsSha256Url',
105 'createdAt', 105 'videoId',
106 'updatedAt', 106 'createdAt',
107 'storage' 107 'updatedAt',
108 ]) 108 'storage'
109 } 109 ]
110
111 return playlistKeys
112 } 110 }
113 111
114 getUserHistoryAttributes () { 112 getUserHistoryAttributes () {
diff --git a/server/models/video/sql/video-model-get-query-builder.ts b/server/models/video/sql/video-model-get-query-builder.ts
index 2f34d5602..a65c96097 100644
--- a/server/models/video/sql/video-model-get-query-builder.ts
+++ b/server/models/video/sql/video-model-get-query-builder.ts
@@ -1,8 +1,8 @@
1import { Sequelize, Transaction } from 'sequelize' 1import { Sequelize, Transaction } from 'sequelize'
2import { AbstractVideosModelQueryBuilder } from './shared/abstract-videos-model-query-builder' 2import { AbstractVideoQueryBuilder } from './shared/abstract-video-query-builder'
3import { VideoFileQueryBuilder } from './shared/video-file-query-builder' 3import { VideoFileQueryBuilder } from './shared/video-file-query-builder'
4import { VideoModelBuilder } from './shared/video-model-builder' 4import { VideoModelBuilder } from './shared/video-model-builder'
5import { VideoTables } from './shared/video-tables' 5import { VideoTableAttributes } from './shared/video-table-attributes'
6 6
7/** 7/**
8 * 8 *
@@ -46,7 +46,7 @@ export class VideoModelGetQueryBuilder {
46 this.webtorrentFilesQueryBuilder = new VideoFileQueryBuilder(sequelize) 46 this.webtorrentFilesQueryBuilder = new VideoFileQueryBuilder(sequelize)
47 this.streamingPlaylistFilesQueryBuilder = new VideoFileQueryBuilder(sequelize) 47 this.streamingPlaylistFilesQueryBuilder = new VideoFileQueryBuilder(sequelize)
48 48
49 this.videoModelBuilder = new VideoModelBuilder('get', new VideoTables('get')) 49 this.videoModelBuilder = new VideoModelBuilder('get', new VideoTableAttributes('get'))
50 } 50 }
51 51
52 async queryVideo (options: BuildVideoGetQueryOptions) { 52 async queryVideo (options: BuildVideoGetQueryOptions) {
@@ -69,15 +69,16 @@ export class VideoModelGetQueryBuilder {
69 }) 69 })
70 70
71 if (videos.length > 1) { 71 if (videos.length > 1) {
72 throw new Error('Video results is more than ') 72 throw new Error('Video results is more than 1')
73 } 73 }
74 74
75 if (videos.length === 0) return null 75 if (videos.length === 0) return null
76
76 return videos[0] 77 return videos[0]
77 } 78 }
78} 79}
79 80
80export class VideosModelGetQuerySubBuilder extends AbstractVideosModelQueryBuilder { 81export class VideosModelGetQuerySubBuilder extends AbstractVideoQueryBuilder {
81 protected attributes: { [key: string]: string } 82 protected attributes: { [key: string]: string }
82 83
83 protected webtorrentFilesQuery: string 84 protected webtorrentFilesQuery: string
diff --git a/server/models/video/sql/videos-id-list-query-builder.ts b/server/models/video/sql/videos-id-list-query-builder.ts
index 4d6e0ea4b..5064afafe 100644
--- a/server/models/video/sql/videos-id-list-query-builder.ts
+++ b/server/models/video/sql/videos-id-list-query-builder.ts
@@ -5,7 +5,7 @@ import { WEBSERVER } from '@server/initializers/constants'
5import { buildDirectionAndField, createSafeIn } from '@server/models/utils' 5import { buildDirectionAndField, createSafeIn } from '@server/models/utils'
6import { MUserAccountId, MUserId } from '@server/types/models' 6import { MUserAccountId, MUserId } from '@server/types/models'
7import { VideoInclude, VideoPrivacy, VideoState } from '@shared/models' 7import { VideoInclude, VideoPrivacy, VideoState } from '@shared/models'
8import { AbstractVideosQueryBuilder } from './shared/abstract-videos-query-builder' 8import { AbstractRunQuery } from './shared/abstract-run-query'
9 9
10/** 10/**
11 * 11 *
@@ -72,7 +72,7 @@ export type BuildVideosListQueryOptions = {
72 having?: string 72 having?: string
73} 73}
74 74
75export class VideosIdListQueryBuilder extends AbstractVideosQueryBuilder { 75export class VideosIdListQueryBuilder extends AbstractRunQuery {
76 protected replacements: any = {} 76 protected replacements: any = {}
77 77
78 private attributes: string[] 78 private attributes: string[]
@@ -105,7 +105,7 @@ export class VideosIdListQueryBuilder extends AbstractVideosQueryBuilder {
105 return this.runQuery().then(rows => rows.length !== 0 ? rows[0].total : 0) 105 return this.runQuery().then(rows => rows.length !== 0 ? rows[0].total : 0)
106 } 106 }
107 107
108 getIdsListQueryAndSort (options: BuildVideosListQueryOptions) { 108 getQuery (options: BuildVideosListQueryOptions) {
109 this.buildIdsListQuery(options) 109 this.buildIdsListQuery(options)
110 110
111 return { query: this.query, sort: this.sort, replacements: this.replacements } 111 return { query: this.query, sort: this.sort, replacements: this.replacements }
diff --git a/server/models/video/sql/videos-model-list-query-builder.ts b/server/models/video/sql/videos-model-list-query-builder.ts
index cd721f055..b15b29ec3 100644
--- a/server/models/video/sql/videos-model-list-query-builder.ts
+++ b/server/models/video/sql/videos-model-list-query-builder.ts
@@ -1,6 +1,6 @@
1import { VideoInclude } from '@shared/models' 1import { VideoInclude } from '@shared/models'
2import { Sequelize } from 'sequelize' 2import { Sequelize } from 'sequelize'
3import { AbstractVideosModelQueryBuilder } from './shared/abstract-videos-model-query-builder' 3import { AbstractVideoQueryBuilder } from './shared/abstract-video-query-builder'
4import { VideoModelBuilder } from './shared/video-model-builder' 4import { VideoModelBuilder } from './shared/video-model-builder'
5import { BuildVideosListQueryOptions, VideosIdListQueryBuilder } from './videos-id-list-query-builder' 5import { BuildVideosListQueryOptions, VideosIdListQueryBuilder } from './videos-id-list-query-builder'
6 6
@@ -10,7 +10,7 @@ import { BuildVideosListQueryOptions, VideosIdListQueryBuilder } from './videos-
10 * 10 *
11 */ 11 */
12 12
13export class VideosModelListQueryBuilder extends AbstractVideosModelQueryBuilder { 13export class VideosModelListQueryBuilder extends AbstractVideoQueryBuilder {
14 protected attributes: { [key: string]: string } 14 protected attributes: { [key: string]: string }
15 15
16 private innerQuery: string 16 private innerQuery: string
@@ -26,7 +26,7 @@ export class VideosModelListQueryBuilder extends AbstractVideosModelQueryBuilder
26 26
27 queryVideos (options: BuildVideosListQueryOptions) { 27 queryVideos (options: BuildVideosListQueryOptions) {
28 this.buildInnerQuery(options) 28 this.buildInnerQuery(options)
29 this.buildListQueryFromIdsQuery(options) 29 this.buildMainQuery(options)
30 30
31 return this.runQuery() 31 return this.runQuery()
32 .then(rows => this.videoModelBuilder.buildVideosFromRows({ rows, include: options.include })) 32 .then(rows => this.videoModelBuilder.buildVideosFromRows({ rows, include: options.include }))
@@ -34,14 +34,14 @@ export class VideosModelListQueryBuilder extends AbstractVideosModelQueryBuilder
34 34
35 private buildInnerQuery (options: BuildVideosListQueryOptions) { 35 private buildInnerQuery (options: BuildVideosListQueryOptions) {
36 const idsQueryBuilder = new VideosIdListQueryBuilder(this.sequelize) 36 const idsQueryBuilder = new VideosIdListQueryBuilder(this.sequelize)
37 const { query, sort, replacements } = idsQueryBuilder.getIdsListQueryAndSort(options) 37 const { query, sort, replacements } = idsQueryBuilder.getQuery(options)
38 38
39 this.replacements = replacements 39 this.replacements = replacements
40 this.innerQuery = query 40 this.innerQuery = query
41 this.innerSort = sort 41 this.innerSort = sort
42 } 42 }
43 43
44 private buildListQueryFromIdsQuery (options: BuildVideosListQueryOptions) { 44 private buildMainQuery (options: BuildVideosListQueryOptions) {
45 this.attributes = { 45 this.attributes = {
46 '"video".*': '' 46 '"video".*': ''
47 } 47 }