Image input

This commit is contained in:
Ian Gulliver
2026-10-14 20:07:26 -07:00
parent bd8702ee87
commit 9e741ede32
27 changed files with 1044 additions and 122 deletions
+9 -2
View File
@@ -23,7 +23,11 @@ type Op<P extends keyof paths, M extends Method> = NonNullable<paths[P][M]>;
type Params<O> = O extends { parameters: infer X } ? X : never;
type PathParams<O> = Params<O> extends { path: infer X } ? X : never;
type QueryParams<O> = Params<O> extends { query?: infer X } ? X : never;
type Body<O> = O extends { requestBody: { content: { "application/json": infer B } } } ? B : never;
type Body<O> = O extends { requestBody: { content: { "application/json": infer B } } }
? B
: O extends { requestBody: { content: Record<`image/${string}`, unknown> } }
? Blob
: never;
type Success<O> = O extends { responses: infer R } ? R[Extract<keyof R, 200 | 201 | 202>] : never;
type Result<O> = Success<O> extends { content: { "application/json": infer J } } ? J : never;
@@ -64,7 +68,10 @@ export async function request<M extends Method, P extends PathsWith<M>>(
}
const init: RequestInit = { method: method.toUpperCase() };
if (opts.body !== undefined) {
if (opts.body instanceof Blob) {
init.headers = { "Content-Type": opts.body.type || "application/octet-stream" };
init.body = opts.body;
} else if (opts.body !== undefined) {
init.headers = { "Content-Type": "application/json" };
init.body = JSON.stringify(opts.body);
}