1 import express from 'express'
2 import { getVideoWithAttributes } from '@server/helpers/video'
3 import { VideoSourceModel } from '@server/models/video/video-source'
4 import { MVideoFullLight } from '@server/types/models'
5 import { HttpStatusCode, UserRight } from '@shared/models'
6 import { logger } from '../../../helpers/logger'
7 import { areValidationErrors, checkUserCanManageVideo, doesVideoExist, isValidVideoIdParam } from '../shared'
9 const videoSourceGetValidator = [
10 isValidVideoIdParam('id'),
12 async (req: express.Request, res: express.Response, next: express.NextFunction) => {
13 logger.debug('Checking videoSourceGet parameters', { parameters: req.params })
15 if (areValidationErrors(req, res)) return
16 if (!await doesVideoExist(req.params.id, res, 'for-api')) return
18 const video = getVideoWithAttributes(res) as MVideoFullLight
20 res.locals.videoSource = await VideoSourceModel.loadByVideoId(video.id)
21 if (!res.locals.videoSource) {
23 status: HttpStatusCode.NOT_FOUND_404,
24 message: 'Video source not found'
28 const user = res.locals.oauth.token.User
29 if (!checkUserCanManageVideo(user, video, UserRight.UPDATE_ANY_VIDEO, res)) return
36 videoSourceGetValidator