From a2431b7dcbc72c05101dcdbe631ff84a823aeb51 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Mon, 27 Nov 2017 17:30:46 +0100 Subject: Refractor validators --- server/controllers/activitypub/client.ts | 10 +++++----- server/controllers/api/server/follows.ts | 2 +- server/controllers/api/users.ts | 16 ++++++++-------- server/controllers/api/videos/abuse.ts | 2 +- server/controllers/api/videos/blacklist.ts | 4 ++-- server/controllers/api/videos/channel.ts | 12 ++++++------ server/controllers/api/videos/index.ts | 8 ++++---- server/controllers/api/videos/rate.ts | 2 +- server/controllers/services.ts | 8 ++++++-- server/controllers/webfinger.ts | 3 ++- 10 files changed, 36 insertions(+), 31 deletions(-) (limited to 'server/controllers') diff --git a/server/controllers/activitypub/client.ts b/server/controllers/activitypub/client.ts index 41272bca0..62cde1fc7 100644 --- a/server/controllers/activitypub/client.ts +++ b/server/controllers/activitypub/client.ts @@ -19,22 +19,22 @@ import { VideoShareInstance } from '../../models/video/video-share-interface' const activityPubClientRouter = express.Router() activityPubClientRouter.get('/account/:name', - executeIfActivityPub(localAccountValidator), + executeIfActivityPub(asyncMiddleware(localAccountValidator)), executeIfActivityPub(accountController) ) activityPubClientRouter.get('/account/:name/followers', - executeIfActivityPub(localAccountValidator), + executeIfActivityPub(asyncMiddleware(localAccountValidator)), executeIfActivityPub(asyncMiddleware(accountFollowersController)) ) activityPubClientRouter.get('/account/:name/following', - executeIfActivityPub(localAccountValidator), + executeIfActivityPub(asyncMiddleware(localAccountValidator)), executeIfActivityPub(asyncMiddleware(accountFollowingController)) ) activityPubClientRouter.get('/videos/watch/:id', - executeIfActivityPub(videosGetValidator), + executeIfActivityPub(asyncMiddleware(videosGetValidator)), executeIfActivityPub(videoController) ) @@ -44,7 +44,7 @@ activityPubClientRouter.get('/videos/watch/:id/announces/:accountId', ) activityPubClientRouter.get('/video-channels/:id', - executeIfActivityPub(videoChannelsGetValidator), + executeIfActivityPub(asyncMiddleware(videoChannelsGetValidator)), executeIfActivityPub(asyncMiddleware(videoChannelController)) ) diff --git a/server/controllers/api/server/follows.ts b/server/controllers/api/server/follows.ts index 535d530f7..c2fb37c39 100644 --- a/server/controllers/api/server/follows.ts +++ b/server/controllers/api/server/follows.ts @@ -41,7 +41,7 @@ serverFollowsRouter.post('/following', serverFollowsRouter.delete('/following/:accountId', authenticate, ensureUserHasRight(UserRight.MANAGE_SERVER_FOLLOW), - removeFollowingValidator, + asyncMiddleware(removeFollowingValidator), asyncMiddleware(removeFollow) ) diff --git a/server/controllers/api/users.ts b/server/controllers/api/users.ts index ac7c87517..721b23301 100644 --- a/server/controllers/api/users.ts +++ b/server/controllers/api/users.ts @@ -43,7 +43,7 @@ usersRouter.get('/me/videos', usersRouter.get('/me/videos/:videoId/rating', authenticate, - usersVideoRatingValidator, + asyncMiddleware(usersVideoRatingValidator), asyncMiddleware(getUserVideoRating) ) @@ -56,20 +56,20 @@ usersRouter.get('/', ) usersRouter.get('/:id', - usersGetValidator, + asyncMiddleware(usersGetValidator), getUser ) usersRouter.post('/', authenticate, ensureUserHasRight(UserRight.MANAGE_USERS), - usersAddValidator, - createUserRetryWrapper + asyncMiddleware(usersAddValidator), + asyncMiddleware(createUserRetryWrapper) ) usersRouter.post('/register', - ensureUserRegistrationAllowed, - usersRegisterValidator, + asyncMiddleware(ensureUserRegistrationAllowed), + asyncMiddleware(usersRegisterValidator), asyncMiddleware(registerUserRetryWrapper) ) @@ -82,14 +82,14 @@ usersRouter.put('/me', usersRouter.put('/:id', authenticate, ensureUserHasRight(UserRight.MANAGE_USERS), - usersUpdateValidator, + asyncMiddleware(usersUpdateValidator), asyncMiddleware(updateUser) ) usersRouter.delete('/:id', authenticate, ensureUserHasRight(UserRight.MANAGE_USERS), - usersRemoveValidator, + asyncMiddleware(usersRemoveValidator), asyncMiddleware(removeUser) ) diff --git a/server/controllers/api/videos/abuse.ts b/server/controllers/api/videos/abuse.ts index 88b3d538d..29e1175c5 100644 --- a/server/controllers/api/videos/abuse.ts +++ b/server/controllers/api/videos/abuse.ts @@ -33,7 +33,7 @@ abuseVideoRouter.get('/abuse', ) abuseVideoRouter.post('/:id/abuse', authenticate, - videoAbuseReportValidator, + asyncMiddleware(videoAbuseReportValidator), asyncMiddleware(reportVideoAbuseRetryWrapper) ) diff --git a/server/controllers/api/videos/blacklist.ts b/server/controllers/api/videos/blacklist.ts index be7cf6ea4..06333c271 100644 --- a/server/controllers/api/videos/blacklist.ts +++ b/server/controllers/api/videos/blacklist.ts @@ -21,7 +21,7 @@ const blacklistRouter = express.Router() blacklistRouter.post('/:videoId/blacklist', authenticate, ensureUserHasRight(UserRight.MANAGE_VIDEO_BLACKLIST), - videosBlacklistAddValidator, + asyncMiddleware(videosBlacklistAddValidator), asyncMiddleware(addVideoToBlacklist) ) @@ -38,7 +38,7 @@ blacklistRouter.get('/blacklist', blacklistRouter.delete('/:videoId/blacklist', authenticate, ensureUserHasRight(UserRight.MANAGE_VIDEO_BLACKLIST), - videosBlacklistRemoveValidator, + asyncMiddleware(videosBlacklistRemoveValidator), asyncMiddleware(removeVideoFromBlacklistController) ) diff --git a/server/controllers/api/videos/channel.ts b/server/controllers/api/videos/channel.ts index ce2656e71..d99f47c32 100644 --- a/server/controllers/api/videos/channel.ts +++ b/server/controllers/api/videos/channel.ts @@ -3,6 +3,7 @@ import { VideoChannelCreate, VideoChannelUpdate } from '../../../../shared' import { getFormattedObjects, logger, resetSequelizeInstance, retryTransactionWrapper } from '../../../helpers' import { database as db } from '../../../initializers' import { createVideoChannel } from '../../../lib' +import { sendUpdateVideoChannel } from '../../../lib/activitypub/send/send-update' import { asyncMiddleware, authenticate, @@ -10,14 +11,13 @@ import { paginationValidator, setPagination, setVideoChannelsSort, - videoChannelsGetValidator, videoChannelsAddValidator, + videoChannelsGetValidator, videoChannelsRemoveValidator, videoChannelsSortValidator, videoChannelsUpdateValidator } from '../../../middlewares' import { AccountInstance, VideoChannelInstance } from '../../../models' -import { sendUpdateVideoChannel } from '../../../lib/activitypub/send/send-update' const videoChannelRouter = express.Router() @@ -30,7 +30,7 @@ videoChannelRouter.get('/channels', ) videoChannelRouter.get('/accounts/:accountId/channels', - listVideoAccountChannelsValidator, + asyncMiddleware(listVideoAccountChannelsValidator), asyncMiddleware(listVideoAccountChannels) ) @@ -42,18 +42,18 @@ videoChannelRouter.post('/channels', videoChannelRouter.put('/channels/:id', authenticate, - videoChannelsUpdateValidator, + asyncMiddleware(videoChannelsUpdateValidator), updateVideoChannelRetryWrapper ) videoChannelRouter.delete('/channels/:id', authenticate, - videoChannelsRemoveValidator, + asyncMiddleware(videoChannelsRemoveValidator), asyncMiddleware(removeVideoChannelRetryWrapper) ) videoChannelRouter.get('/channels/:id', - videoChannelsGetValidator, + asyncMiddleware(videoChannelsGetValidator), asyncMiddleware(getVideoChannel) ) diff --git a/server/controllers/api/videos/index.ts b/server/controllers/api/videos/index.ts index 2b5afd632..244d91914 100644 --- a/server/controllers/api/videos/index.ts +++ b/server/controllers/api/videos/index.ts @@ -86,7 +86,7 @@ videosRouter.get('/', ) videosRouter.put('/:id', authenticate, - videosUpdateValidator, + asyncMiddleware(videosUpdateValidator), asyncMiddleware(updateVideoRetryWrapper) ) videosRouter.post('/upload', @@ -97,17 +97,17 @@ videosRouter.post('/upload', ) videosRouter.get('/:id/description', - videosGetValidator, + asyncMiddleware(videosGetValidator), asyncMiddleware(getVideoDescription) ) videosRouter.get('/:id', - videosGetValidator, + asyncMiddleware(videosGetValidator), getVideo ) videosRouter.delete('/:id', authenticate, - videosRemoveValidator, + asyncMiddleware(videosRemoveValidator), asyncMiddleware(removeVideoRetryWrapper) ) diff --git a/server/controllers/api/videos/rate.ts b/server/controllers/api/videos/rate.ts index 134284df7..0c6a988cf 100644 --- a/server/controllers/api/videos/rate.ts +++ b/server/controllers/api/videos/rate.ts @@ -12,7 +12,7 @@ const rateVideoRouter = express.Router() rateVideoRouter.put('/:id/rate', authenticate, - videoRateValidator, + asyncMiddleware(videoRateValidator), asyncMiddleware(rateVideoRetryWrapper) ) diff --git a/server/controllers/services.ts b/server/controllers/services.ts index 0db6e5498..0c325678c 100644 --- a/server/controllers/services.ts +++ b/server/controllers/services.ts @@ -1,12 +1,16 @@ import * as express from 'express' -import { CONFIG, PREVIEWS_SIZE, EMBED_SIZE } from '../initializers' +import { CONFIG, EMBED_SIZE, PREVIEWS_SIZE } from '../initializers' import { oembedValidator } from '../middlewares' +import { asyncMiddleware } from '../middlewares/async' import { VideoInstance } from '../models' const servicesRouter = express.Router() -servicesRouter.use('/oembed', oembedValidator, generateOEmbed) +servicesRouter.use('/oembed', + asyncMiddleware(oembedValidator), + generateOEmbed +) // --------------------------------------------------------------------------- diff --git a/server/controllers/webfinger.ts b/server/controllers/webfinger.ts index cc28a8909..1cea513a1 100644 --- a/server/controllers/webfinger.ts +++ b/server/controllers/webfinger.ts @@ -1,11 +1,12 @@ import * as express from 'express' +import { asyncMiddleware } from '../middlewares/async' import { webfingerValidator } from '../middlewares/validators/webfinger' import { AccountInstance } from '../models/account/account-interface' const webfingerRouter = express.Router() webfingerRouter.get('/.well-known/webfinger', - webfingerValidator, + asyncMiddleware(webfingerValidator), webfingerController ) -- cgit v1.2.3