Skip to content

Commit 271cc52

Browse files
Mary Hippmaryhipp
authored andcommitted
fix(ui): use token for download if its in store
1 parent e444586 commit 271cc52

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

invokeai/frontend/web/src/features/controlLayers/components/StagingArea/StagingAreaToolbarSaveSelectedToGalleryButton.tsx

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import { IconButton } from '@invoke-ai/ui-library';
2+
import { useStore } from '@nanostores/react';
3+
import { $authToken } from 'app/store/nanostores/authToken';
24
import { useAppSelector } from 'app/store/storeHooks';
35
import { withResultAsync } from 'common/util/result';
46
import { selectSelectedImage } from 'features/controlLayers/store/canvasStagingAreaSlice';
@@ -14,6 +16,7 @@ const TOAST_ID = 'SAVE_STAGING_AREA_IMAGE_TO_GALLERY';
1416
export const StagingAreaToolbarSaveSelectedToGalleryButton = memo(() => {
1517
const autoAddBoardId = useAppSelector(selectAutoAddBoardId);
1618
const selectedImage = useAppSelector(selectSelectedImage);
19+
const authToken = useStore($authToken);
1720

1821
const { t } = useTranslation();
1922

@@ -26,7 +29,14 @@ export const StagingAreaToolbarSaveSelectedToGalleryButton = memo(() => {
2629
// the gallery without borking the canvas, which may need this image to exist.
2730
const result = await withResultAsync(async () => {
2831
// Download the image
29-
const res = await fetch(selectedImage.imageDTO.image_url);
32+
const requestOpts = authToken
33+
? {
34+
headers: {
35+
Authorization: `Bearer ${authToken}`,
36+
},
37+
}
38+
: {};
39+
const res = await fetch(selectedImage.imageDTO.image_url, requestOpts);
3040
const blob = await res.blob();
3141
// Create a new file with the same name, which we will upload
3242
const file = new File([blob], `copy_of_${selectedImage.imageDTO.image_name}`, { type: 'image/png' });
@@ -56,7 +66,7 @@ export const StagingAreaToolbarSaveSelectedToGalleryButton = memo(() => {
5666
status: 'error',
5767
});
5868
}
59-
}, [autoAddBoardId, selectedImage, t]);
69+
}, [autoAddBoardId, selectedImage, t, authToken]);
6070

6171
return (
6272
<IconButton

0 commit comments

Comments
 (0)