feat(ui): add POC image record fetching

This commit is contained in:
psychedelicious 2023-05-22 16:11:28 +10:00 committed by Kent Keirsey
parent 3f94f81acd
commit 4e29a751d8
2 changed files with 62 additions and 2 deletions

View File

@ -6,7 +6,12 @@ import {
} from 'services/util/deserializeImageField';
import { Image } from 'app/types/invokeai';
import { resultAdded } from 'features/gallery/store/resultsSlice';
import { imageReceived, thumbnailReceived } from 'services/thunks/image';
import {
imageReceived,
imageRecordReceived,
imageUrlsReceived,
thumbnailReceived,
} from 'services/thunks/image';
import { startAppListening } from '..';
import { imageSelected } from 'features/gallery/store/gallerySlice';
import { addImageToStagingArea } from 'features/canvas/store/canvasSlice';
@ -24,7 +29,7 @@ export const addImageResultReceivedListener = () => {
}
return false;
},
effect: (action, { getState, dispatch }) => {
effect: async (action, { getState, dispatch, take }) => {
if (!invocationComplete.match(action)) {
return;
}
@ -35,6 +40,29 @@ export const addImageResultReceivedListener = () => {
if (isImageOutput(result) && !nodeDenylist.includes(node.type)) {
const name = result.image.image_name;
const type = result.image.image_type;
dispatch(imageUrlsReceived({ imageName: name, imageType: type }));
const [{ payload }] = await take(
(action): action is ReturnType<typeof imageUrlsReceived.fulfilled> =>
imageUrlsReceived.fulfilled.match(action) &&
action.payload.image_name === name
);
console.log(payload);
dispatch(imageRecordReceived({ imageName: name, imageType: type }));
const [x] = await take(
(
action
): action is ReturnType<typeof imageRecordReceived.fulfilled> =>
imageRecordReceived.fulfilled.match(action) &&
action.payload.image_name === name
);
console.log(x);
const state = getState();
// if we need to refetch, set URLs to placeholder for now

View File

@ -6,6 +6,38 @@ import { getHeaders } from 'services/util/getHeaders';
const imagesLog = log.child({ namespace: 'image' });
type imageUrlsReceivedArg = Parameters<
(typeof ImagesService)['getImageUrls']
>[0];
/**
* `ImagesService.getImageUrls()` thunk
*/
export const imageUrlsReceived = createAppAsyncThunk(
'api/imageUrlsReceived',
async (arg: imageUrlsReceivedArg) => {
const response = await ImagesService.getImageUrls(arg);
imagesLog.info({ arg, response }, 'Received image urls');
return response;
}
);
type imageRecordReceivedArg = Parameters<
(typeof ImagesService)['getImageUrls']
>[0];
/**
* `ImagesService.getImageUrls()` thunk
*/
export const imageRecordReceived = createAppAsyncThunk(
'api/imageUrlsReceived',
async (arg: imageRecordReceivedArg) => {
const response = await ImagesService.getImageRecord(arg);
imagesLog.info({ arg, response }, 'Received image record');
return response;
}
);
type ImageReceivedArg = Parameters<(typeof ImagesService)['getImage']>[0];
/**