Files
FrozenFriendsYume/packages/backend/built/services/instance-actor.js
T
2026-07-26 18:25:37 +09:00

23 lines
723 B
JavaScript

import { createSystemUser } from "./create-system-user.js";
import { Users } from "../models/index.js";
import { Cache } from "../misc/cache.js";
import { IsNull } from "typeorm";
const ACTOR_USERNAME = "instance.actor";
const cache = new Cache("instanceActor", 60 * 30);
export async function getInstanceActor() {
const cached = await cache.get(null, true);
if (cached) return cached;
const user = await Users.findOneBy({
host: IsNull(),
username: ACTOR_USERNAME
});
if (user) {
await cache.set(null, user);
return user;
} else {
const created = await createSystemUser(ACTOR_USERNAME);
await cache.set(null, created);
return created;
}
}