From 29837f8885eb37fa300e4b80c90a6d03ab337084 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Tue, 27 Jul 2021 09:07:38 +0200 Subject: Add ability to search by host in server --- .../models/video/sql/videos-id-list-query-builder.ts | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'server/models/video/sql/videos-id-list-query-builder.ts') 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 054f71c8c..d4260c69c 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 @@ import { Sequelize } from 'sequelize' import validator from 'validator' import { exists } from '@server/helpers/custom-validators/misc' +import { WEBSERVER } from '@server/initializers/constants' import { buildDirectionAndField, createSafeIn } from '@server/models/utils' import { MUserAccountId, MUserId } from '@server/types/models' import { VideoFilter, VideoPrivacy, VideoState } from '@shared/models' @@ -25,6 +26,7 @@ export type BuildVideosListQueryOptions = { nsfw?: boolean filter?: VideoFilter + host?: string isLive?: boolean categoryOneOf?: number[] @@ -131,6 +133,10 @@ export class VideosIdListQueryBuilder extends AbstractVideosQueryBuilder { this.whereOnlyLocal() } + if (options.host) { + this.whereHost(options.host) + } + if (options.accountId) { this.whereAccountId(options.accountId) } @@ -291,6 +297,19 @@ export class VideosIdListQueryBuilder extends AbstractVideosQueryBuilder { this.and.push('"video"."remote" IS FALSE') } + private whereHost (host: string) { + // Local instance + if (host === WEBSERVER.HOST) { + this.and.push('"accountActor"."serverId" IS NULL') + return + } + + this.joins.push('INNER JOIN "server" ON "server"."id" = "accountActor"."serverId"') + + this.and.push('"server"."host" = :host') + this.replacements.host = host + } + private whereAccountId (accountId: number) { this.and.push('"account"."id" = :accountId') this.replacements.accountId = accountId -- cgit v1.2.3