diff options
Diffstat (limited to 'server/middlewares/activitypub.ts')
-rw-r--r-- | server/middlewares/activitypub.ts | 11 |
1 files changed, 5 insertions, 6 deletions
diff --git a/server/middlewares/activitypub.ts b/server/middlewares/activitypub.ts index 29bec0c97..061b2dddc 100644 --- a/server/middlewares/activitypub.ts +++ b/server/middlewares/activitypub.ts | |||
@@ -4,7 +4,7 @@ import { ActivityPubSignature } from '../../shared' | |||
4 | import { isSignatureVerified, logger } from '../helpers' | 4 | import { isSignatureVerified, logger } from '../helpers' |
5 | import { database as db } from '../initializers' | 5 | import { database as db } from '../initializers' |
6 | import { ACTIVITY_PUB } from '../initializers/constants' | 6 | import { ACTIVITY_PUB } from '../initializers/constants' |
7 | import { fetchRemoteAccountAndCreateServer } from '../lib/activitypub/account' | 7 | import { fetchRemoteAccount, saveAccountAndServerIfNotExist } from '../lib/activitypub/account' |
8 | 8 | ||
9 | async function checkSignature (req: Request, res: Response, next: NextFunction) { | 9 | async function checkSignature (req: Request, res: Response, next: NextFunction) { |
10 | const signatureObject: ActivityPubSignature = req.body.signature | 10 | const signatureObject: ActivityPubSignature = req.body.signature |
@@ -15,15 +15,14 @@ async function checkSignature (req: Request, res: Response, next: NextFunction) | |||
15 | 15 | ||
16 | // We don't have this account in our database, fetch it on remote | 16 | // We don't have this account in our database, fetch it on remote |
17 | if (!account) { | 17 | if (!account) { |
18 | const accountResult = await fetchRemoteAccountAndCreateServer(signatureObject.creator) | 18 | account = await fetchRemoteAccount(signatureObject.creator) |
19 | 19 | ||
20 | if (!accountResult) { | 20 | if (!account) { |
21 | return res.sendStatus(403) | 21 | return res.sendStatus(403) |
22 | } | 22 | } |
23 | 23 | ||
24 | // Save our new account in database | 24 | // Save our new account and its server in database |
25 | account = accountResult.account | 25 | await saveAccountAndServerIfNotExist(account) |
26 | await account.save() | ||
27 | } | 26 | } |
28 | 27 | ||
29 | const verified = await isSignatureVerified(account, req.body) | 28 | const verified = await isSignatureVerified(account, req.body) |