diff options
author | Chocobozzz <florian.bigard@gmail.com> | 2017-11-27 17:30:46 +0100 |
---|---|---|
committer | Chocobozzz <florian.bigard@gmail.com> | 2017-11-27 19:43:01 +0100 |
commit | a2431b7dcbc72c05101dcdbe631ff84a823aeb51 (patch) | |
tree | 09278a822905622a70ff976a75e09d99bc45639a /server/controllers | |
parent | fcaf1e0aa84213a1b1f1b1a44a3276eae35ebe70 (diff) | |
download | PeerTube-a2431b7dcbc72c05101dcdbe631ff84a823aeb51.tar.gz PeerTube-a2431b7dcbc72c05101dcdbe631ff84a823aeb51.tar.zst PeerTube-a2431b7dcbc72c05101dcdbe631ff84a823aeb51.zip |
Refractor validators
Diffstat (limited to 'server/controllers')
-rw-r--r-- | server/controllers/activitypub/client.ts | 10 | ||||
-rw-r--r-- | server/controllers/api/server/follows.ts | 2 | ||||
-rw-r--r-- | server/controllers/api/users.ts | 16 | ||||
-rw-r--r-- | server/controllers/api/videos/abuse.ts | 2 | ||||
-rw-r--r-- | server/controllers/api/videos/blacklist.ts | 4 | ||||
-rw-r--r-- | server/controllers/api/videos/channel.ts | 12 | ||||
-rw-r--r-- | server/controllers/api/videos/index.ts | 8 | ||||
-rw-r--r-- | server/controllers/api/videos/rate.ts | 2 | ||||
-rw-r--r-- | server/controllers/services.ts | 8 | ||||
-rw-r--r-- | server/controllers/webfinger.ts | 3 |
10 files changed, 36 insertions, 31 deletions
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' | |||
19 | const activityPubClientRouter = express.Router() | 19 | const activityPubClientRouter = express.Router() |
20 | 20 | ||
21 | activityPubClientRouter.get('/account/:name', | 21 | activityPubClientRouter.get('/account/:name', |
22 | executeIfActivityPub(localAccountValidator), | 22 | executeIfActivityPub(asyncMiddleware(localAccountValidator)), |
23 | executeIfActivityPub(accountController) | 23 | executeIfActivityPub(accountController) |
24 | ) | 24 | ) |
25 | 25 | ||
26 | activityPubClientRouter.get('/account/:name/followers', | 26 | activityPubClientRouter.get('/account/:name/followers', |
27 | executeIfActivityPub(localAccountValidator), | 27 | executeIfActivityPub(asyncMiddleware(localAccountValidator)), |
28 | executeIfActivityPub(asyncMiddleware(accountFollowersController)) | 28 | executeIfActivityPub(asyncMiddleware(accountFollowersController)) |
29 | ) | 29 | ) |
30 | 30 | ||
31 | activityPubClientRouter.get('/account/:name/following', | 31 | activityPubClientRouter.get('/account/:name/following', |
32 | executeIfActivityPub(localAccountValidator), | 32 | executeIfActivityPub(asyncMiddleware(localAccountValidator)), |
33 | executeIfActivityPub(asyncMiddleware(accountFollowingController)) | 33 | executeIfActivityPub(asyncMiddleware(accountFollowingController)) |
34 | ) | 34 | ) |
35 | 35 | ||
36 | activityPubClientRouter.get('/videos/watch/:id', | 36 | activityPubClientRouter.get('/videos/watch/:id', |
37 | executeIfActivityPub(videosGetValidator), | 37 | executeIfActivityPub(asyncMiddleware(videosGetValidator)), |
38 | executeIfActivityPub(videoController) | 38 | executeIfActivityPub(videoController) |
39 | ) | 39 | ) |
40 | 40 | ||
@@ -44,7 +44,7 @@ activityPubClientRouter.get('/videos/watch/:id/announces/:accountId', | |||
44 | ) | 44 | ) |
45 | 45 | ||
46 | activityPubClientRouter.get('/video-channels/:id', | 46 | activityPubClientRouter.get('/video-channels/:id', |
47 | executeIfActivityPub(videoChannelsGetValidator), | 47 | executeIfActivityPub(asyncMiddleware(videoChannelsGetValidator)), |
48 | executeIfActivityPub(asyncMiddleware(videoChannelController)) | 48 | executeIfActivityPub(asyncMiddleware(videoChannelController)) |
49 | ) | 49 | ) |
50 | 50 | ||
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', | |||
41 | serverFollowsRouter.delete('/following/:accountId', | 41 | serverFollowsRouter.delete('/following/:accountId', |
42 | authenticate, | 42 | authenticate, |
43 | ensureUserHasRight(UserRight.MANAGE_SERVER_FOLLOW), | 43 | ensureUserHasRight(UserRight.MANAGE_SERVER_FOLLOW), |
44 | removeFollowingValidator, | 44 | asyncMiddleware(removeFollowingValidator), |
45 | asyncMiddleware(removeFollow) | 45 | asyncMiddleware(removeFollow) |
46 | ) | 46 | ) |
47 | 47 | ||
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', | |||
43 | 43 | ||
44 | usersRouter.get('/me/videos/:videoId/rating', | 44 | usersRouter.get('/me/videos/:videoId/rating', |
45 | authenticate, | 45 | authenticate, |
46 | usersVideoRatingValidator, | 46 | asyncMiddleware(usersVideoRatingValidator), |
47 | asyncMiddleware(getUserVideoRating) | 47 | asyncMiddleware(getUserVideoRating) |
48 | ) | 48 | ) |
49 | 49 | ||
@@ -56,20 +56,20 @@ usersRouter.get('/', | |||
56 | ) | 56 | ) |
57 | 57 | ||
58 | usersRouter.get('/:id', | 58 | usersRouter.get('/:id', |
59 | usersGetValidator, | 59 | asyncMiddleware(usersGetValidator), |
60 | getUser | 60 | getUser |
61 | ) | 61 | ) |
62 | 62 | ||
63 | usersRouter.post('/', | 63 | usersRouter.post('/', |
64 | authenticate, | 64 | authenticate, |
65 | ensureUserHasRight(UserRight.MANAGE_USERS), | 65 | ensureUserHasRight(UserRight.MANAGE_USERS), |
66 | usersAddValidator, | 66 | asyncMiddleware(usersAddValidator), |
67 | createUserRetryWrapper | 67 | asyncMiddleware(createUserRetryWrapper) |
68 | ) | 68 | ) |
69 | 69 | ||
70 | usersRouter.post('/register', | 70 | usersRouter.post('/register', |
71 | ensureUserRegistrationAllowed, | 71 | asyncMiddleware(ensureUserRegistrationAllowed), |
72 | usersRegisterValidator, | 72 | asyncMiddleware(usersRegisterValidator), |
73 | asyncMiddleware(registerUserRetryWrapper) | 73 | asyncMiddleware(registerUserRetryWrapper) |
74 | ) | 74 | ) |
75 | 75 | ||
@@ -82,14 +82,14 @@ usersRouter.put('/me', | |||
82 | usersRouter.put('/:id', | 82 | usersRouter.put('/:id', |
83 | authenticate, | 83 | authenticate, |
84 | ensureUserHasRight(UserRight.MANAGE_USERS), | 84 | ensureUserHasRight(UserRight.MANAGE_USERS), |
85 | usersUpdateValidator, | 85 | asyncMiddleware(usersUpdateValidator), |
86 | asyncMiddleware(updateUser) | 86 | asyncMiddleware(updateUser) |
87 | ) | 87 | ) |
88 | 88 | ||
89 | usersRouter.delete('/:id', | 89 | usersRouter.delete('/:id', |
90 | authenticate, | 90 | authenticate, |
91 | ensureUserHasRight(UserRight.MANAGE_USERS), | 91 | ensureUserHasRight(UserRight.MANAGE_USERS), |
92 | usersRemoveValidator, | 92 | asyncMiddleware(usersRemoveValidator), |
93 | asyncMiddleware(removeUser) | 93 | asyncMiddleware(removeUser) |
94 | ) | 94 | ) |
95 | 95 | ||
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', | |||
33 | ) | 33 | ) |
34 | abuseVideoRouter.post('/:id/abuse', | 34 | abuseVideoRouter.post('/:id/abuse', |
35 | authenticate, | 35 | authenticate, |
36 | videoAbuseReportValidator, | 36 | asyncMiddleware(videoAbuseReportValidator), |
37 | asyncMiddleware(reportVideoAbuseRetryWrapper) | 37 | asyncMiddleware(reportVideoAbuseRetryWrapper) |
38 | ) | 38 | ) |
39 | 39 | ||
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() | |||
21 | blacklistRouter.post('/:videoId/blacklist', | 21 | blacklistRouter.post('/:videoId/blacklist', |
22 | authenticate, | 22 | authenticate, |
23 | ensureUserHasRight(UserRight.MANAGE_VIDEO_BLACKLIST), | 23 | ensureUserHasRight(UserRight.MANAGE_VIDEO_BLACKLIST), |
24 | videosBlacklistAddValidator, | 24 | asyncMiddleware(videosBlacklistAddValidator), |
25 | asyncMiddleware(addVideoToBlacklist) | 25 | asyncMiddleware(addVideoToBlacklist) |
26 | ) | 26 | ) |
27 | 27 | ||
@@ -38,7 +38,7 @@ blacklistRouter.get('/blacklist', | |||
38 | blacklistRouter.delete('/:videoId/blacklist', | 38 | blacklistRouter.delete('/:videoId/blacklist', |
39 | authenticate, | 39 | authenticate, |
40 | ensureUserHasRight(UserRight.MANAGE_VIDEO_BLACKLIST), | 40 | ensureUserHasRight(UserRight.MANAGE_VIDEO_BLACKLIST), |
41 | videosBlacklistRemoveValidator, | 41 | asyncMiddleware(videosBlacklistRemoveValidator), |
42 | asyncMiddleware(removeVideoFromBlacklistController) | 42 | asyncMiddleware(removeVideoFromBlacklistController) |
43 | ) | 43 | ) |
44 | 44 | ||
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' | |||
3 | import { getFormattedObjects, logger, resetSequelizeInstance, retryTransactionWrapper } from '../../../helpers' | 3 | import { getFormattedObjects, logger, resetSequelizeInstance, retryTransactionWrapper } from '../../../helpers' |
4 | import { database as db } from '../../../initializers' | 4 | import { database as db } from '../../../initializers' |
5 | import { createVideoChannel } from '../../../lib' | 5 | import { createVideoChannel } from '../../../lib' |
6 | import { sendUpdateVideoChannel } from '../../../lib/activitypub/send/send-update' | ||
6 | import { | 7 | import { |
7 | asyncMiddleware, | 8 | asyncMiddleware, |
8 | authenticate, | 9 | authenticate, |
@@ -10,14 +11,13 @@ import { | |||
10 | paginationValidator, | 11 | paginationValidator, |
11 | setPagination, | 12 | setPagination, |
12 | setVideoChannelsSort, | 13 | setVideoChannelsSort, |
13 | videoChannelsGetValidator, | ||
14 | videoChannelsAddValidator, | 14 | videoChannelsAddValidator, |
15 | videoChannelsGetValidator, | ||
15 | videoChannelsRemoveValidator, | 16 | videoChannelsRemoveValidator, |
16 | videoChannelsSortValidator, | 17 | videoChannelsSortValidator, |
17 | videoChannelsUpdateValidator | 18 | videoChannelsUpdateValidator |
18 | } from '../../../middlewares' | 19 | } from '../../../middlewares' |
19 | import { AccountInstance, VideoChannelInstance } from '../../../models' | 20 | import { AccountInstance, VideoChannelInstance } from '../../../models' |
20 | import { sendUpdateVideoChannel } from '../../../lib/activitypub/send/send-update' | ||
21 | 21 | ||
22 | const videoChannelRouter = express.Router() | 22 | const videoChannelRouter = express.Router() |
23 | 23 | ||
@@ -30,7 +30,7 @@ videoChannelRouter.get('/channels', | |||
30 | ) | 30 | ) |
31 | 31 | ||
32 | videoChannelRouter.get('/accounts/:accountId/channels', | 32 | videoChannelRouter.get('/accounts/:accountId/channels', |
33 | listVideoAccountChannelsValidator, | 33 | asyncMiddleware(listVideoAccountChannelsValidator), |
34 | asyncMiddleware(listVideoAccountChannels) | 34 | asyncMiddleware(listVideoAccountChannels) |
35 | ) | 35 | ) |
36 | 36 | ||
@@ -42,18 +42,18 @@ videoChannelRouter.post('/channels', | |||
42 | 42 | ||
43 | videoChannelRouter.put('/channels/:id', | 43 | videoChannelRouter.put('/channels/:id', |
44 | authenticate, | 44 | authenticate, |
45 | videoChannelsUpdateValidator, | 45 | asyncMiddleware(videoChannelsUpdateValidator), |
46 | updateVideoChannelRetryWrapper | 46 | updateVideoChannelRetryWrapper |
47 | ) | 47 | ) |
48 | 48 | ||
49 | videoChannelRouter.delete('/channels/:id', | 49 | videoChannelRouter.delete('/channels/:id', |
50 | authenticate, | 50 | authenticate, |
51 | videoChannelsRemoveValidator, | 51 | asyncMiddleware(videoChannelsRemoveValidator), |
52 | asyncMiddleware(removeVideoChannelRetryWrapper) | 52 | asyncMiddleware(removeVideoChannelRetryWrapper) |
53 | ) | 53 | ) |
54 | 54 | ||
55 | videoChannelRouter.get('/channels/:id', | 55 | videoChannelRouter.get('/channels/:id', |
56 | videoChannelsGetValidator, | 56 | asyncMiddleware(videoChannelsGetValidator), |
57 | asyncMiddleware(getVideoChannel) | 57 | asyncMiddleware(getVideoChannel) |
58 | ) | 58 | ) |
59 | 59 | ||
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('/', | |||
86 | ) | 86 | ) |
87 | videosRouter.put('/:id', | 87 | videosRouter.put('/:id', |
88 | authenticate, | 88 | authenticate, |
89 | videosUpdateValidator, | 89 | asyncMiddleware(videosUpdateValidator), |
90 | asyncMiddleware(updateVideoRetryWrapper) | 90 | asyncMiddleware(updateVideoRetryWrapper) |
91 | ) | 91 | ) |
92 | videosRouter.post('/upload', | 92 | videosRouter.post('/upload', |
@@ -97,17 +97,17 @@ videosRouter.post('/upload', | |||
97 | ) | 97 | ) |
98 | 98 | ||
99 | videosRouter.get('/:id/description', | 99 | videosRouter.get('/:id/description', |
100 | videosGetValidator, | 100 | asyncMiddleware(videosGetValidator), |
101 | asyncMiddleware(getVideoDescription) | 101 | asyncMiddleware(getVideoDescription) |
102 | ) | 102 | ) |
103 | videosRouter.get('/:id', | 103 | videosRouter.get('/:id', |
104 | videosGetValidator, | 104 | asyncMiddleware(videosGetValidator), |
105 | getVideo | 105 | getVideo |
106 | ) | 106 | ) |
107 | 107 | ||
108 | videosRouter.delete('/:id', | 108 | videosRouter.delete('/:id', |
109 | authenticate, | 109 | authenticate, |
110 | videosRemoveValidator, | 110 | asyncMiddleware(videosRemoveValidator), |
111 | asyncMiddleware(removeVideoRetryWrapper) | 111 | asyncMiddleware(removeVideoRetryWrapper) |
112 | ) | 112 | ) |
113 | 113 | ||
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() | |||
12 | 12 | ||
13 | rateVideoRouter.put('/:id/rate', | 13 | rateVideoRouter.put('/:id/rate', |
14 | authenticate, | 14 | authenticate, |
15 | videoRateValidator, | 15 | asyncMiddleware(videoRateValidator), |
16 | asyncMiddleware(rateVideoRetryWrapper) | 16 | asyncMiddleware(rateVideoRetryWrapper) |
17 | ) | 17 | ) |
18 | 18 | ||
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 @@ | |||
1 | import * as express from 'express' | 1 | import * as express from 'express' |
2 | 2 | ||
3 | import { CONFIG, PREVIEWS_SIZE, EMBED_SIZE } from '../initializers' | 3 | import { CONFIG, EMBED_SIZE, PREVIEWS_SIZE } from '../initializers' |
4 | import { oembedValidator } from '../middlewares' | 4 | import { oembedValidator } from '../middlewares' |
5 | import { asyncMiddleware } from '../middlewares/async' | ||
5 | import { VideoInstance } from '../models' | 6 | import { VideoInstance } from '../models' |
6 | 7 | ||
7 | const servicesRouter = express.Router() | 8 | const servicesRouter = express.Router() |
8 | 9 | ||
9 | servicesRouter.use('/oembed', oembedValidator, generateOEmbed) | 10 | servicesRouter.use('/oembed', |
11 | asyncMiddleware(oembedValidator), | ||
12 | generateOEmbed | ||
13 | ) | ||
10 | 14 | ||
11 | // --------------------------------------------------------------------------- | 15 | // --------------------------------------------------------------------------- |
12 | 16 | ||
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 @@ | |||
1 | import * as express from 'express' | 1 | import * as express from 'express' |
2 | import { asyncMiddleware } from '../middlewares/async' | ||
2 | import { webfingerValidator } from '../middlewares/validators/webfinger' | 3 | import { webfingerValidator } from '../middlewares/validators/webfinger' |
3 | import { AccountInstance } from '../models/account/account-interface' | 4 | import { AccountInstance } from '../models/account/account-interface' |
4 | 5 | ||
5 | const webfingerRouter = express.Router() | 6 | const webfingerRouter = express.Router() |
6 | 7 | ||
7 | webfingerRouter.get('/.well-known/webfinger', | 8 | webfingerRouter.get('/.well-known/webfinger', |
8 | webfingerValidator, | 9 | asyncMiddleware(webfingerValidator), |
9 | webfingerController | 10 | webfingerController |
10 | ) | 11 | ) |
11 | 12 | ||