2023-01-13 20:39:07 +00:00
|
|
|
import { Maybe } from '@apextoaster/js-utils';
|
|
|
|
|
2023-01-16 20:10:15 +00:00
|
|
|
import { Img2ImgParams, InpaintParams, OutpaintParams, STATUS_SUCCESS, Txt2ImgParams, UpscaleParams } from './client.js';
|
2023-01-06 16:52:42 +00:00
|
|
|
|
2023-01-10 04:59:08 +00:00
|
|
|
export interface ConfigNumber {
|
2023-01-08 20:25:25 +00:00
|
|
|
default: number;
|
|
|
|
min: number;
|
|
|
|
max: number;
|
|
|
|
step: number;
|
|
|
|
}
|
|
|
|
|
2023-01-10 04:59:08 +00:00
|
|
|
export interface ConfigString {
|
|
|
|
default: string;
|
|
|
|
keys: Array<string>;
|
|
|
|
}
|
|
|
|
|
2023-01-13 20:39:07 +00:00
|
|
|
export type KeyFilter<T extends object, TValid = number | string> = {
|
|
|
|
[K in keyof T]: T[K] extends TValid ? K : never;
|
2023-01-08 20:25:25 +00:00
|
|
|
}[keyof T];
|
|
|
|
|
2023-01-13 20:39:07 +00:00
|
|
|
export type ConfigFiles<T extends object> = {
|
|
|
|
[K in KeyFilter<T, Blob | File>]: Maybe<T[K]>;
|
|
|
|
};
|
|
|
|
|
2023-01-08 20:25:25 +00:00
|
|
|
export type ConfigRanges<T extends object> = {
|
2023-01-10 04:59:08 +00:00
|
|
|
[K in KeyFilter<T>]: T[K] extends number ? ConfigNumber : T[K] extends string ? ConfigString : never;
|
2023-01-08 20:25:25 +00:00
|
|
|
};
|
|
|
|
|
2023-01-13 20:39:07 +00:00
|
|
|
export type ConfigState<T extends object, TValid = number | string> = {
|
|
|
|
[K in KeyFilter<T, TValid>]: T[K] extends TValid ? T[K] : never;
|
2023-01-11 02:43:14 +00:00
|
|
|
};
|
|
|
|
|
2023-01-16 20:05:04 +00:00
|
|
|
export type ConfigParams = ConfigRanges<Required<Img2ImgParams & Txt2ImgParams & InpaintParams & OutpaintParams & UpscaleParams>>;
|
2023-01-10 04:59:08 +00:00
|
|
|
|
|
|
|
export interface Config {
|
|
|
|
api: {
|
|
|
|
root: string;
|
|
|
|
};
|
|
|
|
params: {
|
|
|
|
model: ConfigString;
|
|
|
|
platform: ConfigString;
|
|
|
|
scheduler: ConfigString;
|
|
|
|
prompt: ConfigString;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2023-01-10 05:26:01 +00:00
|
|
|
export const DEFAULT_BRUSH = {
|
|
|
|
color: 255,
|
|
|
|
size: 8,
|
|
|
|
};
|
2023-01-09 04:15:58 +00:00
|
|
|
export const IMAGE_FILTER = '.bmp, .jpg, .jpeg, .png';
|
2023-01-13 03:12:20 +00:00
|
|
|
export const STALE_TIME = 300_000; // 5 minutes
|
|
|
|
export const POLL_TIME = 5_000; // 5 seconds
|
2023-01-13 20:39:07 +00:00
|
|
|
export const SAVE_TIME = 5_000; // 5 seconds
|
2023-01-10 04:59:08 +00:00
|
|
|
|
|
|
|
export async function loadConfig(): Promise<Config> {
|
2023-01-14 00:29:14 +00:00
|
|
|
const configPath = new URL('./config.json', window.location.href);
|
2023-01-10 04:59:08 +00:00
|
|
|
const configReq = await fetch(configPath);
|
|
|
|
if (configReq.status === STATUS_SUCCESS) {
|
|
|
|
return configReq.json();
|
|
|
|
} else {
|
|
|
|
throw new Error('could not load config');
|
|
|
|
}
|
|
|
|
}
|