aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/middlewares/activitypub.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/middlewares/activitypub.ts')
-rw-r--r--server/middlewares/activitypub.ts11
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'
4import { isSignatureVerified, logger } from '../helpers' 4import { isSignatureVerified, logger } from '../helpers'
5import { database as db } from '../initializers' 5import { database as db } from '../initializers'
6import { ACTIVITY_PUB } from '../initializers/constants' 6import { ACTIVITY_PUB } from '../initializers/constants'
7import { fetchRemoteAccountAndCreateServer } from '../lib/activitypub/account' 7import { fetchRemoteAccount, saveAccountAndServerIfNotExist } from '../lib/activitypub/account'
8 8
9async function checkSignature (req: Request, res: Response, next: NextFunction) { 9async 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)