Improve handling of deleted actors
This commit is contained in:
parent
77ee132983
commit
4d48f64f2c
|
@ -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<ActorObject | null> {
|
|||
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);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue