aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/models/video/sql/videos-id-list-query-builder.ts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2021-07-27 09:07:38 +0200
committerChocobozzz <me@florianbigard.com>2021-07-27 17:10:52 +0200
commit29837f8885eb37fa300e4b80c90a6d03ab337084 (patch)
treea7a066c6604c9adec4cb21c1bd1965c5bf253b03 /server/models/video/sql/videos-id-list-query-builder.ts
parent5d0095fde19d803bead7cbad0452bd09f3351adc (diff)
downloadPeerTube-29837f8885eb37fa300e4b80c90a6d03ab337084.tar.gz
PeerTube-29837f8885eb37fa300e4b80c90a6d03ab337084.tar.zst
PeerTube-29837f8885eb37fa300e4b80c90a6d03ab337084.zip
Add ability to search by host in server
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.ts19
1 files changed, 19 insertions, 0 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 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 @@
1import { Sequelize } from 'sequelize' 1import { Sequelize } from 'sequelize'
2import validator from 'validator' 2import validator from 'validator'
3import { exists } from '@server/helpers/custom-validators/misc' 3import { exists } from '@server/helpers/custom-validators/misc'
4import { WEBSERVER } from '@server/initializers/constants'
4import { buildDirectionAndField, createSafeIn } from '@server/models/utils' 5import { buildDirectionAndField, createSafeIn } from '@server/models/utils'
5import { MUserAccountId, MUserId } from '@server/types/models' 6import { MUserAccountId, MUserId } from '@server/types/models'
6import { VideoFilter, VideoPrivacy, VideoState } from '@shared/models' 7import { 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[]
@@ -131,6 +133,10 @@ export class VideosIdListQueryBuilder extends AbstractVideosQueryBuilder {
131 this.whereOnlyLocal() 133 this.whereOnlyLocal()
132 } 134 }
133 135
136 if (options.host) {
137 this.whereHost(options.host)
138 }
139
134 if (options.accountId) { 140 if (options.accountId) {
135 this.whereAccountId(options.accountId) 141 this.whereAccountId(options.accountId)
136 } 142 }
@@ -291,6 +297,19 @@ export class VideosIdListQueryBuilder extends AbstractVideosQueryBuilder {
291 this.and.push('"video"."remote" IS FALSE') 297 this.and.push('"video"."remote" IS FALSE')
292 } 298 }
293 299
300 private whereHost (host: string) {
301 // Local instance
302 if (host === WEBSERVER.HOST) {
303 this.and.push('"accountActor"."serverId" IS NULL')
304 return
305 }
306
307 this.joins.push('INNER JOIN "server" ON "server"."id" = "accountActor"."serverId"')
308
309 this.and.push('"server"."host" = :host')
310 this.replacements.host = host
311 }
312
294 private whereAccountId (accountId: number) { 313 private whereAccountId (accountId: number) {
295 this.and.push('"account"."id" = :accountId') 314 this.and.push('"account"."id" = :accountId')
296 this.replacements.accountId = accountId 315 this.replacements.accountId = accountId