class RgthreeApi { private baseUrl: string; getCheckpointsPromise: Promise | null = null; getSamplersPromise: Promise | null = null; getSchedulersPromise: Promise | null = null; getLorasPromise: Promise | null = null; getWorkflowsPromise: Promise | null = null; constructor(baseUrl?: string) { this.baseUrl = baseUrl || './rgthree/api'; } apiURL(route: string) { return `${this.baseUrl}${route}`; } fetchApi(route: string, options?: RequestInit) { return fetch(this.apiURL(route), options); } async fetchJson(route: string, options?: RequestInit) { const r = await this.fetchApi(route, options); return await r.json(); } async postJson(route: string, json: any) { const body = new FormData(); body.append("json", JSON.stringify(json)); return await rgthreeApi.fetchJson(route, { method: "POST", body }); } getLoras(force = false) { if (!this.getLorasPromise || force) { this.getLorasPromise = this.fetchJson("/loras", { cache: "no-store" }); } return this.getLorasPromise; } } export const rgthreeApi = new RgthreeApi();