From 4d48f64f2ca7e21e430c1ee3497d8d6542947d36 Mon Sep 17 00:00:00 2001 From: Shadowfacts Date: Wed, 15 Apr 2020 14:15:37 -0400 Subject: [PATCH] Improve handling of deleted actors --- lib/activitypub/federate.ts | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/lib/activitypub/federate.ts b/lib/activitypub/federate.ts index 3746f4b..a26616e 100644 --- a/lib/activitypub/federate.ts +++ b/lib/activitypub/federate.ts @@ -13,6 +13,7 @@ import { URL } from "url"; import { getConnection } from "typeorm"; import Actor from "../entity/Actor"; import Article from "../entity/Article"; +import Note from "../entity/Note"; const domain = process.env.DOMAIN; @@ -42,7 +43,20 @@ export async function getActor(url: string, forceUpdate: boolean = false): Promi } } const remote = await fetchActor(url); - if (remote) cacheActor(remote); + if (remote) { + cacheActor(remote); + } else { + getConnection().createQueryBuilder() + .delete() + .from(Actor, "actor") + .where("actor.id = :id", { id: url }) + .execute(); + getConnection().createQueryBuilder() + .delete() + .from(Note, "note") + .where("note.\"actorId\" = :actor", { actor: url }) + .execute(); + } return remote; } @@ -88,7 +102,8 @@ async function fetchActor(url?: string): Promise { json: true }, (err, res) => { if (err) reject(err); - else resolve(res.body && res.body instanceof Object ? res.body as ActorObject : null); + else if (!res.body || res.body.error || Object.keys(res.body).length === 0) resolve(null); + else resolve(res.body as ActorObject); }); }); }