diff --git a/invokeai/frontend/web/src/features/nodes/util/getMetadataAndWorkflowFromImageBlob.ts b/invokeai/frontend/web/src/features/nodes/util/getMetadataAndWorkflowFromImageBlob.ts deleted file mode 100644 index b46a701757..0000000000 --- a/invokeai/frontend/web/src/features/nodes/util/getMetadataAndWorkflowFromImageBlob.ts +++ /dev/null @@ -1,45 +0,0 @@ -import * as png from '@stevebel/png'; -import { logger } from 'app/logging/logger'; -import { parseify } from 'common/util/serialize'; -import { - ImageMetadataAndWorkflow, - zCoreMetadata, - zWorkflow, -} from 'features/nodes/types/types'; -import { get } from 'lodash-es'; - -export const getMetadataAndWorkflowFromImageBlob = async ( - image: Blob -): Promise => { - const data: ImageMetadataAndWorkflow = {}; - const buffer = await image.arrayBuffer(); - const text = png.decode(buffer).text; - - const rawMetadata = get(text, 'invokeai_metadata'); - if (rawMetadata) { - const metadataResult = zCoreMetadata.safeParse(JSON.parse(rawMetadata)); - if (metadataResult.success) { - data.metadata = metadataResult.data; - } else { - logger('system').error( - { error: parseify(metadataResult.error) }, - 'Problem reading metadata from image' - ); - } - } - - const rawWorkflow = get(text, 'invokeai_workflow'); - if (rawWorkflow) { - const workflowResult = zWorkflow.safeParse(JSON.parse(rawWorkflow)); - if (workflowResult.success) { - data.workflow = workflowResult.data; - } else { - logger('system').error( - { error: parseify(workflowResult.error) }, - 'Problem reading workflow from image' - ); - } - } - - return data; -}; diff --git a/invokeai/frontend/web/src/services/api/endpoints/images.ts b/invokeai/frontend/web/src/services/api/endpoints/images.ts index 36c00ee1c9..166d00a3db 100644 --- a/invokeai/frontend/web/src/services/api/endpoints/images.ts +++ b/invokeai/frontend/web/src/services/api/endpoints/images.ts @@ -1,5 +1,4 @@ import { EntityState, Update } from '@reduxjs/toolkit'; -import { fetchBaseQuery } from '@reduxjs/toolkit/dist/query'; import { PatchCollection } from '@reduxjs/toolkit/dist/query/core/buildThunks'; import { logger } from 'app/logging/logger'; import { @@ -8,15 +7,9 @@ import { IMAGE_CATEGORIES, IMAGE_LIMIT, } from 'features/gallery/store/types'; -import { - CoreMetadata, - ImageMetadataAndWorkflow, - zCoreMetadata, -} from 'features/nodes/types/types'; -import { getMetadataAndWorkflowFromImageBlob } from 'features/nodes/util/getMetadataAndWorkflowFromImageBlob'; +import { CoreMetadata, zCoreMetadata } from 'features/nodes/types/types'; import { keyBy } from 'lodash-es'; import { ApiTagDescription, LIST_TAG, api } from '..'; -import { $authToken, $projectId } from '../client'; import { components, paths } from '../schema'; import { DeleteBoardResult, @@ -135,68 +128,6 @@ export const imagesApi = api.injectEndpoints({ }, keepUnusedDataFor: 86400, // 24 hours }), - getImageMetadataFromFile: build.query< - ImageMetadataAndWorkflow, - { image: ImageDTO; shouldFetchMetadataFromApi: boolean } - >({ - queryFn: async ( - args: { image: ImageDTO; shouldFetchMetadataFromApi: boolean }, - api, - extraOptions, - fetchWithBaseQuery - ) => { - if (args.shouldFetchMetadataFromApi) { - let metadata; - const metadataResponse = await fetchWithBaseQuery( - `images/i/${args.image.image_name}/metadata` - ); - if (metadataResponse.data) { - const metadataResult = zCoreMetadata.safeParse( - // eslint-disable-next-line @typescript-eslint/no-explicit-any - (metadataResponse.data as any)?.metadata - ); - if (metadataResult.success) { - metadata = metadataResult.data; - } - } - return { data: { metadata } }; - } else { - 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.image_url, - api, - extraOptions - ); - const data = await getMetadataAndWorkflowFromImageBlob( - response.data as Blob - ); - - return { data }; - } - }, - providesTags: (result, error, { image }) => [ - { type: 'ImageMetadataFromFile', id: image.image_name }, - ], - keepUnusedDataFor: 86400, // 24 hours - }), deleteImage: build.mutation({ query: ({ image_name }) => ({ url: `images/i/${image_name}`, @@ -1643,6 +1574,5 @@ export const { useDeleteBoardMutation, useStarImagesMutation, useUnstarImagesMutation, - useGetImageMetadataFromFileQuery, useBulkDownloadImagesMutation, } = imagesApi;