Fix crash when trying to comment

This commit is contained in:
Shadowfacts 2019-06-29 22:38:47 -04:00
parent 08b936980f
commit b44a37de5a
Signed by untrusted user: shadowfacts
GPG Key ID: 94A5AB95422746E5
1 changed files with 14 additions and 10 deletions

View File

@ -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<Actor> {
export async function getCachedActor(url: string, db: Database): Promise<Actor | null> {
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<Actor>
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);
}
}
});
});