From 690f7506c0dfdbd7e11adce214c9c77483879392 Mon Sep 17 00:00:00 2001 From: Mary Hipp Date: Fri, 22 Nov 2024 12:04:25 -0500 Subject: [PATCH] fix(ui): use token for download if its in store --- ...agingAreaToolbarSaveSelectedToGalleryButton.tsx | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/invokeai/frontend/web/src/features/controlLayers/components/StagingArea/StagingAreaToolbarSaveSelectedToGalleryButton.tsx b/invokeai/frontend/web/src/features/controlLayers/components/StagingArea/StagingAreaToolbarSaveSelectedToGalleryButton.tsx index 0c31215f0d1..9e930928a22 100644 --- a/invokeai/frontend/web/src/features/controlLayers/components/StagingArea/StagingAreaToolbarSaveSelectedToGalleryButton.tsx +++ b/invokeai/frontend/web/src/features/controlLayers/components/StagingArea/StagingAreaToolbarSaveSelectedToGalleryButton.tsx @@ -1,4 +1,6 @@ import { IconButton } from '@invoke-ai/ui-library'; +import { useStore } from '@nanostores/react'; +import { $authToken } from 'app/store/nanostores/authToken'; import { useAppSelector } from 'app/store/storeHooks'; import { withResultAsync } from 'common/util/result'; import { selectSelectedImage } from 'features/controlLayers/store/canvasStagingAreaSlice'; @@ -14,6 +16,7 @@ const TOAST_ID = 'SAVE_STAGING_AREA_IMAGE_TO_GALLERY'; export const StagingAreaToolbarSaveSelectedToGalleryButton = memo(() => { const autoAddBoardId = useAppSelector(selectAutoAddBoardId); const selectedImage = useAppSelector(selectSelectedImage); + const authToken = useStore($authToken); const { t } = useTranslation(); @@ -26,7 +29,14 @@ export const StagingAreaToolbarSaveSelectedToGalleryButton = memo(() => { // the gallery without borking the canvas, which may need this image to exist. const result = await withResultAsync(async () => { // Download the image - const res = await fetch(selectedImage.imageDTO.image_url); + const requestOpts = authToken + ? { + headers: { + Authorization: `Bearer ${authToken}`, + }, + } + : {}; + const res = await fetch(selectedImage.imageDTO.image_url, requestOpts); const blob = await res.blob(); // Create a new file with the same name, which we will upload const file = new File([blob], `copy_of_${selectedImage.imageDTO.image_name}`, { type: 'image/png' }); @@ -56,7 +66,7 @@ export const StagingAreaToolbarSaveSelectedToGalleryButton = memo(() => { status: 'error', }); } - }, [autoAddBoardId, selectedImage, t]); + }, [autoAddBoardId, selectedImage, t, authToken]); return (