rudeshark.net/packages/backend/src/misc/keypair-store.ts

15 lines
466 B
TypeScript
Raw Normal View History

2023-01-13 05:40:33 +01:00
import { UserKeypairs } from "@/models/index.js";
import type { User } from "@/models/entities/user.js";
import type { UserKeypair } from "@/models/entities/user-keypair.js";
import { Cache } from "./cache.js";
2021-03-22 07:14:54 +01:00
2023-07-03 04:10:33 +02:00
const cache = new Cache<UserKeypair>("keypairStore", 60 * 30);
2021-03-22 07:14:54 +01:00
2023-01-13 05:40:33 +01:00
export async function getUserKeypair(userId: User["id"]): Promise<UserKeypair> {
2023-07-03 04:10:33 +02:00
return await cache.fetch(
userId,
() => UserKeypairs.findOneByOrFail({ userId: userId }),
true,
2023-01-13 05:40:33 +01:00
);
2021-03-22 07:14:54 +01:00
}