+ [ Op.in ]: options.ids // FIXME: sequelize ANY seems broken
+ }
+ },
+ include: [
+ {
+ model: VideoChannelModel.scope({ method: [ VideoChannelScopeNames.SUMMARY, true ] }),
+ required: true
+ },
+ {
+ attributes: [ 'type', 'filename' ],
+ model: ThumbnailModel,
+ required: false
+ }
+ ]
+ }
+
+ if (options.withFiles === true) {
+ query.include.push({
+ model: VideoFileModel.unscoped(),
+ required: true
+ })
+ }
+
+ if (options.videoPlaylistId) {
+ query.include.push({
+ model: VideoPlaylistElementModel.unscoped(),
+ required: true,
+ where: {
+ videoPlaylistId: options.videoPlaylistId
+ }
+ })
+ }
+
+ return query
+ },
+ [ ScopeNames.AVAILABLE_FOR_LIST_IDS ]: (options: AvailableForListIDsOptions) => {
+ const whereAnd = options.baseWhere ? options.baseWhere : []
+
+ const query: FindOptions = {
+ raw: true,
+ attributes: options.withoutId === true ? [] : [ 'id' ],
+ include: []
+ }
+
+ whereAnd.push({
+ id: {
+ [ Op.notIn ]: Sequelize.literal(
+ '(SELECT "videoBlacklist"."videoId" FROM "videoBlacklist")'
+ )
+ }
+ })
+
+ whereAnd.push({
+ channelId: {
+ [ Op.notIn ]: Sequelize.literal(
+ '(' +
+ 'SELECT id FROM "videoChannel" WHERE "accountId" IN (' +
+ buildBlockedAccountSQL(options.serverAccountId, options.user ? options.user.Account.id : undefined) +
+ ')' +
+ ')'
+ )
+ }
+ })
+
+ // Only list public/published videos
+ if (!options.filter || options.filter !== 'all-local') {
+ const privacyWhere = {
+ // Always list public videos
+ privacy: VideoPrivacy.PUBLIC,
+ // Always list published videos, or videos that are being transcoded but on which we don't want to wait for transcoding
+ [ Op.or ]: [
+ {
+ state: VideoState.PUBLISHED
+ },
+ {
+ [ Op.and ]: {
+ state: VideoState.TO_TRANSCODE,
+ waitTranscoding: false
+ }
+ }
+ ]
+ }
+
+ whereAnd.push(privacyWhere)
+ }
+
+ if (options.videoPlaylistId) {
+ query.include.push({
+ attributes: [],
+ model: VideoPlaylistElementModel.unscoped(),
+ required: true,
+ where: {
+ videoPlaylistId: options.videoPlaylistId
+ }
+ })
+
+ query.subQuery = false
+ }
+
+ if (options.filter || options.accountId || options.videoChannelId) {
+ const videoChannelInclude: IncludeOptions = {
+ attributes: [],
+ model: VideoChannelModel.unscoped(),
+ required: true
+ }
+
+ if (options.videoChannelId) {
+ videoChannelInclude.where = {
+ id: options.videoChannelId
+ }
+ }
+
+ if (options.filter || options.accountId) {
+ const accountInclude: IncludeOptions = {
+ attributes: [],
+ model: AccountModel.unscoped(),
+ required: true
+ }
+
+ if (options.filter) {
+ accountInclude.include = [
+ {
+ attributes: [],
+ model: ActorModel.unscoped(),
+ required: true,
+ where: VideoModel.buildActorWhereWithFilter(options.filter)
+ }
+ ]
+ }
+
+ if (options.accountId) {
+ accountInclude.where = { id: options.accountId }
+ }
+
+ videoChannelInclude.include = [ accountInclude ]
+ }
+
+ query.include.push(videoChannelInclude)
+ }
+
+ if (options.followerActorId) {
+ let localVideosReq = ''
+ if (options.includeLocalVideos === true) {
+ localVideosReq = ' UNION ALL ' +
+ 'SELECT "video"."id" AS "id" FROM "video" ' +
+ 'INNER JOIN "videoChannel" ON "videoChannel"."id" = "video"."channelId" ' +
+ 'INNER JOIN "account" ON "account"."id" = "videoChannel"."accountId" ' +
+ 'INNER JOIN "actor" ON "account"."actorId" = "actor"."id" ' +
+ 'WHERE "actor"."serverId" IS NULL'
+ }
+
+ // Force actorId to be a number to avoid SQL injections
+ const actorIdNumber = parseInt(options.followerActorId.toString(), 10)
+ whereAnd.push({
+ id: {
+ [ Op.in ]: Sequelize.literal(