From f8bb1f7a3e38109937a4f941a299a41415698baa Mon Sep 17 00:00:00 2001 From: Mary Hipp Date: Fri, 1 Sep 2023 13:02:43 -0400 Subject: [PATCH] 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({