From 2760b454a761f6af3138b2fb5f34340772ab0d1e Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Wed, 27 Oct 2021 14:37:04 +0200 Subject: Deprecate filter video query Introduce include and isLocal instead --- server/controllers/api/accounts.ts | 18 +++++++++++++----- server/controllers/api/overviews.ts | 8 +++++++- server/controllers/api/search/search-videos.ts | 12 +++++++++--- server/controllers/api/users/my-subscriptions.ts | 9 ++++++--- server/controllers/api/video-channel.ts | 17 +++++++++++++---- server/controllers/api/videos/index.ts | 10 ++++++++-- server/controllers/bots.ts | 10 ++++++++-- server/controllers/feeds.ts | 21 +++++++++++++++------ 8 files changed, 79 insertions(+), 26 deletions(-) (limited to 'server/controllers') diff --git a/server/controllers/api/accounts.ts b/server/controllers/api/accounts.ts index 8eb880d59..44edffe38 100644 --- a/server/controllers/api/accounts.ts +++ b/server/controllers/api/accounts.ts @@ -2,6 +2,7 @@ import express from 'express' import { pickCommonVideoQuery } from '@server/helpers/query' import { ActorFollowModel } from '@server/models/actor/actor-follow' import { getServerActor } from '@server/models/application/application' +import { guessAdditionalAttributesFromQuery } from '@server/models/video/formatter/video-format-utils' import { buildNSFWFilter, getCountVideos, isUserAbleToSearchRemoteURI } from '../../helpers/express-utils' import { getFormattedObjects } from '../../helpers/utils' import { JobQueue } from '../../lib/job-queue' @@ -169,17 +170,24 @@ async function listAccountPlaylists (req: express.Request, res: express.Response } async function listAccountVideos (req: express.Request, res: express.Response) { + const serverActor = await getServerActor() + const account = res.locals.account - const followerActorId = isUserAbleToSearchRemoteURI(res) ? null : undefined + + const displayOnlyForFollower = isUserAbleToSearchRemoteURI(res) + ? null + : { + actorId: serverActor.id, + orLocalVideos: true + } + const countVideos = getCountVideos(req) const query = pickCommonVideoQuery(req.query) const apiOptions = await Hooks.wrapObject({ ...query, - followerActorId, - search: req.query.search, - includeLocalVideos: true, + displayOnlyForFollower, nsfw: buildNSFWFilter(res, query.nsfw), withFiles: false, accountId: account.id, @@ -193,7 +201,7 @@ async function listAccountVideos (req: express.Request, res: express.Response) { 'filter:api.accounts.videos.list.result' ) - return res.json(getFormattedObjects(resultList.data, resultList.total)) + return res.json(getFormattedObjects(resultList.data, resultList.total, guessAdditionalAttributesFromQuery(query))) } async function listAccountRatings (req: express.Request, res: express.Response) { diff --git a/server/controllers/api/overviews.ts b/server/controllers/api/overviews.ts index 5b16232e2..68626a508 100644 --- a/server/controllers/api/overviews.ts +++ b/server/controllers/api/overviews.ts @@ -8,6 +8,7 @@ import { buildNSFWFilter } from '../../helpers/express-utils' import { MEMOIZE_TTL, OVERVIEWS } from '../../initializers/constants' import { asyncMiddleware, optionalAuthenticate, videosOverviewValidator } from '../../middlewares' import { TagModel } from '../../models/video/tag' +import { getServerActor } from '@server/models/application/application' const overviewsRouter = express.Router() @@ -109,11 +110,16 @@ async function getVideos ( res: express.Response, where: { videoChannelId?: number, tagsOneOf?: string[], categoryOneOf?: number[] } ) { + const serverActor = await getServerActor() + const query = await Hooks.wrapObject({ start: 0, count: 12, sort: '-createdAt', - includeLocalVideos: true, + displayOnlyForFollower: { + actorId: serverActor.id, + orLocalVideos: true + }, nsfw: buildNSFWFilter(res), user: res.locals.oauth ? res.locals.oauth.token.User : undefined, withFiles: false, diff --git a/server/controllers/api/search/search-videos.ts b/server/controllers/api/search/search-videos.ts index 90946cb74..6db70acdf 100644 --- a/server/controllers/api/search/search-videos.ts +++ b/server/controllers/api/search/search-videos.ts @@ -7,6 +7,8 @@ import { WEBSERVER } from '@server/initializers/constants' import { getOrCreateAPVideo } from '@server/lib/activitypub/videos' import { Hooks } from '@server/lib/plugins/hooks' import { buildMutedForSearchIndex, isSearchIndexSearch, isURISearch } from '@server/lib/search' +import { getServerActor } from '@server/models/application/application' +import { guessAdditionalAttributesFromQuery } from '@server/models/video/formatter/video-format-utils' import { HttpStatusCode, ResultList, Video } from '@shared/models' import { VideosSearchQueryAfterSanitize } from '../../../../shared/models/search' import { buildNSFWFilter, isUserAbleToSearchRemoteURI } from '../../../helpers/express-utils' @@ -100,11 +102,15 @@ async function searchVideosIndex (query: VideosSearchQueryAfterSanitize, res: ex } async function searchVideosDB (query: VideosSearchQueryAfterSanitize, res: express.Response) { + const serverActor = await getServerActor() + const apiOptions = await Hooks.wrapObject({ ...query, - includeLocalVideos: true, - filter: query.filter, + displayOnlyForFollower: { + actorId: serverActor.id, + orLocalVideos: true + }, nsfw: buildNSFWFilter(res, query.nsfw), user: res.locals.oauth @@ -118,7 +124,7 @@ async function searchVideosDB (query: VideosSearchQueryAfterSanitize, res: expre 'filter:api.search.videos.local.list.result' ) - return res.json(getFormattedObjects(resultList.data, resultList.total)) + return res.json(getFormattedObjects(resultList.data, resultList.total, guessAdditionalAttributesFromQuery(query))) } async function searchVideoURI (url: string, res: express.Response) { diff --git a/server/controllers/api/users/my-subscriptions.ts b/server/controllers/api/users/my-subscriptions.ts index b2b441673..d96378180 100644 --- a/server/controllers/api/users/my-subscriptions.ts +++ b/server/controllers/api/users/my-subscriptions.ts @@ -2,6 +2,7 @@ import 'multer' import express from 'express' import { pickCommonVideoQuery } from '@server/helpers/query' import { sendUndoFollow } from '@server/lib/activitypub/send' +import { guessAdditionalAttributesFromQuery } from '@server/models/video/formatter/video-format-utils' import { VideoChannelModel } from '@server/models/video/video-channel' import { HttpStatusCode } from '../../../../shared/models/http/http-error-codes' import { buildNSFWFilter, getCountVideos } from '../../../helpers/express-utils' @@ -175,13 +176,15 @@ async function getUserSubscriptionVideos (req: express.Request, res: express.Res const resultList = await VideoModel.listForApi({ ...query, - includeLocalVideos: false, + displayOnlyForFollower: { + actorId: user.Account.Actor.id, + orLocalVideos: false + }, nsfw: buildNSFWFilter(res, query.nsfw), withFiles: false, - followerActorId: user.Account.Actor.id, user, countVideos }) - return res.json(getFormattedObjects(resultList.data, resultList.total)) + return res.json(getFormattedObjects(resultList.data, resultList.total, guessAdditionalAttributesFromQuery(query))) } diff --git a/server/controllers/api/video-channel.ts b/server/controllers/api/video-channel.ts index 7bf7a68c9..f9c1a405d 100644 --- a/server/controllers/api/video-channel.ts +++ b/server/controllers/api/video-channel.ts @@ -3,6 +3,7 @@ import { pickCommonVideoQuery } from '@server/helpers/query' import { Hooks } from '@server/lib/plugins/hooks' import { ActorFollowModel } from '@server/models/actor/actor-follow' import { getServerActor } from '@server/models/application/application' +import { guessAdditionalAttributesFromQuery } from '@server/models/video/formatter/video-format-utils' import { MChannelBannerAccountDefault } from '@server/types/models' import { ActorImageType, VideoChannelCreate, VideoChannelUpdate } from '../../../shared' import { HttpStatusCode } from '../../../shared/models/http/http-error-codes' @@ -327,16 +328,24 @@ async function listVideoChannelPlaylists (req: express.Request, res: express.Res } async function listVideoChannelVideos (req: express.Request, res: express.Response) { + const serverActor = await getServerActor() + const videoChannelInstance = res.locals.videoChannel - const followerActorId = isUserAbleToSearchRemoteURI(res) ? null : undefined + + const displayOnlyForFollower = isUserAbleToSearchRemoteURI(res) + ? null + : { + actorId: serverActor.id, + orLocalVideos: true + } + const countVideos = getCountVideos(req) const query = pickCommonVideoQuery(req.query) const apiOptions = await Hooks.wrapObject({ ...query, - followerActorId, - includeLocalVideos: true, + displayOnlyForFollower, nsfw: buildNSFWFilter(res, query.nsfw), withFiles: false, videoChannelId: videoChannelInstance.id, @@ -350,7 +359,7 @@ async function listVideoChannelVideos (req: express.Request, res: express.Respon 'filter:api.video-channels.videos.list.result' ) - return res.json(getFormattedObjects(resultList.data, resultList.total)) + return res.json(getFormattedObjects(resultList.data, resultList.total, guessAdditionalAttributesFromQuery(query))) } async function listVideoChannelFollowers (req: express.Request, res: express.Response) { diff --git a/server/controllers/api/videos/index.ts b/server/controllers/api/videos/index.ts index c0c77f3f7..821ed7ff3 100644 --- a/server/controllers/api/videos/index.ts +++ b/server/controllers/api/videos/index.ts @@ -5,6 +5,7 @@ import { doJSONRequest } from '@server/helpers/requests' import { LiveManager } from '@server/lib/live' import { openapiOperationDoc } from '@server/middlewares/doc' import { getServerActor } from '@server/models/application/application' +import { guessAdditionalAttributesFromQuery } from '@server/models/video/formatter/video-format-utils' import { MVideoAccountLight } from '@server/types/models' import { HttpStatusCode } from '../../../../shared/models' import { auditLoggerFactory, getAuditIdFromRes, VideoAuditView } from '../../../helpers/audit-logger' @@ -211,13 +212,18 @@ async function getVideoFileMetadata (req: express.Request, res: express.Response } async function listVideos (req: express.Request, res: express.Response) { + const serverActor = await getServerActor() + const query = pickCommonVideoQuery(req.query) const countVideos = getCountVideos(req) const apiOptions = await Hooks.wrapObject({ ...query, - includeLocalVideos: true, + displayOnlyForFollower: { + actorId: serverActor.id, + orLocalVideos: true + }, nsfw: buildNSFWFilter(res, query.nsfw), withFiles: false, user: res.locals.oauth ? res.locals.oauth.token.User : undefined, @@ -230,7 +236,7 @@ async function listVideos (req: express.Request, res: express.Response) { 'filter:api.videos.list.result' ) - return res.json(getFormattedObjects(resultList.data, resultList.total)) + return res.json(getFormattedObjects(resultList.data, resultList.total, guessAdditionalAttributesFromQuery(query))) } async function removeVideo (_req: express.Request, res: express.Response) { diff --git a/server/controllers/bots.ts b/server/controllers/bots.ts index 63db345bf..9f03de7e8 100644 --- a/server/controllers/bots.ts +++ b/server/controllers/bots.ts @@ -1,3 +1,4 @@ +import { getServerActor } from '@server/models/application/application' import express from 'express' import { truncate } from 'lodash' import { SitemapStream, streamToPromise } from 'sitemap' @@ -63,13 +64,18 @@ async function getSitemapAccountUrls () { } async function getSitemapLocalVideoUrls () { + const serverActor = await getServerActor() + const { data } = await VideoModel.listForApi({ start: 0, count: undefined, sort: 'createdAt', - includeLocalVideos: true, + displayOnlyForFollower: { + actorId: serverActor.id, + orLocalVideos: true + }, + isLocal: true, nsfw: buildNSFWFilter(), - filter: 'local', withFiles: false, countVideos: false }) diff --git a/server/controllers/feeds.ts b/server/controllers/feeds.ts index 5ac2e43a1..1f6aebac3 100644 --- a/server/controllers/feeds.ts +++ b/server/controllers/feeds.ts @@ -1,7 +1,7 @@ import express from 'express' import Feed from 'pfeed' +import { getServerActor } from '@server/models/application/application' import { getCategoryLabel } from '@server/models/video/formatter/video-format-utils' -import { VideoFilter } from '../../shared/models/videos/video-query.type' import { buildNSFWFilter } from '../helpers/express-utils' import { CONFIG } from '../initializers/config' import { FEEDS, PREVIEWS_SIZE, ROUTE_CACHE_LIFETIME, WEBSERVER } from '../initializers/constants' @@ -160,13 +160,18 @@ async function generateVideoFeed (req: express.Request, res: express.Response) { videoChannelId: videoChannel ? videoChannel.id : null } + const server = await getServerActor() const { data } = await VideoModel.listForApi({ start, count: FEEDS.COUNT, sort: req.query.sort, - includeLocalVideos: true, + displayOnlyForFollower: { + actorId: server.id, + orLocalVideos: true + }, nsfw, - filter: req.query.filter as VideoFilter, + isLocal: req.query.isLocal, + include: req.query.include, withFiles: true, countVideos: false, ...options @@ -196,14 +201,18 @@ async function generateVideoFeedForSubscriptions (req: express.Request, res: exp start, count: FEEDS.COUNT, sort: req.query.sort, - includeLocalVideos: false, nsfw, - filter: req.query.filter as VideoFilter, + + isLocal: req.query.isLocal, + include: req.query.include, withFiles: true, countVideos: false, - followerActorId: res.locals.user.Account.Actor.id, + displayOnlyForFollower: { + actorId: res.locals.user.Account.Actor.id, + orLocalVideos: false + }, user: res.locals.user }) -- cgit v1.2.3