X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Fcontrollers%2Fapi%2Fvideos%2Findex.ts;h=49490f79b13c3579918f0f47d337d47cd88f97d1;hb=171efc48e67498406feb6d7873b3482b41505515;hp=8c6c441448561598bacba05be3a722531f0122f8;hpb=c756bae079e02873f6433582ca14a092fec0db27;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/controllers/api/videos/index.ts b/server/controllers/api/videos/index.ts index 8c6c44144..49490f79b 100644 --- a/server/controllers/api/videos/index.ts +++ b/server/controllers/api/videos/index.ts @@ -1,12 +1,12 @@ import * as express from 'express' import toInt from 'validator/lib/toInt' +import { pickCommonVideoQuery } from '@server/helpers/query' import { doJSONRequest } from '@server/helpers/requests' -import { LiveManager } from '@server/lib/live-manager' +import { LiveManager } from '@server/lib/live' import { openapiOperationDoc } from '@server/middlewares/doc' import { getServerActor } from '@server/models/application/application' import { MVideoAccountLight } from '@server/types/models' -import { VideosCommonQuery } from '../../../../shared' -import { HttpStatusCode } from '../../../../shared/core-utils/miscs' +import { HttpStatusCode } from '../../../../shared/models' import { auditLoggerFactory, getAuditIdFromRes, VideoAuditView } from '../../../helpers/audit-logger' import { buildNSFWFilter, getCountVideos } from '../../../helpers/express-utils' import { logger } from '../../../helpers/logger' @@ -100,7 +100,7 @@ videosRouter.get('/:id/metadata/:videoFileId', videosRouter.get('/:id', openapiOperationDoc({ operationId: 'getVideo' }), optionalAuthenticate, - asyncMiddleware(videosCustomGetValidator('only-video-with-rights')), + asyncMiddleware(videosCustomGetValidator('for-api')), asyncMiddleware(checkVideoFollowConstraints), asyncMiddleware(getVideo) ) @@ -142,14 +142,7 @@ function listVideoPrivacies (_req: express.Request, res: express.Response) { } async function getVideo (_req: express.Request, res: express.Response) { - // We need more attributes - const userId: number = res.locals.oauth ? res.locals.oauth.token.User.id : null - - const video = await Hooks.wrapPromiseFun( - VideoModel.loadForGetAPI, - { id: res.locals.onlyVideoWithRights.id, userId }, - 'filter:api.video.get.result' - ) + const video = res.locals.videoAPI if (video.isOutdated()) { JobQueue.Instance.createJob({ type: 'activitypub-refresher', payload: { type: 'video', url: video.url } }) @@ -218,22 +211,14 @@ async function getVideoFileMetadata (req: express.Request, res: express.Response } async function listVideos (req: express.Request, res: express.Response) { - const query = req.query as VideosCommonQuery + const query = pickCommonVideoQuery(req.query) const countVideos = getCountVideos(req) const apiOptions = await Hooks.wrapObject({ - start: query.start, - count: query.count, - sort: query.sort, + ...query, + includeLocalVideos: true, - categoryOneOf: query.categoryOneOf, - licenceOneOf: query.licenceOneOf, - languageOneOf: query.languageOneOf, - tagsOneOf: query.tagsOneOf, - tagsAllOf: query.tagsAllOf, nsfw: buildNSFWFilter(res, query.nsfw), - isLive: query.isLive, - filter: query.filter, withFiles: false, user: res.locals.oauth ? res.locals.oauth.token.User : undefined, countVideos