From b44a37de5a8e9aba8cb0145c78e0a4bb7c58c0c8 Mon Sep 17 00:00:00 2001 From: Shadowfacts Date: Sat, 29 Jun 2019 22:38:47 -0400 Subject: [PATCH] Fix crash when trying to comment --- lib/activitypub/federate.ts | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/lib/activitypub/federate.ts b/lib/activitypub/federate.ts index 9817430..a271cbd 100644 --- a/lib/activitypub/federate.ts +++ b/lib/activitypub/federate.ts @@ -38,7 +38,7 @@ export async function getActor(url: string, db: Database, forceUpdate: boolean = return remote; } -export async function getCachedActor(url: string, db: Database): Promise { +export async function getCachedActor(url: string, db: Database): Promise { return new Promise((resolve, reject) => { db.get("SELECT * FROM actors WHERE id = $id", { $id: url @@ -46,15 +46,19 @@ export async function getCachedActor(url: string, db: Database): Promise if (err) { reject(err); } else { - resolve({ - id: result.id, - name: result.display_name, - inbox: result.inbox, - icon: result.icon_url, - publicKey: { - publicKeyPem: result.public_key_pem - } - } as Actor); + if (result) { + resolve({ + id: result.id, + name: result.display_name, + inbox: result.inbox, + icon: result.icon_url, + publicKey: { + publicKeyPem: result.public_key_pem + } + } as Actor); + } else { + resolve(null); + } } }); });