]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/middlewares/validators/videos/videos.ts
Implement video comment list in admin
[github/Chocobozzz/PeerTube.git] / server / middlewares / validators / videos / videos.ts
index 867c05fc13f8152dca39732973f07adb3e9882ab..ff90e347ae0b44d0d78819641decabb5c1ebbb8b 100644 (file)
@@ -1,6 +1,10 @@
 import * as express from 'express'
 import { body, param, query, ValidationChain } from 'express-validator'
-import { UserRight, VideoChangeOwnershipStatus, VideoPrivacy } from '../../../../shared'
+import { isAbleToUploadVideo } from '@server/lib/user'
+import { getServerActor } from '@server/models/application/application'
+import { MVideoFullLight } from '@server/types/models'
+import { ServerErrorCode, UserRight, VideoChangeOwnershipStatus, VideoPrivacy } from '../../../../shared'
+import { VideoChangeOwnershipAccept } from '../../../../shared/models/videos/video-change-ownership-accept.model'
 import {
   isBooleanValid,
   isDateValid,
@@ -12,6 +16,8 @@ import {
   toIntOrNull,
   toValueOrNull
 } from '../../../helpers/custom-validators/misc'
+import { isNSFWQueryValid, isNumberArray, isStringArray } from '../../../helpers/custom-validators/search'
+import { checkUserCanTerminateOwnershipChange, doesChangeVideoOwnershipExist } from '../../../helpers/custom-validators/video-ownership'
 import {
   isScheduleVideoUpdatePrivacyValid,
   isVideoCategoryValid,
@@ -27,29 +33,24 @@ import {
   isVideoSupportValid,
   isVideoTagsValid
 } from '../../../helpers/custom-validators/videos'
+import { cleanUpReqFiles } from '../../../helpers/express-utils'
 import { getDurationFromVideoFile } from '../../../helpers/ffmpeg-utils'
 import { logger } from '../../../helpers/logger'
-import { CONSTRAINTS_FIELDS, OVERVIEWS } from '../../../initializers/constants'
-import { authenticatePromiseIfNeeded } from '../../oauth'
-import { areValidationErrors } from '../utils'
-import { cleanUpReqFiles } from '../../../helpers/express-utils'
-import { VideoModel } from '../../../models/video/video'
-import { checkUserCanTerminateOwnershipChange, doesChangeVideoOwnershipExist } from '../../../helpers/custom-validators/video-ownership'
-import { VideoChangeOwnershipAccept } from '../../../../shared/models/videos/video-change-ownership-accept.model'
-import { AccountModel } from '../../../models/account/account'
-import { isNSFWQueryValid, isNumberArray, isStringArray } from '../../../helpers/custom-validators/search'
-import { CONFIG } from '../../../initializers/config'
-import { isLocalVideoAccepted } from '../../../lib/moderation'
-import { Hooks } from '../../../lib/plugins/hooks'
 import {
   checkUserCanManageVideo,
   doesVideoChannelOfAccountExist,
   doesVideoExist,
   doesVideoFileOfVideoExist
 } from '../../../helpers/middlewares'
-import { MVideoFullLight } from '@server/typings/models'
 import { getVideoWithAttributes } from '../../../helpers/video'
-import { getServerActor } from '@server/models/application/application'
+import { CONFIG } from '../../../initializers/config'
+import { CONSTRAINTS_FIELDS, OVERVIEWS } from '../../../initializers/constants'
+import { isLocalVideoAccepted } from '../../../lib/moderation'
+import { Hooks } from '../../../lib/plugins/hooks'
+import { AccountModel } from '../../../models/account/account'
+import { VideoModel } from '../../../models/video/video'
+import { authenticatePromiseIfNeeded } from '../../oauth'
+import { areValidationErrors } from '../utils'
 
 const videosAddValidator = getCommonVideoEditAttributes().concat([
   body('videofile')
@@ -73,7 +74,7 @@ const videosAddValidator = getCommonVideoEditAttributes().concat([
 
     if (!await doesVideoChannelOfAccountExist(req.body.channelId, user, res)) return cleanUpReqFiles(req)
 
-    if (await user.isAbleToUploadVideo(videoFile) === false) {
+    if (await isAbleToUploadVideo(user.id, videoFile.size) === false) {
       res.status(403)
          .json({ error: 'The user video quota is exceeded with this video.' })
 
@@ -148,7 +149,9 @@ async function checkVideoFollowConstraints (req: express.Request, res: express.R
 
   return res.status(403)
             .json({
-              error: 'Cannot get this video regarding follow constraints.'
+              errorCode: ServerErrorCode.DOES_NOT_RESPECT_FOLLOW_CONSTRAINTS,
+              error: 'Cannot get this video regarding follow constraints.',
+              originUrl: video.url
             })
 }
 
@@ -289,7 +292,7 @@ const videosAcceptChangeOwnershipValidator = [
 
     const user = res.locals.oauth.token.User
     const videoChangeOwnership = res.locals.videoChangeOwnership
-    const isAble = await user.isAbleToUploadVideo(videoChangeOwnership.Video.getMaxQualityFile())
+    const isAble = await isAbleToUploadVideo(user.id, videoChangeOwnership.Video.getMaxQualityFile().size)
     if (isAble === false) {
       res.status(403)
         .json({ error: 'The user video quota is exceeded with this video.' })