X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Fmodels%2Fvideo%2Fvideo-query-builder.ts;h=2aa5e65c877e0d58cd0f86928dbf62924f1eea03;hb=ff0ea0cd8e3b0ecad445672deb75b193babeddc2;hp=4d95ddee29a8b1fcaf5f7a561baae499c73e8a5c;hpb=f479685678406a5df864d89615b33d29085ebfc6;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/models/video/video-query-builder.ts b/server/models/video/video-query-builder.ts index 4d95ddee2..2aa5e65c8 100644 --- a/server/models/video/video-query-builder.ts +++ b/server/models/video/video-query-builder.ts @@ -1,9 +1,9 @@ -import { VideoFilter, VideoPrivacy, VideoState } from '@shared/models' -import { buildDirectionAndField, createSafeIn } from '@server/models/utils' -import { Model } from 'sequelize-typescript' -import { MUserAccountId, MUserId } from '@server/types/models' +import { Sequelize } from 'sequelize/types' import validator from 'validator' import { exists } from '@server/helpers/custom-validators/misc' +import { buildDirectionAndField, createSafeIn } from '@server/models/utils' +import { MUserAccountId, MUserId } from '@server/types/models' +import { VideoFilter, VideoPrivacy, VideoState } from '@shared/models' export type BuildVideosQueryOptions = { attributes?: string[] @@ -16,9 +16,11 @@ export type BuildVideosQueryOptions = { start: number sort: string + nsfw?: boolean filter?: VideoFilter + isLive?: boolean + categoryOneOf?: number[] - nsfw?: boolean licenceOneOf?: number[] languageOneOf?: string[] tagsOneOf?: string[] @@ -53,7 +55,7 @@ export type BuildVideosQueryOptions = { having?: string } -function buildListQuery (model: typeof Model, options: BuildVideosQueryOptions) { +function buildListQuery (sequelize: Sequelize, options: BuildVideosQueryOptions) { const and: string[] = [] const joins: string[] = [] const replacements: any = {} @@ -75,7 +77,7 @@ function buildListQuery (model: typeof Model, options: BuildVideosQueryOptions) const blockerIds = [ options.serverAccountId ] if (options.user) blockerIds.push(options.user.Account.id) - const inClause = createSafeIn(model, blockerIds) + const inClause = createSafeIn(sequelize, blockerIds) and.push( 'NOT EXISTS (' + @@ -177,7 +179,7 @@ function buildListQuery (model: typeof Model, options: BuildVideosQueryOptions) 'EXISTS (' + ' SELECT 1 FROM "videoTag" ' + ' INNER JOIN "tag" ON "tag"."id" = "videoTag"."tagId" ' + - ' WHERE lower("tag"."name") IN (' + createSafeIn(model, tagsOneOfLower) + ') ' + + ' WHERE lower("tag"."name") IN (' + createSafeIn(sequelize, tagsOneOfLower) + ') ' + ' AND "video"."id" = "videoTag"."videoId"' + ')' ) @@ -190,7 +192,7 @@ function buildListQuery (model: typeof Model, options: BuildVideosQueryOptions) 'EXISTS (' + ' SELECT 1 FROM "videoTag" ' + ' INNER JOIN "tag" ON "tag"."id" = "videoTag"."tagId" ' + - ' WHERE lower("tag"."name") IN (' + createSafeIn(model, tagsAllOfLower) + ') ' + + ' WHERE lower("tag"."name") IN (' + createSafeIn(sequelize, tagsAllOfLower) + ') ' + ' AND "video"."id" = "videoTag"."videoId" ' + ' GROUP BY "videoTag"."videoId" HAVING COUNT(*) = ' + tagsAllOfLower.length + ')' @@ -199,10 +201,14 @@ function buildListQuery (model: typeof Model, options: BuildVideosQueryOptions) if (options.nsfw === true) { and.push('"video"."nsfw" IS TRUE') + } else if (options.nsfw === false) { + and.push('"video"."nsfw" IS FALSE') } - if (options.nsfw === false) { - and.push('"video"."nsfw" IS FALSE') + if (options.isLive === true) { + and.push('"video"."isLive" IS TRUE') + } else if (options.isLive === false) { + and.push('"video"."isLive" IS FALSE') } if (options.categoryOneOf) { @@ -226,7 +232,7 @@ function buildListQuery (model: typeof Model, options: BuildVideosQueryOptions) languagesQueryParts.push( 'EXISTS (' + ' SELECT 1 FROM "videoCaption" WHERE "videoCaption"."language" ' + - ' IN (' + createSafeIn(model, languages) + ') AND ' + + ' IN (' + createSafeIn(sequelize, languages) + ') AND ' + ' "videoCaption"."videoId" = "video"."id"' + ')' ) @@ -339,8 +345,8 @@ function buildListQuery (model: typeof Model, options: BuildVideosQueryOptions) } if (options.search) { - const escapedSearch = model.sequelize.escape(options.search) - const escapedLikeSearch = model.sequelize.escape('%' + options.search + '%') + const escapedSearch = sequelize.escape(options.search) + const escapedLikeSearch = sequelize.escape('%' + options.search + '%') cte.push( '"trigramSearch" AS (' +