aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/models/video/video-query-builder.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/models/video/video-query-builder.ts')
-rw-r--r--server/models/video/video-query-builder.ts22
1 files changed, 11 insertions, 11 deletions
diff --git a/server/models/video/video-query-builder.ts b/server/models/video/video-query-builder.ts
index 155afe64b..2aa5e65c8 100644
--- a/server/models/video/video-query-builder.ts
+++ b/server/models/video/video-query-builder.ts
@@ -1,9 +1,9 @@
1import { VideoFilter, VideoPrivacy, VideoState } from '@shared/models' 1import { Sequelize } from 'sequelize/types'
2import { buildDirectionAndField, createSafeIn } from '@server/models/utils'
3import { Model } from 'sequelize-typescript'
4import { MUserAccountId, MUserId } from '@server/types/models'
5import validator from 'validator' 2import validator from 'validator'
6import { exists } from '@server/helpers/custom-validators/misc' 3import { exists } from '@server/helpers/custom-validators/misc'
4import { buildDirectionAndField, createSafeIn } from '@server/models/utils'
5import { MUserAccountId, MUserId } from '@server/types/models'
6import { VideoFilter, VideoPrivacy, VideoState } from '@shared/models'
7 7
8export type BuildVideosQueryOptions = { 8export type BuildVideosQueryOptions = {
9 attributes?: string[] 9 attributes?: string[]
@@ -55,7 +55,7 @@ export type BuildVideosQueryOptions = {
55 having?: string 55 having?: string
56} 56}
57 57
58function buildListQuery (model: typeof Model, options: BuildVideosQueryOptions) { 58function buildListQuery (sequelize: Sequelize, options: BuildVideosQueryOptions) {
59 const and: string[] = [] 59 const and: string[] = []
60 const joins: string[] = [] 60 const joins: string[] = []
61 const replacements: any = {} 61 const replacements: any = {}
@@ -77,7 +77,7 @@ function buildListQuery (model: typeof Model, options: BuildVideosQueryOptions)
77 const blockerIds = [ options.serverAccountId ] 77 const blockerIds = [ options.serverAccountId ]
78 if (options.user) blockerIds.push(options.user.Account.id) 78 if (options.user) blockerIds.push(options.user.Account.id)
79 79
80 const inClause = createSafeIn(model, blockerIds) 80 const inClause = createSafeIn(sequelize, blockerIds)
81 81
82 and.push( 82 and.push(
83 'NOT EXISTS (' + 83 'NOT EXISTS (' +
@@ -179,7 +179,7 @@ function buildListQuery (model: typeof Model, options: BuildVideosQueryOptions)
179 'EXISTS (' + 179 'EXISTS (' +
180 ' SELECT 1 FROM "videoTag" ' + 180 ' SELECT 1 FROM "videoTag" ' +
181 ' INNER JOIN "tag" ON "tag"."id" = "videoTag"."tagId" ' + 181 ' INNER JOIN "tag" ON "tag"."id" = "videoTag"."tagId" ' +
182 ' WHERE lower("tag"."name") IN (' + createSafeIn(model, tagsOneOfLower) + ') ' + 182 ' WHERE lower("tag"."name") IN (' + createSafeIn(sequelize, tagsOneOfLower) + ') ' +
183 ' AND "video"."id" = "videoTag"."videoId"' + 183 ' AND "video"."id" = "videoTag"."videoId"' +
184 ')' 184 ')'
185 ) 185 )
@@ -192,7 +192,7 @@ function buildListQuery (model: typeof Model, options: BuildVideosQueryOptions)
192 'EXISTS (' + 192 'EXISTS (' +
193 ' SELECT 1 FROM "videoTag" ' + 193 ' SELECT 1 FROM "videoTag" ' +
194 ' INNER JOIN "tag" ON "tag"."id" = "videoTag"."tagId" ' + 194 ' INNER JOIN "tag" ON "tag"."id" = "videoTag"."tagId" ' +
195 ' WHERE lower("tag"."name") IN (' + createSafeIn(model, tagsAllOfLower) + ') ' + 195 ' WHERE lower("tag"."name") IN (' + createSafeIn(sequelize, tagsAllOfLower) + ') ' +
196 ' AND "video"."id" = "videoTag"."videoId" ' + 196 ' AND "video"."id" = "videoTag"."videoId" ' +
197 ' GROUP BY "videoTag"."videoId" HAVING COUNT(*) = ' + tagsAllOfLower.length + 197 ' GROUP BY "videoTag"."videoId" HAVING COUNT(*) = ' + tagsAllOfLower.length +
198 ')' 198 ')'
@@ -232,7 +232,7 @@ function buildListQuery (model: typeof Model, options: BuildVideosQueryOptions)
232 languagesQueryParts.push( 232 languagesQueryParts.push(
233 'EXISTS (' + 233 'EXISTS (' +
234 ' SELECT 1 FROM "videoCaption" WHERE "videoCaption"."language" ' + 234 ' SELECT 1 FROM "videoCaption" WHERE "videoCaption"."language" ' +
235 ' IN (' + createSafeIn(model, languages) + ') AND ' + 235 ' IN (' + createSafeIn(sequelize, languages) + ') AND ' +
236 ' "videoCaption"."videoId" = "video"."id"' + 236 ' "videoCaption"."videoId" = "video"."id"' +
237 ')' 237 ')'
238 ) 238 )
@@ -345,8 +345,8 @@ function buildListQuery (model: typeof Model, options: BuildVideosQueryOptions)
345 } 345 }
346 346
347 if (options.search) { 347 if (options.search) {
348 const escapedSearch = model.sequelize.escape(options.search) 348 const escapedSearch = sequelize.escape(options.search)
349 const escapedLikeSearch = model.sequelize.escape('%' + options.search + '%') 349 const escapedLikeSearch = sequelize.escape('%' + options.search + '%')
350 350
351 cte.push( 351 cte.push(
352 '"trigramSearch" AS (' + 352 '"trigramSearch" AS (' +