]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/middlewares/validators/videos/video-ownership-changes.ts
Add sync link to import page
[github/Chocobozzz/PeerTube.git] / server / middlewares / validators / videos / video-ownership-changes.ts
index 120b0469cc92b8c72e007d82139003a164997b8e..6dcdc05f5c72cdbc7673eb7857d7b01b2244d206 100644 (file)
@@ -1,23 +1,23 @@
-import * as express from 'express'
+import express from 'express'
 import { param } from 'express-validator'
-import { isIdOrUUIDValid } from '@server/helpers/custom-validators/misc'
+import { isIdValid } from '@server/helpers/custom-validators/misc'
 import { checkUserCanTerminateOwnershipChange } from '@server/helpers/custom-validators/video-ownership'
 import { logger } from '@server/helpers/logger'
-import { isAbleToUploadVideo } from '@server/lib/user'
 import { AccountModel } from '@server/models/account/account'
 import { MVideoWithAllFiles } from '@server/types/models'
-import { HttpStatusCode } from '@shared/core-utils'
-import { ServerErrorCode, UserRight, VideoChangeOwnershipAccept, VideoChangeOwnershipStatus, VideoState } from '@shared/models'
+import { HttpStatusCode, UserRight, VideoChangeOwnershipAccept, VideoChangeOwnershipStatus, VideoState } from '@shared/models'
 import {
   areValidationErrors,
   checkUserCanManageVideo,
+  checkUserQuota,
   doesChangeVideoOwnershipExist,
   doesVideoChannelOfAccountExist,
-  doesVideoExist
+  doesVideoExist,
+  isValidVideoIdParam
 } from '../shared'
 
 const videosChangeOwnershipValidator = [
-  param('videoId').custom(isIdOrUUIDValid).not().isEmpty().withMessage('Should have a valid id'),
+  isValidVideoIdParam('videoId'),
 
   async (req: express.Request, res: express.Response, next: express.NextFunction) => {
     logger.debug('Checking changeOwnership parameters', { parameters: req.params })
@@ -40,7 +40,8 @@ const videosChangeOwnershipValidator = [
 ]
 
 const videosTerminateChangeOwnershipValidator = [
-  param('id').custom(isIdOrUUIDValid).not().isEmpty().withMessage('Should have a valid id'),
+  param('id')
+    .custom(isIdValid).withMessage('Should have a valid id'),
 
   async (req: express.Request, res: express.Response, next: express.NextFunction) => {
     logger.debug('Checking changeOwnership parameters', { parameters: req.params })
@@ -105,15 +106,7 @@ async function checkCanAccept (video: MVideoWithAllFiles, res: express.Response)
 
   const user = res.locals.oauth.token.User
 
-  if (!await isAbleToUploadVideo(user.id, video.getMaxQualityFile().size)) {
-    res.fail({
-      status: HttpStatusCode.PAYLOAD_TOO_LARGE_413,
-      message: 'The user video quota is exceeded with this video.',
-      type: ServerErrorCode.QUOTA_REACHED
-    })
-
-    return false
-  }
+  if (!await checkUserQuota(user, video.getMaxQualityFile().size, res)) return false
 
   return true
 }