aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/controllers/api
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2021-10-27 14:37:04 +0200
committerChocobozzz <chocobozzz@cpy.re>2021-10-29 11:48:21 +0200
commit2760b454a761f6af3138b2fb5f34340772ab0d1e (patch)
tree2b3a2d81478f8b432eb54cce4caa5a760c494627 /server/controllers/api
parente4611b54910d8e7f2b4f8a97ee2d9cc8e1054127 (diff)
downloadPeerTube-2760b454a761f6af3138b2fb5f34340772ab0d1e.tar.gz
PeerTube-2760b454a761f6af3138b2fb5f34340772ab0d1e.tar.zst
PeerTube-2760b454a761f6af3138b2fb5f34340772ab0d1e.zip
Deprecate filter video query
Introduce include and isLocal instead
Diffstat (limited to 'server/controllers/api')
-rw-r--r--server/controllers/api/accounts.ts18
-rw-r--r--server/controllers/api/overviews.ts8
-rw-r--r--server/controllers/api/search/search-videos.ts12
-rw-r--r--server/controllers/api/users/my-subscriptions.ts9
-rw-r--r--server/controllers/api/video-channel.ts17
-rw-r--r--server/controllers/api/videos/index.ts10
6 files changed, 56 insertions, 18 deletions
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'
2import { pickCommonVideoQuery } from '@server/helpers/query' 2import { pickCommonVideoQuery } from '@server/helpers/query'
3import { ActorFollowModel } from '@server/models/actor/actor-follow' 3import { ActorFollowModel } from '@server/models/actor/actor-follow'
4import { getServerActor } from '@server/models/application/application' 4import { getServerActor } from '@server/models/application/application'
5import { guessAdditionalAttributesFromQuery } from '@server/models/video/formatter/video-format-utils'
5import { buildNSFWFilter, getCountVideos, isUserAbleToSearchRemoteURI } from '../../helpers/express-utils' 6import { buildNSFWFilter, getCountVideos, isUserAbleToSearchRemoteURI } from '../../helpers/express-utils'
6import { getFormattedObjects } from '../../helpers/utils' 7import { getFormattedObjects } from '../../helpers/utils'
7import { JobQueue } from '../../lib/job-queue' 8import { JobQueue } from '../../lib/job-queue'
@@ -169,17 +170,24 @@ async function listAccountPlaylists (req: express.Request, res: express.Response
169} 170}
170 171
171async function listAccountVideos (req: express.Request, res: express.Response) { 172async function listAccountVideos (req: express.Request, res: express.Response) {
173 const serverActor = await getServerActor()
174
172 const account = res.locals.account 175 const account = res.locals.account
173 const followerActorId = isUserAbleToSearchRemoteURI(res) ? null : undefined 176
177 const displayOnlyForFollower = isUserAbleToSearchRemoteURI(res)
178 ? null
179 : {
180 actorId: serverActor.id,
181 orLocalVideos: true
182 }
183
174 const countVideos = getCountVideos(req) 184 const countVideos = getCountVideos(req)
175 const query = pickCommonVideoQuery(req.query) 185 const query = pickCommonVideoQuery(req.query)
176 186
177 const apiOptions = await Hooks.wrapObject({ 187 const apiOptions = await Hooks.wrapObject({
178 ...query, 188 ...query,
179 189
180 followerActorId, 190 displayOnlyForFollower,
181 search: req.query.search,
182 includeLocalVideos: true,
183 nsfw: buildNSFWFilter(res, query.nsfw), 191 nsfw: buildNSFWFilter(res, query.nsfw),
184 withFiles: false, 192 withFiles: false,
185 accountId: account.id, 193 accountId: account.id,
@@ -193,7 +201,7 @@ async function listAccountVideos (req: express.Request, res: express.Response) {
193 'filter:api.accounts.videos.list.result' 201 'filter:api.accounts.videos.list.result'
194 ) 202 )
195 203
196 return res.json(getFormattedObjects(resultList.data, resultList.total)) 204 return res.json(getFormattedObjects(resultList.data, resultList.total, guessAdditionalAttributesFromQuery(query)))
197} 205}
198 206
199async function listAccountRatings (req: express.Request, res: express.Response) { 207async 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'
8import { MEMOIZE_TTL, OVERVIEWS } from '../../initializers/constants' 8import { MEMOIZE_TTL, OVERVIEWS } from '../../initializers/constants'
9import { asyncMiddleware, optionalAuthenticate, videosOverviewValidator } from '../../middlewares' 9import { asyncMiddleware, optionalAuthenticate, videosOverviewValidator } from '../../middlewares'
10import { TagModel } from '../../models/video/tag' 10import { TagModel } from '../../models/video/tag'
11import { getServerActor } from '@server/models/application/application'
11 12
12const overviewsRouter = express.Router() 13const overviewsRouter = express.Router()
13 14
@@ -109,11 +110,16 @@ async function getVideos (
109 res: express.Response, 110 res: express.Response,
110 where: { videoChannelId?: number, tagsOneOf?: string[], categoryOneOf?: number[] } 111 where: { videoChannelId?: number, tagsOneOf?: string[], categoryOneOf?: number[] }
111) { 112) {
113 const serverActor = await getServerActor()
114
112 const query = await Hooks.wrapObject({ 115 const query = await Hooks.wrapObject({
113 start: 0, 116 start: 0,
114 count: 12, 117 count: 12,
115 sort: '-createdAt', 118 sort: '-createdAt',
116 includeLocalVideos: true, 119 displayOnlyForFollower: {
120 actorId: serverActor.id,
121 orLocalVideos: true
122 },
117 nsfw: buildNSFWFilter(res), 123 nsfw: buildNSFWFilter(res),
118 user: res.locals.oauth ? res.locals.oauth.token.User : undefined, 124 user: res.locals.oauth ? res.locals.oauth.token.User : undefined,
119 withFiles: false, 125 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'
7import { getOrCreateAPVideo } from '@server/lib/activitypub/videos' 7import { getOrCreateAPVideo } from '@server/lib/activitypub/videos'
8import { Hooks } from '@server/lib/plugins/hooks' 8import { Hooks } from '@server/lib/plugins/hooks'
9import { buildMutedForSearchIndex, isSearchIndexSearch, isURISearch } from '@server/lib/search' 9import { buildMutedForSearchIndex, isSearchIndexSearch, isURISearch } from '@server/lib/search'
10import { getServerActor } from '@server/models/application/application'
11import { guessAdditionalAttributesFromQuery } from '@server/models/video/formatter/video-format-utils'
10import { HttpStatusCode, ResultList, Video } from '@shared/models' 12import { HttpStatusCode, ResultList, Video } from '@shared/models'
11import { VideosSearchQueryAfterSanitize } from '../../../../shared/models/search' 13import { VideosSearchQueryAfterSanitize } from '../../../../shared/models/search'
12import { buildNSFWFilter, isUserAbleToSearchRemoteURI } from '../../../helpers/express-utils' 14import { buildNSFWFilter, isUserAbleToSearchRemoteURI } from '../../../helpers/express-utils'
@@ -100,11 +102,15 @@ async function searchVideosIndex (query: VideosSearchQueryAfterSanitize, res: ex
100} 102}
101 103
102async function searchVideosDB (query: VideosSearchQueryAfterSanitize, res: express.Response) { 104async function searchVideosDB (query: VideosSearchQueryAfterSanitize, res: express.Response) {
105 const serverActor = await getServerActor()
106
103 const apiOptions = await Hooks.wrapObject({ 107 const apiOptions = await Hooks.wrapObject({
104 ...query, 108 ...query,
105 109
106 includeLocalVideos: true, 110 displayOnlyForFollower: {
107 filter: query.filter, 111 actorId: serverActor.id,
112 orLocalVideos: true
113 },
108 114
109 nsfw: buildNSFWFilter(res, query.nsfw), 115 nsfw: buildNSFWFilter(res, query.nsfw),
110 user: res.locals.oauth 116 user: res.locals.oauth
@@ -118,7 +124,7 @@ async function searchVideosDB (query: VideosSearchQueryAfterSanitize, res: expre
118 'filter:api.search.videos.local.list.result' 124 'filter:api.search.videos.local.list.result'
119 ) 125 )
120 126
121 return res.json(getFormattedObjects(resultList.data, resultList.total)) 127 return res.json(getFormattedObjects(resultList.data, resultList.total, guessAdditionalAttributesFromQuery(query)))
122} 128}
123 129
124async function searchVideoURI (url: string, res: express.Response) { 130async 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'
2import express from 'express' 2import express from 'express'
3import { pickCommonVideoQuery } from '@server/helpers/query' 3import { pickCommonVideoQuery } from '@server/helpers/query'
4import { sendUndoFollow } from '@server/lib/activitypub/send' 4import { sendUndoFollow } from '@server/lib/activitypub/send'
5import { guessAdditionalAttributesFromQuery } from '@server/models/video/formatter/video-format-utils'
5import { VideoChannelModel } from '@server/models/video/video-channel' 6import { VideoChannelModel } from '@server/models/video/video-channel'
6import { HttpStatusCode } from '../../../../shared/models/http/http-error-codes' 7import { HttpStatusCode } from '../../../../shared/models/http/http-error-codes'
7import { buildNSFWFilter, getCountVideos } from '../../../helpers/express-utils' 8import { buildNSFWFilter, getCountVideos } from '../../../helpers/express-utils'
@@ -175,13 +176,15 @@ async function getUserSubscriptionVideos (req: express.Request, res: express.Res
175 const resultList = await VideoModel.listForApi({ 176 const resultList = await VideoModel.listForApi({
176 ...query, 177 ...query,
177 178
178 includeLocalVideos: false, 179 displayOnlyForFollower: {
180 actorId: user.Account.Actor.id,
181 orLocalVideos: false
182 },
179 nsfw: buildNSFWFilter(res, query.nsfw), 183 nsfw: buildNSFWFilter(res, query.nsfw),
180 withFiles: false, 184 withFiles: false,
181 followerActorId: user.Account.Actor.id,
182 user, 185 user,
183 countVideos 186 countVideos
184 }) 187 })
185 188
186 return res.json(getFormattedObjects(resultList.data, resultList.total)) 189 return res.json(getFormattedObjects(resultList.data, resultList.total, guessAdditionalAttributesFromQuery(query)))
187} 190}
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'
3import { Hooks } from '@server/lib/plugins/hooks' 3import { Hooks } from '@server/lib/plugins/hooks'
4import { ActorFollowModel } from '@server/models/actor/actor-follow' 4import { ActorFollowModel } from '@server/models/actor/actor-follow'
5import { getServerActor } from '@server/models/application/application' 5import { getServerActor } from '@server/models/application/application'
6import { guessAdditionalAttributesFromQuery } from '@server/models/video/formatter/video-format-utils'
6import { MChannelBannerAccountDefault } from '@server/types/models' 7import { MChannelBannerAccountDefault } from '@server/types/models'
7import { ActorImageType, VideoChannelCreate, VideoChannelUpdate } from '../../../shared' 8import { ActorImageType, VideoChannelCreate, VideoChannelUpdate } from '../../../shared'
8import { HttpStatusCode } from '../../../shared/models/http/http-error-codes' 9import { HttpStatusCode } from '../../../shared/models/http/http-error-codes'
@@ -327,16 +328,24 @@ async function listVideoChannelPlaylists (req: express.Request, res: express.Res
327} 328}
328 329
329async function listVideoChannelVideos (req: express.Request, res: express.Response) { 330async function listVideoChannelVideos (req: express.Request, res: express.Response) {
331 const serverActor = await getServerActor()
332
330 const videoChannelInstance = res.locals.videoChannel 333 const videoChannelInstance = res.locals.videoChannel
331 const followerActorId = isUserAbleToSearchRemoteURI(res) ? null : undefined 334
335 const displayOnlyForFollower = isUserAbleToSearchRemoteURI(res)
336 ? null
337 : {
338 actorId: serverActor.id,
339 orLocalVideos: true
340 }
341
332 const countVideos = getCountVideos(req) 342 const countVideos = getCountVideos(req)
333 const query = pickCommonVideoQuery(req.query) 343 const query = pickCommonVideoQuery(req.query)
334 344
335 const apiOptions = await Hooks.wrapObject({ 345 const apiOptions = await Hooks.wrapObject({
336 ...query, 346 ...query,
337 347
338 followerActorId, 348 displayOnlyForFollower,
339 includeLocalVideos: true,
340 nsfw: buildNSFWFilter(res, query.nsfw), 349 nsfw: buildNSFWFilter(res, query.nsfw),
341 withFiles: false, 350 withFiles: false,
342 videoChannelId: videoChannelInstance.id, 351 videoChannelId: videoChannelInstance.id,
@@ -350,7 +359,7 @@ async function listVideoChannelVideos (req: express.Request, res: express.Respon
350 'filter:api.video-channels.videos.list.result' 359 'filter:api.video-channels.videos.list.result'
351 ) 360 )
352 361
353 return res.json(getFormattedObjects(resultList.data, resultList.total)) 362 return res.json(getFormattedObjects(resultList.data, resultList.total, guessAdditionalAttributesFromQuery(query)))
354} 363}
355 364
356async function listVideoChannelFollowers (req: express.Request, res: express.Response) { 365async 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'
5import { LiveManager } from '@server/lib/live' 5import { LiveManager } from '@server/lib/live'
6import { openapiOperationDoc } from '@server/middlewares/doc' 6import { openapiOperationDoc } from '@server/middlewares/doc'
7import { getServerActor } from '@server/models/application/application' 7import { getServerActor } from '@server/models/application/application'
8import { guessAdditionalAttributesFromQuery } from '@server/models/video/formatter/video-format-utils'
8import { MVideoAccountLight } from '@server/types/models' 9import { MVideoAccountLight } from '@server/types/models'
9import { HttpStatusCode } from '../../../../shared/models' 10import { HttpStatusCode } from '../../../../shared/models'
10import { auditLoggerFactory, getAuditIdFromRes, VideoAuditView } from '../../../helpers/audit-logger' 11import { auditLoggerFactory, getAuditIdFromRes, VideoAuditView } from '../../../helpers/audit-logger'
@@ -211,13 +212,18 @@ async function getVideoFileMetadata (req: express.Request, res: express.Response
211} 212}
212 213
213async function listVideos (req: express.Request, res: express.Response) { 214async function listVideos (req: express.Request, res: express.Response) {
215 const serverActor = await getServerActor()
216
214 const query = pickCommonVideoQuery(req.query) 217 const query = pickCommonVideoQuery(req.query)
215 const countVideos = getCountVideos(req) 218 const countVideos = getCountVideos(req)
216 219
217 const apiOptions = await Hooks.wrapObject({ 220 const apiOptions = await Hooks.wrapObject({
218 ...query, 221 ...query,
219 222
220 includeLocalVideos: true, 223 displayOnlyForFollower: {
224 actorId: serverActor.id,
225 orLocalVideos: true
226 },
221 nsfw: buildNSFWFilter(res, query.nsfw), 227 nsfw: buildNSFWFilter(res, query.nsfw),
222 withFiles: false, 228 withFiles: false,
223 user: res.locals.oauth ? res.locals.oauth.token.User : undefined, 229 user: res.locals.oauth ? res.locals.oauth.token.User : undefined,
@@ -230,7 +236,7 @@ async function listVideos (req: express.Request, res: express.Response) {
230 'filter:api.videos.list.result' 236 'filter:api.videos.list.result'
231 ) 237 )
232 238
233 return res.json(getFormattedObjects(resultList.data, resultList.total)) 239 return res.json(getFormattedObjects(resultList.data, resultList.total, guessAdditionalAttributesFromQuery(query)))
234} 240}
235 241
236async function removeVideo (_req: express.Request, res: express.Response) { 242async function removeVideo (_req: express.Request, res: express.Response) {