From b7de3162c33577cf56c99630633bbc4ab461ed6d Mon Sep 17 00:00:00 2001 From: psychedelicious <4822129+psychedelicious@users.noreply.github.com> Date: Tue, 4 Apr 2023 18:30:52 +1000 Subject: [PATCH] chore(ui): regenerate api --- .../web/src/services/api/core/request.ts | 74 ++++++++++++++----- .../frontend/web/src/services/api/index.ts | 2 + .../web/src/services/api/models/ImageField.ts | 4 +- .../models/PaginatedResults_ImageField_.ts | 32 ++++++++ .../src/services/api/schemas/$ImageField.ts | 5 +- .../schemas/$PaginatedResults_ImageField_.ts | 35 +++++++++ .../services/api/services/ImagesService.ts | 39 ++++++++++ 7 files changed, 169 insertions(+), 22 deletions(-) create mode 100644 invokeai/frontend/web/src/services/api/models/PaginatedResults_ImageField_.ts create mode 100644 invokeai/frontend/web/src/services/api/schemas/$PaginatedResults_ImageField_.ts diff --git a/invokeai/frontend/web/src/services/api/core/request.ts b/invokeai/frontend/web/src/services/api/core/request.ts index 990b803e4b..7cf57e96b6 100644 --- a/invokeai/frontend/web/src/services/api/core/request.ts +++ b/invokeai/frontend/web/src/services/api/core/request.ts @@ -4,9 +4,9 @@ /** * Custom `request.ts` file for OpenAPI code generator. - * + * * Patches the request logic in such a way that we can extract headers from requests. - * + * * Copied from https://github.com/ferdikoomen/openapi-typescript-codegen/issues/829#issuecomment-1228224477 */ @@ -21,9 +21,11 @@ import { CancelablePromise } from './CancelablePromise'; import type { OnCancel } from './CancelablePromise'; import type { OpenAPIConfig } from './OpenAPI'; -export const HEADERS = Symbol("HEADERS") +export const HEADERS = Symbol('HEADERS'); -const isDefined = (value: T | null | undefined): value is Exclude => { +const isDefined = ( + value: T | null | undefined +): value is Exclude => { return value !== undefined && value !== null; }; @@ -75,7 +77,7 @@ const getQueryString = (params: Record): string => { const process = (key: string, value: any) => { if (isDefined(value)) { if (Array.isArray(value)) { - value.forEach(v => { + value.forEach((v) => { process(key, v); }); } else if (typeof value === 'object') { @@ -134,7 +136,7 @@ const getFormData = (options: ApiRequestOptions): FormData | undefined => { .filter(([_, value]) => isDefined(value)) .forEach(([key, value]) => { if (Array.isArray(value)) { - value.forEach(v => process(key, v)); + value.forEach((v) => process(key, v)); } else { process(key, value); } @@ -147,19 +149,28 @@ const getFormData = (options: ApiRequestOptions): FormData | undefined => { type Resolver = (options: ApiRequestOptions) => Promise; -const resolve = async (options: ApiRequestOptions, resolver?: T | Resolver): Promise => { +const resolve = async ( + options: ApiRequestOptions, + resolver?: T | Resolver +): Promise => { if (typeof resolver === 'function') { return (resolver as Resolver)(options); } return resolver; }; -const getHeaders = async (config: OpenAPIConfig, options: ApiRequestOptions, formData?: FormData): Promise> => { +const getHeaders = async ( + config: OpenAPIConfig, + options: ApiRequestOptions, + formData?: FormData +): Promise> => { const token = await resolve(options, config.TOKEN); const username = await resolve(options, config.USERNAME); const password = await resolve(options, config.PASSWORD); const additionalHeaders = await resolve(options, config.HEADERS); - const formHeaders = typeof formData?.getHeaders === 'function' && formData?.getHeaders() || {} + const formHeaders = + (typeof formData?.getHeaders === 'function' && formData?.getHeaders()) || + {}; const headers = Object.entries({ Accept: 'application/json', @@ -167,11 +178,14 @@ const getHeaders = async (config: OpenAPIConfig, options: ApiRequestOptions, for ...options.headers, ...formHeaders, }) - .filter(([_, value]) => isDefined(value)) - .reduce((headers, [key, value]) => ({ - ...headers, - [key]: String(value), - }), {} as Record); + .filter(([_, value]) => isDefined(value)) + .reduce( + (headers, [key, value]) => ({ + ...headers, + [key]: String(value), + }), + {} as Record + ); if (isStringWithValue(token)) { headers['Authorization'] = `Bearer ${token}`; @@ -237,7 +251,10 @@ const sendRequest = async ( } }; -const getResponseHeader = (response: AxiosResponse, responseHeader?: string): string | undefined => { +const getResponseHeader = ( + response: AxiosResponse, + responseHeader?: string +): string | undefined => { if (responseHeader) { const content = response.headers[responseHeader]; if (isString(content)) { @@ -254,7 +271,10 @@ const getResponseBody = (response: AxiosResponse): any => { return undefined; }; -const catchErrorCodes = (options: ApiRequestOptions, result: ApiResult): void => { +const catchErrorCodes = ( + options: ApiRequestOptions, + result: ApiResult +): void => { const errors: Record = { 400: 'Bad Request', 401: 'Unauthorized', @@ -264,7 +284,7 @@ const catchErrorCodes = (options: ApiRequestOptions, result: ApiResult): void => 502: 'Bad Gateway', 503: 'Service Unavailable', ...options.errors, - } + }; const error = errors[result.status]; if (error) { @@ -283,7 +303,10 @@ const catchErrorCodes = (options: ApiRequestOptions, result: ApiResult): void => * @returns CancelablePromise * @throws ApiError */ -export const request = (config: OpenAPIConfig, options: ApiRequestOptions): CancelablePromise => { +export const request = ( + config: OpenAPIConfig, + options: ApiRequestOptions +): CancelablePromise => { return new CancelablePromise(async (resolve, reject, onCancel) => { try { const url = getUrl(config, options); @@ -292,9 +315,20 @@ export const request = (config: OpenAPIConfig, options: ApiRequestOptions): C const headers = await getHeaders(config, options, formData); if (!onCancel.isCancelled) { - const response = await sendRequest(config, options, url, body, formData, headers, onCancel); + const response = await sendRequest( + config, + options, + url, + body, + formData, + headers, + onCancel + ); const responseBody = getResponseBody(response); - const responseHeader = getResponseHeader(response, options.responseHeader); + const responseHeader = getResponseHeader( + response, + options.responseHeader + ); const result: ApiResult = { url, diff --git a/invokeai/frontend/web/src/services/api/index.ts b/invokeai/frontend/web/src/services/api/index.ts index d10e0b6624..2dd1d616d8 100644 --- a/invokeai/frontend/web/src/services/api/index.ts +++ b/invokeai/frontend/web/src/services/api/index.ts @@ -32,6 +32,7 @@ export type { LoadImageInvocation } from './models/LoadImageInvocation'; export type { MaskFromAlphaInvocation } from './models/MaskFromAlphaInvocation'; export type { MaskOutput } from './models/MaskOutput'; export type { PaginatedResults_GraphExecutionState_ } from './models/PaginatedResults_GraphExecutionState_'; +export type { PaginatedResults_ImageField_ } from './models/PaginatedResults_ImageField_'; export type { PasteImageInvocation } from './models/PasteImageInvocation'; export type { PromptOutput } from './models/PromptOutput'; export type { RestoreFaceInvocation } from './models/RestoreFaceInvocation'; @@ -66,6 +67,7 @@ export { $LoadImageInvocation } from './schemas/$LoadImageInvocation'; export { $MaskFromAlphaInvocation } from './schemas/$MaskFromAlphaInvocation'; export { $MaskOutput } from './schemas/$MaskOutput'; export { $PaginatedResults_GraphExecutionState_ } from './schemas/$PaginatedResults_GraphExecutionState_'; +export { $PaginatedResults_ImageField_ } from './schemas/$PaginatedResults_ImageField_'; export { $PasteImageInvocation } from './schemas/$PasteImageInvocation'; export { $PromptOutput } from './schemas/$PromptOutput'; export { $RestoreFaceInvocation } from './schemas/$RestoreFaceInvocation'; diff --git a/invokeai/frontend/web/src/services/api/models/ImageField.ts b/invokeai/frontend/web/src/services/api/models/ImageField.ts index fe1485f00d..fa22ae8007 100644 --- a/invokeai/frontend/web/src/services/api/models/ImageField.ts +++ b/invokeai/frontend/web/src/services/api/models/ImageField.ts @@ -2,6 +2,8 @@ /* tslint:disable */ /* eslint-disable */ +import type { ImageType } from './ImageType'; + /** * An image field used for passing image objects between invocations */ @@ -9,7 +11,7 @@ export type ImageField = { /** * The type of the image */ - image_type: string; + image_type: ImageType; /** * The name of the image */ diff --git a/invokeai/frontend/web/src/services/api/models/PaginatedResults_ImageField_.ts b/invokeai/frontend/web/src/services/api/models/PaginatedResults_ImageField_.ts new file mode 100644 index 0000000000..99f9dfe920 --- /dev/null +++ b/invokeai/frontend/web/src/services/api/models/PaginatedResults_ImageField_.ts @@ -0,0 +1,32 @@ +/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ + +import type { ImageField } from './ImageField'; + +/** + * Paginated results + */ +export type PaginatedResults_ImageField_ = { + /** + * Items + */ + items: Array; + /** + * Current Page + */ + page: number; + /** + * Total number of pages + */ + pages: number; + /** + * Number of items per page + */ + per_page: number; + /** + * Total number of items in result + */ + total: number; +}; + diff --git a/invokeai/frontend/web/src/services/api/schemas/$ImageField.ts b/invokeai/frontend/web/src/services/api/schemas/$ImageField.ts index aefb6c0807..968ac29a45 100644 --- a/invokeai/frontend/web/src/services/api/schemas/$ImageField.ts +++ b/invokeai/frontend/web/src/services/api/schemas/$ImageField.ts @@ -5,8 +5,11 @@ export const $ImageField = { description: `An image field used for passing image objects between invocations`, properties: { image_type: { - type: 'string', + type: 'all-of', description: `The type of the image`, + contains: [{ + type: 'ImageType', + }], isRequired: true, }, image_name: { diff --git a/invokeai/frontend/web/src/services/api/schemas/$PaginatedResults_ImageField_.ts b/invokeai/frontend/web/src/services/api/schemas/$PaginatedResults_ImageField_.ts new file mode 100644 index 0000000000..688e3745f2 --- /dev/null +++ b/invokeai/frontend/web/src/services/api/schemas/$PaginatedResults_ImageField_.ts @@ -0,0 +1,35 @@ +/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ +export const $PaginatedResults_ImageField_ = { + description: `Paginated results`, + properties: { + items: { + type: 'array', + contains: { + type: 'ImageField', + }, + isRequired: true, + }, + page: { + type: 'number', + description: `Current Page`, + isRequired: true, + }, + pages: { + type: 'number', + description: `Total number of pages`, + isRequired: true, + }, + per_page: { + type: 'number', + description: `Number of items per page`, + isRequired: true, + }, + total: { + type: 'number', + description: `Total number of items in result`, + isRequired: true, + }, + }, +} as const; diff --git a/invokeai/frontend/web/src/services/api/services/ImagesService.ts b/invokeai/frontend/web/src/services/api/services/ImagesService.ts index d0108dbce6..9a5b2cedea 100644 --- a/invokeai/frontend/web/src/services/api/services/ImagesService.ts +++ b/invokeai/frontend/web/src/services/api/services/ImagesService.ts @@ -3,6 +3,7 @@ /* eslint-disable */ import type { Body_upload_image } from '../models/Body_upload_image'; import type { ImageType } from '../models/ImageType'; +import type { PaginatedResults_ImageField_ } from '../models/PaginatedResults_ImageField_'; import type { CancelablePromise } from '../core/CancelablePromise'; import { OpenAPI } from '../core/OpenAPI'; @@ -96,4 +97,42 @@ export class ImagesService { }); } + /** + * List Images + * Gets a list of images + * @returns PaginatedResults_ImageField_ Successful Response + * @throws ApiError + */ + public static listImages({ + imageType, + page, + perPage = 10, + }: { + /** + * The type of images to get + */ + imageType?: ImageType, + /** + * The page of images to get + */ + page?: number, + /** + * The number of images per page + */ + perPage?: number, + }): CancelablePromise { + return __request(OpenAPI, { + method: 'GET', + url: '/api/v1/images/', + query: { + 'image_type': imageType, + 'page': page, + 'per_page': perPage, + }, + errors: { + 422: `Validation Error`, + }, + }); + } + }