add state config loading logic
This commit is contained in:
parent
39d75031ba
commit
c8afcb43d2
2 changed files with 29 additions and 10 deletions
|
@ -18,16 +18,14 @@ export function parse_container_config(json: string) {
|
|||
name: z.string(),
|
||||
version: z.number(),
|
||||
redirects: z.array(
|
||||
z
|
||||
.tuple([
|
||||
z.number(),
|
||||
z.number(),
|
||||
])
|
||||
.or(z.tuple([
|
||||
z.number(),
|
||||
z.number(),
|
||||
z.literal("tcp").or(z.literal("udp")),
|
||||
])),
|
||||
z.tuple([
|
||||
z.number(),
|
||||
z.number(),
|
||||
]).or(z.tuple([
|
||||
z.number(),
|
||||
z.number(),
|
||||
z.literal("tcp").or(z.literal("udp")),
|
||||
])),
|
||||
),
|
||||
}).parse(JSON.parse(json));
|
||||
}
|
||||
|
@ -57,3 +55,20 @@ export async function load_all_container_configs() {
|
|||
const results = await Promise.all(names.map((name) => load_container_config(name)));
|
||||
return results.filter((item) => item != null) as ContainerConfig[];
|
||||
}
|
||||
|
||||
export type StateConfig = ReturnType<typeof new_config>;
|
||||
export function new_config(app_key: string, app_secret: string, consumer_key: string) {
|
||||
return { app_key, app_secret, consumer_key };
|
||||
}
|
||||
|
||||
export async function load_state_config() {
|
||||
try {
|
||||
const content = await Deno.readTextFile(state_config_path());
|
||||
return JSON.parse(content) as StateConfig;
|
||||
} catch (_) {
|
||||
const result = new_config("APP_KEY", "APP_SECRET", "CONSUMER_KEY");
|
||||
const content = JSON.stringify(result);
|
||||
await Deno.writeTextFile(state_config_path(), content);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -34,3 +34,7 @@ export function base_paths(name: string) {
|
|||
const module = base + "/module.ts";
|
||||
return { base, module };
|
||||
}
|
||||
|
||||
export function state_config_path() {
|
||||
return instance_root_path() + "/local/config.json";
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue