-import * as express from 'express'
+import 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'
videosRouter.get('/:id',
openapiOperationDoc({ operationId: 'getVideo' }),
optionalAuthenticate,
- asyncMiddleware(videosCustomGetValidator('only-video-with-rights')),
+ asyncMiddleware(videosCustomGetValidator('for-api')),
asyncMiddleware(checkVideoFollowConstraints),
- asyncMiddleware(getVideo)
+ getVideo
)
videosRouter.post('/:id/views',
openapiOperationDoc({ operationId: 'addView' }),
res.json(VIDEO_PRIVACIES)
}
-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'
- )
+function getVideo (_req: express.Request, res: express.Response) {
+ const video = res.locals.videoAPI
if (video.isOutdated()) {
JobQueue.Instance.createJob({ type: 'activitypub-refresher', payload: { type: 'video', url: video.url } })
}
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