]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/middlewares/activitypub.ts
Misc cleanup
[github/Chocobozzz/PeerTube.git] / server / middlewares / activitypub.ts
index 8e8a3961b3c5f70c7ef077dac7b54b546cad5022..061b2dddc432d4ec156f47b04be688832e29a3a8 100644 (file)
@@ -2,9 +2,9 @@ import { eachSeries } from 'async'
 import { NextFunction, Request, RequestHandler, Response } from 'express'
 import { ActivityPubSignature } from '../../shared'
 import { isSignatureVerified, logger } from '../helpers'
-import { fetchRemoteAccountAndCreateServer } from '../helpers/activitypub'
 import { database as db } from '../initializers'
 import { ACTIVITY_PUB } from '../initializers/constants'
+import { fetchRemoteAccount, saveAccountAndServerIfNotExist } from '../lib/activitypub/account'
 
 async function checkSignature (req: Request, res: Response, next: NextFunction) {
   const signatureObject: ActivityPubSignature = req.body.signature
@@ -15,15 +15,14 @@ async function checkSignature (req: Request, res: Response, next: NextFunction)
 
   // We don't have this account in our database, fetch it on remote
   if (!account) {
-    const accountResult = await fetchRemoteAccountAndCreateServer(signatureObject.creator)
+    account = await fetchRemoteAccount(signatureObject.creator)
 
-    if (!accountResult) {
+    if (!account) {
       return res.sendStatus(403)
     }
 
-    // Save our new account in database
-    account = accountResult.account
-    await account.save()
+    // Save our new account and its server in database
+    await saveAccountAndServerIfNotExist(account)
   }
 
   const verified = await isSignatureVerified(account, req.body)