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'
nsfw?: boolean
filter?: VideoFilter
+ host?: string
isLive?: boolean
categoryOneOf?: number[]
tagsOneOf?: string[]
tagsAllOf?: string[]
+ uuids?: string[]
+
withFiles?: boolean
accountId?: number
this.whereOnlyLocal()
}
+ if (options.host) {
+ this.whereHost(options.host)
+ }
+
if (options.accountId) {
this.whereAccountId(options.accountId)
}
this.whereTagsAllOf(options.tagsAllOf)
}
+ if (options.uuids) {
+ this.whereUUIDs(options.uuids)
+ }
+
if (options.nsfw === true) {
this.whereNSFW()
} else if (options.nsfw === false) {
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
)
}
+ private whereUUIDs (uuids: string[]) {
+ this.and.push('"video"."uuid" IN (' + createSafeIn(this.sequelize, uuids) + ')')
+ }
+
private whereCategoryOneOf (categoryOneOf: number[]) {
this.and.push('"video"."category" IN (:categoryOneOf)')
this.replacements.categoryOneOf = categoryOneOf