]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/lib/activitypub/actor.ts
Add ability to cleanup remote AP interactions
[github/Chocobozzz/PeerTube.git] / server / lib / activitypub / actor.ts
index 086d656f9c975c0a61dcf589348910c912f96956..a726f9e209d0093f8510bec3cad4cd1ecbb1f2ae 100644 (file)
@@ -39,17 +39,13 @@ import { getServerActor } from '@server/models/application/application'
 import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes'
 
 // Set account keys, this could be long so process after the account creation and do not block the client
-function setAsyncActorKeys <T extends MActor> (actor: T) {
-  return createPrivateAndPublicKeys()
-    .then(({ publicKey, privateKey }) => {
-      actor.publicKey = publicKey
-      actor.privateKey = privateKey
-      return actor.save()
-    })
-    .catch(err => {
-      logger.error('Cannot set public/private keys of actor %d.', actor.url, { err })
-      return actor
-    })
+async function generateAndSaveActorKeys <T extends MActor> (actor: T) {
+  const { publicKey, privateKey } = await createPrivateAndPublicKeys()
+
+  actor.publicKey = publicKey
+  actor.privateKey = privateKey
+
+  return actor.save()
 }
 
 function getOrCreateActorAndServerAndModel (
@@ -104,7 +100,7 @@ async function getOrCreateActorAndServerAndModel (
         const recurseIfNeeded = false
         ownerActor = await getOrCreateActorAndServerAndModel(accountAttributedTo.id, 'all', recurseIfNeeded)
       } catch (err) {
-        logger.error('Cannot get or create account attributed to video channel ' + actor.url)
+        logger.error('Cannot get or create account attributed to video channel ' + actorUrl)
         throw new Error(err)
       }
     }
@@ -346,7 +342,7 @@ async function refreshActorIfNeeded <T extends MActorFull | MActorAccountChannel
 export {
   getOrCreateActorAndServerAndModel,
   buildActorInstance,
-  setAsyncActorKeys,
+  generateAndSaveActorKeys,
   fetchActorTotalItems,
   getAvatarInfoIfExists,
   updateActorInstance,