]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/middlewares/validators/user-subscriptions.ts
Cleanup useless express validator messages
[github/Chocobozzz/PeerTube.git] / server / middlewares / validators / user-subscriptions.ts
index 48ce90d7b0f7f30a82f76034e214b958ebf644a3..d9e6aa66724236efe1277b4790f8f6f245bca231 100644 (file)
@@ -9,7 +9,9 @@ import { ActorFollowModel } from '../../models/actor/actor-follow'
 import { areValidationErrors } from './shared'
 
 const userSubscriptionListValidator = [
-  query('search').optional().not().isEmpty().withMessage('Should have a valid search'),
+  query('search')
+    .optional()
+    .not().isEmpty(),
 
   (req: express.Request, res: express.Response, next: express.NextFunction) => {
     logger.debug('Checking userSubscriptionListValidator parameters', { parameters: req.query })
@@ -21,7 +23,8 @@ const userSubscriptionListValidator = [
 ]
 
 const userSubscriptionAddValidator = [
-  body('uri').custom(isValidActorHandle).withMessage('Should have a valid URI to follow (username@domain)'),
+  body('uri')
+    .custom(isValidActorHandle).withMessage('Should have a valid URI to follow (username@domain)'),
 
   (req: express.Request, res: express.Response, next: express.NextFunction) => {
     logger.debug('Checking userSubscriptionAddValidator parameters', { parameters: req.body })
@@ -35,7 +38,7 @@ const userSubscriptionAddValidator = [
 const areSubscriptionsExistValidator = [
   query('uris')
     .customSanitizer(toArray)
-    .custom(areValidActorHandles).withMessage('Should have a valid uri array'),
+    .custom(areValidActorHandles).withMessage('Should have a valid array of URIs'),
 
   (req: express.Request, res: express.Response, next: express.NextFunction) => {
     logger.debug('Checking areSubscriptionsExistValidator parameters', { parameters: req.query })
@@ -47,7 +50,8 @@ const areSubscriptionsExistValidator = [
 ]
 
 const userSubscriptionGetValidator = [
-  param('uri').custom(isValidActorHandle).withMessage('Should have a valid URI to unfollow'),
+  param('uri')
+    .custom(isValidActorHandle),
 
   async (req: express.Request, res: express.Response, next: express.NextFunction) => {
     logger.debug('Checking userSubscriptionGetValidator parameters', { parameters: req.params })
@@ -58,7 +62,12 @@ const userSubscriptionGetValidator = [
     if (host === WEBSERVER.HOST) host = null
 
     const user = res.locals.oauth.token.User
-    const subscription = await ActorFollowModel.loadByActorAndTargetNameAndHostForAPI(user.Account.Actor.id, name, host)
+    const subscription = await ActorFollowModel.loadByActorAndTargetNameAndHostForAPI({
+      actorId: user.Account.Actor.id,
+      targetName: name,
+      targetHost: host,
+      state: 'accepted'
+    })
 
     if (!subscription || !subscription.ActorFollowing.VideoChannel) {
       return res.fail({