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 { areValidationErrors, checkUserCanManageVideo, doesVideoExist, isValidVideoIdParam } from '../shared'
8 const videoSourceGetValidator = [
9 isValidVideoIdParam('id'),
11 async (req: express.Request, res: express.Response, next: express.NextFunction) => {
12 if (areValidationErrors(req, res)) return
13 if (!await doesVideoExist(req.params.id, res, 'for-api')) return
15 const video = getVideoWithAttributes(res) as MVideoFullLight
17 res.locals.videoSource = await VideoSourceModel.loadByVideoId(video.id)
18 if (!res.locals.videoSource) {
20 status: HttpStatusCode.NOT_FOUND_404,
21 message: 'Video source not found'
25 const user = res.locals.oauth.token.User
26 if (!checkUserCanManageVideo(user, video, UserRight.UPDATE_ANY_VIDEO, res)) return
33 videoSourceGetValidator