From 0a7d06f8c614b42c8c70617d36c4340171c09f24 Mon Sep 17 00:00:00 2001 From: psychedelicious <4822129+psychedelicious@users.noreply.github.com> Date: Sat, 2 Sep 2023 11:26:48 +1000 Subject: [PATCH 1/3] fix(ui): fix circular imports The logic that introduced a circular import was actually extraneous. I have entirely removed it. --- .../web/src/features/nodes/types/types.ts | 15 +-------------- 1 file changed, 1 insertion(+), 14 deletions(-) diff --git a/invokeai/frontend/web/src/features/nodes/types/types.ts b/invokeai/frontend/web/src/features/nodes/types/types.ts index 7783393d6f..a2de44cb38 100644 --- a/invokeai/frontend/web/src/features/nodes/types/types.ts +++ b/invokeai/frontend/web/src/features/nodes/types/types.ts @@ -1,4 +1,3 @@ -import { store } from 'app/store/store'; import { SchedulerParam, zBaseModel, @@ -10,7 +9,6 @@ import { keyBy } from 'lodash-es'; import { OpenAPIV3 } from 'openapi-types'; import { RgbaColor } from 'react-colorful'; import { Node } from 'reactflow'; -import { JsonObject } from 'type-fest'; import { Graph, ImageDTO, _InputField, _OutputField } from 'services/api/types'; import { AnyInvocationType, @@ -18,6 +16,7 @@ import { ProgressImage, } from 'services/events/types'; import { O } from 'ts-toolbelt'; +import { JsonObject } from 'type-fest'; import { z } from 'zod'; export type NonNullableGraph = O.Required; @@ -936,22 +935,10 @@ export const zWorkflow = z.object({ }); export const zValidatedWorkflow = zWorkflow.transform((workflow) => { - const nodeTemplates = store.getState().nodes.nodeTemplates; const { nodes, edges } = workflow; const warnings: WorkflowWarning[] = []; const invocationNodes = nodes.filter(isWorkflowInvocationNode); const keyedNodes = keyBy(invocationNodes, 'id'); - invocationNodes.forEach((node, i) => { - const nodeTemplate = nodeTemplates[node.data.type]; - if (!nodeTemplate) { - warnings.push({ - message: `Node "${node.data.label || node.data.id}" skipped`, - issues: [`Unable to find template for type "${node.data.type}"`], - data: node, - }); - delete nodes[i]; - } - }); edges.forEach((edge, i) => { const sourceNode = keyedNodes[edge.source]; const targetNode = keyedNodes[edge.target]; From f8bb1f7a3e38109937a4f941a299a41415698baa Mon Sep 17 00:00:00 2001 From: Mary Hipp Date: Fri, 1 Sep 2023 13:02:43 -0400 Subject: [PATCH 2/3] update getImageMetadataFromFile query to allow dyanmic URL based on image without using baseUrl for rest of endpoints --- .../web/src/services/api/endpoints/images.ts | 46 ++++++++++++++----- 1 file changed, 35 insertions(+), 11 deletions(-) diff --git a/invokeai/frontend/web/src/services/api/endpoints/images.ts b/invokeai/frontend/web/src/services/api/endpoints/images.ts index 62a9b6611e..6b04864815 100644 --- a/invokeai/frontend/web/src/services/api/endpoints/images.ts +++ b/invokeai/frontend/web/src/services/api/endpoints/images.ts @@ -28,6 +28,8 @@ import { } from '../util'; import { boardsApi } from './boards'; import { ImageMetadataAndWorkflow } from 'features/nodes/types/types'; +import { fetchBaseQuery } from '@reduxjs/toolkit/dist/query'; +import { $authToken, $projectId } from '../client'; export const imagesApi = api.injectEndpoints({ endpoints: (build) => ({ @@ -115,18 +117,40 @@ export const imagesApi = api.injectEndpoints({ ], keepUnusedDataFor: 86400, // 24 hours }), - getImageMetadataFromFile: build.query({ - query: (image_name) => ({ - url: `images/i/${image_name}/full`, - responseHandler: async (res) => { - return await res.blob(); - }, - }), - providesTags: (result, error, image_name) => [ - { type: 'ImageMetadataFromFile', id: image_name }, + getImageMetadataFromFile: build.query({ + queryFn: async (args: ImageDTO, api, extraOptions) => { + const authToken = $authToken.get(); + const projectId = $projectId.get(); + const customBaseQuery = fetchBaseQuery({ + baseUrl: '', + prepareHeaders: (headers) => { + if (authToken) { + headers.set('Authorization', `Bearer ${authToken}`); + } + if (projectId) { + headers.set('project-id', projectId); + } + + return headers; + }, + responseHandler: async (res) => { + return await res.blob(); + }, + }); + + const response = await customBaseQuery( + args.image_url, + api, + extraOptions + ); + const data = await getMetadataAndWorkflowFromImageBlob( + response.data as Blob + ); + return { data }; + }, + providesTags: (result, error, image_dto) => [ + { type: 'ImageMetadataFromFile', id: image_dto.image_name }, ], - transformResponse: (response: Blob) => - getMetadataAndWorkflowFromImageBlob(response), keepUnusedDataFor: 86400, // 24 hours }), clearIntermediates: build.mutation({ From ec2b44bfbd51e0a153c2bc709239d65499756218 Mon Sep 17 00:00:00 2001 From: Mary Hipp Date: Fri, 1 Sep 2023 13:03:06 -0400 Subject: [PATCH 3/3] update hooks to pass in DTO --- .../CurrentImage/CurrentImageButtons.tsx | 2 +- .../ImageContextMenu/SingleSelectionMenuItems.tsx | 2 +- .../ImageMetadataViewer/ImageMetadataViewer.tsx | 15 ++++++--------- 3 files changed, 8 insertions(+), 11 deletions(-) diff --git a/invokeai/frontend/web/src/features/gallery/components/CurrentImage/CurrentImageButtons.tsx b/invokeai/frontend/web/src/features/gallery/components/CurrentImage/CurrentImageButtons.tsx index af5aff52d8..3559679fc4 100644 --- a/invokeai/frontend/web/src/features/gallery/components/CurrentImage/CurrentImageButtons.tsx +++ b/invokeai/frontend/web/src/features/gallery/components/CurrentImage/CurrentImageButtons.tsx @@ -110,7 +110,7 @@ const CurrentImageButtons = (props: CurrentImageButtonsProps) => { ); const { metadata, workflow, isLoading } = useGetImageMetadataFromFileQuery( - lastSelectedImage?.image_name ?? skipToken, + lastSelectedImage ?? skipToken, { selectFromResult: (res) => ({ isLoading: res.isFetching, diff --git a/invokeai/frontend/web/src/features/gallery/components/ImageContextMenu/SingleSelectionMenuItems.tsx b/invokeai/frontend/web/src/features/gallery/components/ImageContextMenu/SingleSelectionMenuItems.tsx index 272f63fc93..e75a7745bb 100644 --- a/invokeai/frontend/web/src/features/gallery/components/ImageContextMenu/SingleSelectionMenuItems.tsx +++ b/invokeai/frontend/web/src/features/gallery/components/ImageContextMenu/SingleSelectionMenuItems.tsx @@ -52,7 +52,7 @@ const SingleSelectionMenuItems = (props: SingleSelectionMenuItemsProps) => { const isCanvasEnabled = useFeatureStatus('unifiedCanvas').isFeatureEnabled; const { metadata, workflow, isLoading } = useGetImageMetadataFromFileQuery( - imageDTO.image_name, + imageDTO, { selectFromResult: (res) => ({ isLoading: res.isFetching, diff --git a/invokeai/frontend/web/src/features/gallery/components/ImageMetadataViewer/ImageMetadataViewer.tsx b/invokeai/frontend/web/src/features/gallery/components/ImageMetadataViewer/ImageMetadataViewer.tsx index 51a734c49a..ca3eab2dba 100644 --- a/invokeai/frontend/web/src/features/gallery/components/ImageMetadataViewer/ImageMetadataViewer.tsx +++ b/invokeai/frontend/web/src/features/gallery/components/ImageMetadataViewer/ImageMetadataViewer.tsx @@ -27,15 +27,12 @@ const ImageMetadataViewer = ({ image }: ImageMetadataViewerProps) => { // dispatch(setShouldShowImageDetails(false)); // }); - const { metadata, workflow } = useGetImageMetadataFromFileQuery( - image.image_name, - { - selectFromResult: (res) => ({ - metadata: res?.currentData?.metadata, - workflow: res?.currentData?.workflow, - }), - } - ); + const { metadata, workflow } = useGetImageMetadataFromFileQuery(image, { + selectFromResult: (res) => ({ + metadata: res?.currentData?.metadata, + workflow: res?.currentData?.workflow, + }), + }); return (