import { Maybe } from '@apextoaster/js-utils'; import { Img2ImgParams, InpaintParams, ModelParams, OutpaintParams, STATUS_SUCCESS, Txt2ImgParams, UpscaleParams } from './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 TValid ? K : never; }[keyof T]; export type ConfigFiles = { [K in KeyFilter]: Maybe; }; 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 TValid ? T[K] : never; }; /* eslint-disable */ export type ConfigParams = ConfigRanges>; /* eslint-enable */ 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 const SAVE_TIME = 5_000; // 5 seconds export async function loadConfig(): Promise { const configPath = new URL('./config.json', window.location.href); const configReq = await fetch(configPath); if (configReq.status === STATUS_SUCCESS) { return configReq.json(); } else { throw new Error('could not load config'); } }