]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/middlewares/validators/videos/video-shares.ts
Translated using Weblate (Persian)
[github/Chocobozzz/PeerTube.git] / server / middlewares / validators / videos / video-shares.ts
index d5cbdb03ef2ae64eccfdc821f6d844e4bbc03a79..c234de6ed53dfff68b1b3e69af101a19c6cc9d63 100644 (file)
@@ -1,27 +1,25 @@
-import * as express from 'express'
-import 'express-validator'
-import { param } from 'express-validator/check'
-import { isIdOrUUIDValid, isIdValid } from '../../../helpers/custom-validators/misc'
-import { doesVideoExist } from '../../../helpers/custom-validators/videos'
-import { logger } from '../../../helpers/logger'
+import express from 'express'
+import { param } from 'express-validator'
+import { HttpStatusCode } from '../../../../shared/models/http/http-error-codes'
+import { isIdValid } from '../../../helpers/custom-validators/misc'
 import { VideoShareModel } from '../../../models/video/video-share'
-import { areValidationErrors } from '../utils'
+import { areValidationErrors, doesVideoExist, isValidVideoIdParam } from '../shared'
 
 const videosShareValidator = [
-  param('id').custom(isIdOrUUIDValid).not().isEmpty().withMessage('Should have a valid id'),
-  param('actorId').custom(isIdValid).not().isEmpty().withMessage('Should have a valid actor id'),
+  isValidVideoIdParam('id'),
 
-  async (req: express.Request, res: express.Response, next: express.NextFunction) => {
-    logger.debug('Checking videoShare parameters', { parameters: req.params })
+  param('actorId')
+    .custom(isIdValid),
 
+  async (req: express.Request, res: express.Response, next: express.NextFunction) => {
     if (areValidationErrors(req, res)) return
     if (!await doesVideoExist(req.params.id, res)) return
 
-    const video = res.locals.video
+    const video = res.locals.videoAll
 
     const share = await VideoShareModel.load(req.params.actorId, video.id)
     if (!share) {
-      return res.status(404)
+      return res.status(HttpStatusCode.NOT_FOUND_404)
                 .end()
     }