diff options
Diffstat (limited to 'server/models/video/sql/videos-id-list-query-builder.ts')
-rw-r--r-- | server/models/video/sql/videos-id-list-query-builder.ts | 35 |
1 files changed, 32 insertions, 3 deletions
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 30b251f0f..7625c003d 100644 --- a/server/models/video/sql/videos-id-list-query-builder.ts +++ b/server/models/video/sql/videos-id-list-query-builder.ts | |||
@@ -1,6 +1,7 @@ | |||
1 | import { Sequelize } from 'sequelize' | 1 | import { Sequelize } from 'sequelize' |
2 | import validator from 'validator' | 2 | import validator from 'validator' |
3 | import { exists } from '@server/helpers/custom-validators/misc' | 3 | import { exists } from '@server/helpers/custom-validators/misc' |
4 | import { WEBSERVER } from '@server/initializers/constants' | ||
4 | import { buildDirectionAndField, createSafeIn } from '@server/models/utils' | 5 | import { buildDirectionAndField, createSafeIn } from '@server/models/utils' |
5 | import { MUserAccountId, MUserId } from '@server/types/models' | 6 | import { MUserAccountId, MUserId } from '@server/types/models' |
6 | import { VideoFilter, VideoPrivacy, VideoState } from '@shared/models' | 7 | import { VideoFilter, VideoPrivacy, VideoState } from '@shared/models' |
@@ -25,6 +26,7 @@ export type BuildVideosListQueryOptions = { | |||
25 | 26 | ||
26 | nsfw?: boolean | 27 | nsfw?: boolean |
27 | filter?: VideoFilter | 28 | filter?: VideoFilter |
29 | host?: string | ||
28 | isLive?: boolean | 30 | isLive?: boolean |
29 | 31 | ||
30 | categoryOneOf?: number[] | 32 | categoryOneOf?: number[] |
@@ -33,6 +35,8 @@ export type BuildVideosListQueryOptions = { | |||
33 | tagsOneOf?: string[] | 35 | tagsOneOf?: string[] |
34 | tagsAllOf?: string[] | 36 | tagsAllOf?: string[] |
35 | 37 | ||
38 | uuids?: string[] | ||
39 | |||
36 | withFiles?: boolean | 40 | withFiles?: boolean |
37 | 41 | ||
38 | accountId?: number | 42 | accountId?: number |
@@ -131,6 +135,10 @@ export class VideosIdListQueryBuilder extends AbstractVideosQueryBuilder { | |||
131 | this.whereOnlyLocal() | 135 | this.whereOnlyLocal() |
132 | } | 136 | } |
133 | 137 | ||
138 | if (options.host) { | ||
139 | this.whereHost(options.host) | ||
140 | } | ||
141 | |||
134 | if (options.accountId) { | 142 | if (options.accountId) { |
135 | this.whereAccountId(options.accountId) | 143 | this.whereAccountId(options.accountId) |
136 | } | 144 | } |
@@ -155,6 +163,10 @@ export class VideosIdListQueryBuilder extends AbstractVideosQueryBuilder { | |||
155 | this.whereTagsAllOf(options.tagsAllOf) | 163 | this.whereTagsAllOf(options.tagsAllOf) |
156 | } | 164 | } |
157 | 165 | ||
166 | if (options.uuids) { | ||
167 | this.whereUUIDs(options.uuids) | ||
168 | } | ||
169 | |||
158 | if (options.nsfw === true) { | 170 | if (options.nsfw === true) { |
159 | this.whereNSFW() | 171 | this.whereNSFW() |
160 | } else if (options.nsfw === false) { | 172 | } else if (options.nsfw === false) { |
@@ -291,6 +303,19 @@ export class VideosIdListQueryBuilder extends AbstractVideosQueryBuilder { | |||
291 | this.and.push('"video"."remote" IS FALSE') | 303 | this.and.push('"video"."remote" IS FALSE') |
292 | } | 304 | } |
293 | 305 | ||
306 | private whereHost (host: string) { | ||
307 | // Local instance | ||
308 | if (host === WEBSERVER.HOST) { | ||
309 | this.and.push('"accountActor"."serverId" IS NULL') | ||
310 | return | ||
311 | } | ||
312 | |||
313 | this.joins.push('INNER JOIN "server" ON "server"."id" = "accountActor"."serverId"') | ||
314 | |||
315 | this.and.push('"server"."host" = :host') | ||
316 | this.replacements.host = host | ||
317 | } | ||
318 | |||
294 | private whereAccountId (accountId: number) { | 319 | private whereAccountId (accountId: number) { |
295 | this.and.push('"account"."id" = :accountId') | 320 | this.and.push('"account"."id" = :accountId') |
296 | this.replacements.accountId = accountId | 321 | this.replacements.accountId = accountId |
@@ -304,16 +329,16 @@ export class VideosIdListQueryBuilder extends AbstractVideosQueryBuilder { | |||
304 | private whereFollowerActorId (followerActorId: number, includeLocalVideos: boolean) { | 329 | private whereFollowerActorId (followerActorId: number, includeLocalVideos: boolean) { |
305 | let query = | 330 | let query = |
306 | '(' + | 331 | '(' + |
307 | ' EXISTS (' + | 332 | ' EXISTS (' + // Videos shared by actors we follow |
308 | ' SELECT 1 FROM "videoShare" ' + | 333 | ' SELECT 1 FROM "videoShare" ' + |
309 | ' INNER JOIN "actorFollow" "actorFollowShare" ON "actorFollowShare"."targetActorId" = "videoShare"."actorId" ' + | 334 | ' INNER JOIN "actorFollow" "actorFollowShare" ON "actorFollowShare"."targetActorId" = "videoShare"."actorId" ' + |
310 | ' AND "actorFollowShare"."actorId" = :followerActorId AND "actorFollowShare"."state" = \'accepted\' ' + | 335 | ' AND "actorFollowShare"."actorId" = :followerActorId AND "actorFollowShare"."state" = \'accepted\' ' + |
311 | ' WHERE "videoShare"."videoId" = "video"."id"' + | 336 | ' WHERE "videoShare"."videoId" = "video"."id"' + |
312 | ' )' + | 337 | ' )' + |
313 | ' OR' + | 338 | ' OR' + |
314 | ' EXISTS (' + | 339 | ' EXISTS (' + // Videos published by accounts we follow |
315 | ' SELECT 1 from "actorFollow" ' + | 340 | ' SELECT 1 from "actorFollow" ' + |
316 | ' WHERE "actorFollow"."targetActorId" = "videoChannel"."actorId" AND "actorFollow"."actorId" = :followerActorId ' + | 341 | ' WHERE "actorFollow"."targetActorId" = "account"."actorId" AND "actorFollow"."actorId" = :followerActorId ' + |
317 | ' AND "actorFollow"."state" = \'accepted\'' + | 342 | ' AND "actorFollow"."state" = \'accepted\'' + |
318 | ' )' | 343 | ' )' |
319 | 344 | ||
@@ -367,6 +392,10 @@ export class VideosIdListQueryBuilder extends AbstractVideosQueryBuilder { | |||
367 | ) | 392 | ) |
368 | } | 393 | } |
369 | 394 | ||
395 | private whereUUIDs (uuids: string[]) { | ||
396 | this.and.push('"video"."uuid" IN (' + createSafeIn(this.sequelize, uuids) + ')') | ||
397 | } | ||
398 | |||
370 | private whereCategoryOneOf (categoryOneOf: number[]) { | 399 | private whereCategoryOneOf (categoryOneOf: number[]) { |
371 | this.and.push('"video"."category" IN (:categoryOneOf)') | 400 | this.and.push('"video"."category" IN (:categoryOneOf)') |
372 | this.replacements.categoryOneOf = categoryOneOf | 401 | this.replacements.categoryOneOf = categoryOneOf |