aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/middlewares
diff options
context:
space:
mode:
Diffstat (limited to 'server/middlewares')
-rw-r--r--server/middlewares/activitypub.ts11
-rw-r--r--server/middlewares/validators/follows.ts8
2 files changed, 9 insertions, 10 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)
diff --git a/server/middlewares/validators/follows.ts b/server/middlewares/validators/follows.ts
index dfd6e7f03..ddc4c1de1 100644
--- a/server/middlewares/validators/follows.ts
+++ b/server/middlewares/validators/follows.ts
@@ -31,19 +31,19 @@ const removeFollowingValidator = [
31 param('accountId').custom(isIdOrUUIDValid).withMessage('Should have a valid account id'), 31 param('accountId').custom(isIdOrUUIDValid).withMessage('Should have a valid account id'),
32 32
33 (req: express.Request, res: express.Response, next: express.NextFunction) => { 33 (req: express.Request, res: express.Response, next: express.NextFunction) => {
34 logger.debug('Checking follow parameters', { parameters: req.body }) 34 logger.debug('Checking unfollow parameters', { parameters: req.params })
35 35
36 checkErrors(req, res, async () => { 36 checkErrors(req, res, async () => {
37 try { 37 try {
38 const serverAccount = await getServerAccount() 38 const serverAccount = await getServerAccount()
39 const following = await db.AccountFollow.loadByAccountAndTarget(serverAccount.id, req.params.accountId) 39 const follow = await db.AccountFollow.loadByAccountAndTarget(serverAccount.id, req.params.accountId)
40 40
41 if (!following) { 41 if (!follow) {
42 return res.status(404) 42 return res.status(404)
43 .end() 43 .end()
44 } 44 }
45 45
46 res.locals.following = following 46 res.locals.follow = follow
47 47
48 return next() 48 return next()
49 } catch (err) { 49 } catch (err) {