mirror of
https://github.com/invoke-ai/InvokeAI
synced 2024-08-30 20:32:17 +00:00
fix(ui): remove getMetadataFromFile query & util
This will all be handled by python going forward
This commit is contained in:
parent
2f4f83280b
commit
c071262c20
@ -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<ImageMetadataAndWorkflow> => {
|
||||
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;
|
||||
};
|
@ -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<void, ImageDTO>({
|
||||
query: ({ image_name }) => ({
|
||||
url: `images/i/${image_name}`,
|
||||
@ -1643,6 +1574,5 @@ export const {
|
||||
useDeleteBoardMutation,
|
||||
useStarImagesMutation,
|
||||
useUnstarImagesMutation,
|
||||
useGetImageMetadataFromFileQuery,
|
||||
useBulkDownloadImagesMutation,
|
||||
} = imagesApi;
|
||||
|
Loading…
Reference in New Issue
Block a user