diff options
Diffstat (limited to 'server/middlewares')
-rw-r--r-- | server/middlewares/activitypub.ts | 26 |
1 files changed, 9 insertions, 17 deletions
diff --git a/server/middlewares/activitypub.ts b/server/middlewares/activitypub.ts index 01e5dd24e..5fa10cbfd 100644 --- a/server/middlewares/activitypub.ts +++ b/server/middlewares/activitypub.ts | |||
@@ -1,5 +1,4 @@ | |||
1 | import { eachSeries } from 'async' | 1 | import { NextFunction, Request, Response } from 'express' |
2 | import { NextFunction, Request, RequestHandler, Response } from 'express' | ||
3 | import { ActivityPubSignature } from '../../shared' | 2 | import { ActivityPubSignature } from '../../shared' |
4 | import { logger } from '../helpers/logger' | 3 | import { logger } from '../helpers/logger' |
5 | import { isHTTPSignatureVerified, isJsonLDSignatureVerified, parseHTTPSignature } from '../helpers/peertube-crypto' | 4 | import { isHTTPSignatureVerified, isJsonLDSignatureVerified, parseHTTPSignature } from '../helpers/peertube-crypto' |
@@ -30,23 +29,16 @@ async function checkSignature (req: Request, res: Response, next: NextFunction) | |||
30 | } | 29 | } |
31 | } | 30 | } |
32 | 31 | ||
33 | function executeIfActivityPub (fun: RequestHandler | RequestHandler[]) { | 32 | function executeIfActivityPub (req: Request, res: Response, next: NextFunction) { |
34 | return (req: Request, res: Response, next: NextFunction) => { | 33 | const accepted = req.accepts(ACCEPT_HEADERS) |
35 | const accepted = req.accepts(ACCEPT_HEADERS) | 34 | if (accepted === false || ACTIVITY_PUB.POTENTIAL_ACCEPT_HEADERS.indexOf(accepted) === -1) { |
36 | if (accepted === false || ACTIVITY_PUB.POTENTIAL_ACCEPT_HEADERS.indexOf(accepted) === -1) { | 35 | // Bypass this route |
37 | return next() | 36 | return next('route') |
38 | } | 37 | } |
39 | 38 | ||
40 | logger.debug('ActivityPub request for %s.', req.url) | 39 | logger.debug('ActivityPub request for %s.', req.url) |
41 | 40 | ||
42 | if (Array.isArray(fun) === true) { | 41 | return next() |
43 | return eachSeries(fun as RequestHandler[], (f, cb) => { | ||
44 | f(req, res, cb) | ||
45 | }, next) | ||
46 | } | ||
47 | |||
48 | return (fun as RequestHandler)(req, res, next) | ||
49 | } | ||
50 | } | 42 | } |
51 | 43 | ||
52 | // --------------------------------------------------------------------------- | 44 | // --------------------------------------------------------------------------- |