1
1
import { IconButton } from '@invoke-ai/ui-library' ;
2
+ import { useStore } from '@nanostores/react' ;
3
+ import { $authToken } from 'app/store/nanostores/authToken' ;
2
4
import { useAppSelector } from 'app/store/storeHooks' ;
3
5
import { withResultAsync } from 'common/util/result' ;
4
6
import { selectSelectedImage } from 'features/controlLayers/store/canvasStagingAreaSlice' ;
@@ -14,6 +16,7 @@ const TOAST_ID = 'SAVE_STAGING_AREA_IMAGE_TO_GALLERY';
14
16
export const StagingAreaToolbarSaveSelectedToGalleryButton = memo ( ( ) => {
15
17
const autoAddBoardId = useAppSelector ( selectAutoAddBoardId ) ;
16
18
const selectedImage = useAppSelector ( selectSelectedImage ) ;
19
+ const authToken = useStore ( $authToken ) ;
17
20
18
21
const { t } = useTranslation ( ) ;
19
22
@@ -26,7 +29,14 @@ export const StagingAreaToolbarSaveSelectedToGalleryButton = memo(() => {
26
29
// the gallery without borking the canvas, which may need this image to exist.
27
30
const result = await withResultAsync ( async ( ) => {
28
31
// 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 ) ;
30
40
const blob = await res . blob ( ) ;
31
41
// Create a new file with the same name, which we will upload
32
42
const file = new File ( [ blob ] , `copy_of_${ selectedImage . imageDTO . image_name } ` , { type : 'image/png' } ) ;
@@ -56,7 +66,7 @@ export const StagingAreaToolbarSaveSelectedToGalleryButton = memo(() => {
56
66
status : 'error' ,
57
67
} ) ;
58
68
}
59
- } , [ autoAddBoardId , selectedImage , t ] ) ;
69
+ } , [ autoAddBoardId , selectedImage , t , authToken ] ) ;
60
70
61
71
return (
62
72
< IconButton
0 commit comments