Download ui/src/api.ts from Kazzze/sd-anatomy-fix: direct link, hf CLI and curl.
- Browser
- Download file 2.49 kB
-
https://huggingface.co/Kazzze/sd-anatomy-fix/resolve/main/ui/src/api.ts
- Command line
-
hf download hf://Kazzze/sd-anatomy-fix/ui/src/api.ts
-
curl -L -o api.ts https://huggingface.co/Kazzze/sd-anatomy-fix/resolve/main/ui/src/api.ts
2.49 kB
| import type { BoneItem, DraftInfo, Job, Line, Model, Options, Prompts, RunState, SessionInfo, Settings } from './types' | |
| const BASE = '/anatomy_fix' | |
| async function unwrap<T>(response: Response): Promise<T> { | |
| let body: unknown = null | |
| try { | |
| body = await response.json() | |
| } catch { | |
| // not JSON: the status text has to do | |
| } | |
| if (!response.ok) { | |
| const message = body && typeof body === 'object' && 'error' in body ? String((body as { error: unknown }).error) : '' | |
| throw new Error(message || `${response.status} ${response.statusText}`) | |
| } | |
| return body as T | |
| } | |
| function post<T>(path: string, body: unknown): Promise<T> { | |
| return fetch(BASE + path, { | |
| method: 'POST', | |
| headers: { 'Content-Type': 'application/json' }, | |
| body: JSON.stringify(body), | |
| }).then((response) => unwrap<T>(response)) | |
| } | |
| export type ImageWhich = 'image' | 'draft' | 'levels' | 'guide' | 'result' | `variant-${number}` | |
| export const api = { | |
| options: () => fetch(`${BASE}/options`).then((response) => unwrap<Options>(response)), | |
| upload: (file: Blob, name: string) => | |
| fetch(`${BASE}/session?name=${encodeURIComponent(name)}`, { method: 'POST', body: file }).then((response) => | |
| unwrap<SessionInfo>(response), | |
| ), | |
| /** ComfyUI: the image the node last received. */ | |
| node: (node: string) => post<SessionInfo>('/session/node', { node }), | |
| draft: (session: string, job: Job) => post<DraftInfo>('/draft', { session, job }), | |
| fan: (line: Line, kind: string, thumb: string, spread: number, width: number) => | |
| post<{ bones: Omit<BoneItem, 'id'>[] }>('/fan', { line, kind, thumb, spread, width }), | |
| run: (session: string, job: Job, model: Model & Prompts) => post<RunState>('/run', { session, job, model }), | |
| runState: (session: string) => post<RunState>('/run/state', { session }), | |
| stop: (session: string) => post<RunState>('/run/stop', { session }), | |
| pick: (session: string, seed: number) => post<{ version: number }>('/pick', { session, seed }), | |
| apply: (session: string) => post<SessionInfo>('/apply', { session }), | |
| undo: (session: string) => post<SessionInfo>('/undo', { session }), | |
| save: (session: string, tab: string) => post<{ path: string }>('/save', { session, tab }), | |
| saveSettings: (settings: Settings) => post<{ settings: Settings }>('/settings', settings), | |
| imageUrl: (session: string, which: ImageWhich, version: number) => `${BASE}/image/${session}/${which}?v=${version}`, | |
| } | |