import { Hooks } from '../../../lib/plugins/hooks'
import { checkUserCanManageVideo, doesVideoChannelOfAccountExist, doesVideoExist } from '../../../helpers/middlewares'
import { MVideoFullLight } from '@server/typings/models'
-import { getVideo } from '../../../helpers/video'
+import { getVideoWithAttributes } from '../../../helpers/video'
const videosAddValidator = getCommonVideoEditAttributes().concat([
body('videofile')
])
async function checkVideoFollowConstraints (req: express.Request, res: express.Response, next: express.NextFunction) {
- const video = getVideo(res)
+ const video = getVideoWithAttributes(res)
// Anybody can watch local videos
if (video.isOwned() === true) return next()
})
}
-const videosCustomGetValidator = (fetchType: 'all' | 'only-video' | 'only-video-with-rights') => {
+const videosCustomGetValidator = (fetchType: 'all' | 'only-video' | 'only-video-with-rights', authenticateInQuery = false) => {
return [
param('id').custom(isIdOrUUIDValid).not().isEmpty().withMessage('Should have a valid id'),
if (areValidationErrors(req, res)) return
if (!await doesVideoExist(req.params.id, res, fetchType)) return
- const video = getVideo(res)
+ const video = getVideoWithAttributes(res)
const videoAll = video as MVideoFullLight
// Video private or blacklisted
if (video.privacy === VideoPrivacy.PRIVATE || videoAll.VideoBlacklist) {
- await authenticatePromiseIfNeeded(req, res)
+ await authenticatePromiseIfNeeded(req, res, authenticateInQuery)
const user = res.locals.oauth ? res.locals.oauth.token.User : null
}
const videosGetValidator = videosCustomGetValidator('all')
+const videosDownloadValidator = videosCustomGetValidator('all', true)
const videosRemoveValidator = [
param('id').custom(isIdOrUUIDValid).not().isEmpty().withMessage('Should have a valid id'),
const user = res.locals.oauth.token.User
const videoChangeOwnership = res.locals.videoChangeOwnership
- const isAble = await user.isAbleToUploadVideo(videoChangeOwnership.Video.getOriginalFile())
+ const isAble = await user.isAbleToUploadVideo(videoChangeOwnership.Video.getMaxQualityFile())
if (isAble === false) {
res.status(403)
.json({ error: 'The user video quota is exceeded with this video.' })
videosAddValidator,
videosUpdateValidator,
videosGetValidator,
+ videosDownloadValidator,
checkVideoFollowConstraints,
videosCustomGetValidator,
videosRemoveValidator,