Skip to content

Commit b049880

Browse files
fix(ui): uploads initiated from canvas
1 parent e5293fd commit b049880

File tree

3 files changed

+14
-32
lines changed

3 files changed

+14
-32
lines changed

invokeai/frontend/web/src/features/controlLayers/hooks/useSaveLayerToAssets.ts

Lines changed: 10 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,10 @@ import type { CanvasEntityAdapterRasterLayer } from 'features/controlLayers/konv
55
import type { CanvasEntityAdapterRegionalGuidance } from 'features/controlLayers/konva/CanvasEntity/CanvasEntityAdapterRegionalGuidance';
66
import { canvasToBlob } from 'features/controlLayers/konva/util';
77
import { selectAutoAddBoardId } from 'features/gallery/store/gallerySelectors';
8-
import { toast } from 'features/toast/toast';
98
import { useCallback } from 'react';
10-
import { useTranslation } from 'react-i18next';
119
import { useUploadImageMutation } from 'services/api/endpoints/images';
1210

1311
export const useSaveLayerToAssets = () => {
14-
const { t } = useTranslation();
1512
const [uploadImage] = useUploadImageMutation();
1613
const autoAddBoardId = useAppSelector(selectAutoAddBoardId);
1714

@@ -27,30 +24,17 @@ export const useSaveLayerToAssets = () => {
2724
if (!adapter) {
2825
return;
2926
}
30-
try {
31-
const canvas = adapter.getCanvas();
32-
const blob = await canvasToBlob(canvas);
33-
const file = new File([blob], `layer-${adapter.id}.png`, { type: 'image/png' });
34-
await uploadImage({
35-
file,
36-
image_category: 'user',
37-
is_intermediate: false,
38-
postUploadAction: { type: 'TOAST' },
39-
board_id: autoAddBoardId === 'none' ? undefined : autoAddBoardId,
40-
});
41-
42-
toast({
43-
status: 'info',
44-
title: t('toast.layerSavedToAssets'),
45-
});
46-
} catch (error) {
47-
toast({
48-
status: 'error',
49-
title: t('toast.problemSavingLayer'),
50-
});
51-
}
27+
const canvas = adapter.getCanvas();
28+
const blob = await canvasToBlob(canvas);
29+
const file = new File([blob], `layer-${adapter.id}.png`, { type: 'image/png' });
30+
uploadImage({
31+
file,
32+
image_category: 'user',
33+
is_intermediate: false,
34+
board_id: autoAddBoardId === 'none' ? undefined : autoAddBoardId,
35+
});
5236
},
53-
[t, autoAddBoardId, uploadImage]
37+
[autoAddBoardId, uploadImage]
5438
);
5539

5640
return saveLayerToAssets;

invokeai/frontend/web/src/features/controlLayers/konva/CanvasCompositorModule.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ import { t } from 'i18next';
3535
import { atom, computed } from 'nanostores';
3636
import type { Logger } from 'roarr';
3737
import { serializeError } from 'serialize-error';
38-
import type { UploadOptions } from 'services/api/endpoints/images';
38+
import type { UploadImageArg } from 'services/api/endpoints/images';
3939
import { getImageDTOSafe, uploadImage } from 'services/api/endpoints/images';
4040
import type { ImageDTO } from 'services/api/types';
4141
import stableHash from 'stable-hash';
@@ -259,7 +259,7 @@ export class CanvasCompositorModule extends CanvasModuleBase {
259259
getCompositeImageDTO = async (
260260
adapters: CanvasEntityAdapter[],
261261
rect: Rect,
262-
uploadOptions: Pick<UploadOptions, 'is_intermediate' | 'metadata'>,
262+
uploadOptions: Pick<UploadImageArg, 'is_intermediate' | 'metadata'>,
263263
compositingOptions?: CompositingOptions,
264264
forceUpload?: boolean
265265
): Promise<ImageDTO> => {
@@ -297,8 +297,7 @@ export class CanvasCompositorModule extends CanvasModuleBase {
297297
this.$isUploading.set(true);
298298
const uploadResult = await withResultAsync(() =>
299299
uploadImage({
300-
blob,
301-
fileName: 'canvas-composite.png',
300+
file: new File([blob], 'canvas-composite.png', { type: 'image/png' }),
302301
image_category: 'general',
303302
is_intermediate: uploadOptions.is_intermediate,
304303
board_id: uploadOptions.is_intermediate ? undefined : selectAutoAddBoardId(this.manager.store.getState()),

invokeai/frontend/web/src/features/controlLayers/konva/CanvasEntity/CanvasEntityObjectRenderer.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -490,8 +490,7 @@ export class CanvasEntityObjectRenderer extends CanvasModuleBase {
490490
previewBlob(blob, 'Rasterized entity');
491491
}
492492
imageDTO = await uploadImage({
493-
blob,
494-
fileName: `${this.id}_rasterized.png`,
493+
file: new File([blob], `${this.id}_rasterized.png`, { type: 'image/png' }),
495494
image_category: 'other',
496495
is_intermediate: true,
497496
});

0 commit comments

Comments
 (0)