]>
Commit | Line | Data |
---|---|---|
2e401e85 | 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' | |
2e401e85 | 6 | import { areValidationErrors, checkUserCanManageVideo, doesVideoExist, isValidVideoIdParam } from '../shared' |
7 | ||
8 | const videoSourceGetValidator = [ | |
9 | isValidVideoIdParam('id'), | |
10 | ||
11 | async (req: express.Request, res: express.Response, next: express.NextFunction) => { | |
2e401e85 | 12 | if (areValidationErrors(req, res)) return |
13 | if (!await doesVideoExist(req.params.id, res, 'for-api')) return | |
14 | ||
15 | const video = getVideoWithAttributes(res) as MVideoFullLight | |
16 | ||
17 | res.locals.videoSource = await VideoSourceModel.loadByVideoId(video.id) | |
18 | if (!res.locals.videoSource) { | |
19 | return res.fail({ | |
20 | status: HttpStatusCode.NOT_FOUND_404, | |
21 | message: 'Video source not found' | |
22 | }) | |
23 | } | |
24 | ||
25 | const user = res.locals.oauth.token.User | |
26 | if (!checkUserCanManageVideo(user, video, UserRight.UPDATE_ANY_VIDEO, res)) return | |
27 | ||
28 | return next() | |
29 | } | |
30 | ] | |
31 | ||
32 | export { | |
33 | videoSourceGetValidator | |
34 | } |