import { Img2ImgParams, STATUS_SUCCESS, Txt2ImgParams } from './api/client.js'; export interface ConfigNumber { default: number; min: number; max: number; step: number; } export interface ConfigString { default: string; keys: Array; } export type KeyFilter = { [K in keyof T]: T[K] extends number ? K : T[K] extends string ? K : never; }[keyof T]; export type ConfigRanges = { [K in KeyFilter]: T[K] extends number ? ConfigNumber : T[K] extends string ? ConfigString : never; }; export type ConfigState = { [K in KeyFilter]: T[K] extends number ? number : T[K] extends string ? string : never; }; export type ConfigParams = ConfigRanges>; export interface Config { api: { root: string; }; params: { model: ConfigString; platform: ConfigString; scheduler: ConfigString; prompt: ConfigString; }; } export const DEFAULT_BRUSH = { color: 255, size: 8, }; export const IMAGE_FILTER = '.bmp, .jpg, .jpeg, .png'; export const STALE_TIME = 300_000; // 5 minutes export const POLL_TIME = 5_000; // 5 seconds export async function loadConfig(): Promise { const configPath = new URL('./config.json', window.origin); const configReq = await fetch(configPath); if (configReq.status === STATUS_SUCCESS) { return configReq.json(); } else { throw new Error('could not load config'); } }