forked from pinks/eris
1
0
Fork 0
eris/app/config.ts

46 lines
1.3 KiB
TypeScript
Raw Normal View History

import { Static, t } from "elysia";
import { Tkv } from "../utils/Tkv.ts";
2023-09-22 02:59:22 +00:00
import { db } from "./db.ts";
export const defaultParamsSchema = t.Partial(t.Object({
batch_size: t.Number(),
n_iter: t.Number(),
width: t.Number(),
height: t.Number(),
steps: t.Number(),
cfg_scale: t.Number(),
sampler_name: t.String(),
negative_prompt: t.String(),
}));
export type DefaultParams = Static<typeof defaultParamsSchema>;
export const configSchema = t.Object({
pausedReason: t.Nullable(t.String()),
maxUserJobs: t.Number(),
maxJobs: t.Number(),
defaultParams: defaultParamsSchema,
});
export type Config = Static<typeof configSchema>;
export const configStore = new Tkv<["config"], Config>(db);
const defaultConfig: Config = {
pausedReason: null,
maxUserJobs: Infinity,
maxJobs: Infinity,
defaultParams: {},
};
2023-09-22 02:59:22 +00:00
2023-10-05 09:00:51 +00:00
export async function getConfig(): Promise<Config> {
const configEntry = await configStore.get(["config"]);
return { ...defaultConfig, ...configEntry.value };
2023-09-22 02:59:22 +00:00
}
export async function setConfig<K extends keyof Config>(newConfig: Pick<Config, K>): Promise<void> {
const configEntry = await configStore.get(["config"]);
const config = { ...defaultConfig, ...configEntry.value, ...newConfig };
await configStore.atomicSet(["config"], configEntry.versionstamp, config);
2023-09-22 02:59:22 +00:00
}