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 +++++++++++++++++++ server/models/video/video-playlist.ts | 2 +- server/models/video/video.ts | 6 ++++-- 3 files changed, 24 insertions(+), 3 deletions(-) (limited to 'server/models/video') 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 diff --git a/server/models/video/video-playlist.ts b/server/models/video/video-playlist.ts index 245475f94..72ba474b4 100644 --- a/server/models/video/video-playlist.ts +++ b/server/models/video/video-playlist.ts @@ -20,7 +20,7 @@ import { import { setAsUpdated } from '@server/helpers/database-utils' import { buildUUID, uuidToShort } from '@server/helpers/uuid' import { MAccountId, MChannelId } from '@server/types/models' -import { AttributesOnly, buildPlaylistEmbedPath, buildPlaylistLink, buildPlaylistWatchPath } from '@shared/core-utils' +import { AttributesOnly, buildPlaylistEmbedPath, buildPlaylistWatchPath } from '@shared/core-utils' import { ActivityIconObject } from '../../../shared/models/activitypub/objects' import { PlaylistObject } from '../../../shared/models/activitypub/objects/playlist-object' import { VideoPlaylistPrivacy } from '../../../shared/models/videos/playlist/video-playlist-privacy.model' diff --git a/server/models/video/video.ts b/server/models/video/video.ts index 543e604bb..c006a91af 100644 --- a/server/models/video/video.ts +++ b/server/models/video/video.ts @@ -26,7 +26,7 @@ import { } from 'sequelize-typescript' import { setAsUpdated } from '@server/helpers/database-utils' import { buildNSFWFilter } from '@server/helpers/express-utils' -import { shortToUUID } from '@server/helpers/uuid' +import { uuidToShort } from '@server/helpers/uuid' import { getPrivaciesForFederation, isPrivacyForFederation, isStateForFederation } from '@server/helpers/video' import { LiveManager } from '@server/lib/live/live-manager' import { getHLSDirectory, getVideoFilePath } from '@server/lib/video-paths' @@ -1113,6 +1113,7 @@ export class VideoModel extends Model>> { static async searchAndPopulateAccountAndServer (options: { includeLocalVideos: boolean search?: string + host?: string start?: number count?: number sort?: string @@ -1151,6 +1152,7 @@ export class VideoModel extends Model>> { user: options.user, filter: options.filter, + host: options.host, start: options.start, count: options.count, @@ -1579,7 +1581,7 @@ export class VideoModel extends Model>> { } getWatchStaticPath () { - return buildVideoWatchPath({ shortUUID: shortToUUID(this.uuid) }) + return buildVideoWatchPath({ shortUUID: uuidToShort(this.uuid) }) } getEmbedStaticPath () { -- cgit v1.2.3