mirror of
https://iceshrimp.dev/crimekillz/iceshrimp-161sh.git
synced 2024-11-24 04:59:06 +01:00
29 lines
771 B
TypeScript
29 lines
771 B
TypeScript
import { createSystemUser } from "./create-system-user.js";
|
|
import type { ILocalUser } from "@/models/entities/user.js";
|
|
import { Users } from "@/models/index.js";
|
|
import { Cache } from "@/misc/cache.js";
|
|
import { IsNull } from "typeorm";
|
|
|
|
const ACTOR_USERNAME = "instance.actor" as const;
|
|
|
|
const cache = new Cache<ILocalUser>(Infinity);
|
|
|
|
export async function getInstanceActor(): Promise<ILocalUser> {
|
|
const cached = cache.get(null);
|
|
if (cached) return cached;
|
|
|
|
const user = (await Users.findOneBy({
|
|
host: IsNull(),
|
|
username: ACTOR_USERNAME,
|
|
})) as ILocalUser | undefined;
|
|
|
|
if (user) {
|
|
cache.set(null, user);
|
|
return user;
|
|
} else {
|
|
const created = (await createSystemUser(ACTOR_USERNAME)) as ILocalUser;
|
|
cache.set(null, created);
|
|
return created;
|
|
}
|
|
}
|