{serverConfig.enableFileManager ? (
-
{
- try {
- const newFile = await getMediaFile(tab, filename)
- setFile(newFile)
- } catch (e: any) {
- toast({
- variant: "destructive",
- description: e.message ? e.message : e.toString(),
- })
- return
- }
- }}
- />
+
) : (
<>>
)}
diff --git a/web_app/src/lib/api.ts b/web_app/src/lib/api.ts
index f77e38e..a8f0b7f 100644
--- a/web_app/src/lib/api.ts
+++ b/web_app/src/lib/api.ts
@@ -135,7 +135,7 @@ export async function runPlugin(
body: JSON.stringify({
name,
image: imageBase64,
- scale:upscale,
+ scale: upscale,
clicks,
}),
})
@@ -167,6 +167,23 @@ export async function getMediaFile(tab: string, filename: string) {
throw new Error(errMsg.errors)
}
+export async function getMediaBlob(tab: string, filename: string) {
+ const res = await fetch(
+ `${API_ENDPOINT}/media_file?tab=${tab}&filename=${encodeURIComponent(
+ filename
+ )}`,
+ {
+ method: "GET",
+ }
+ )
+ if (res.ok) {
+ const blob = await res.blob()
+ return blob
+ }
+ const errMsg = await res.json()
+ throw new Error(errMsg.errors)
+}
+
export async function getMedias(tab: string): Promise {
const res = await api.get(`medias`, { params: { tab } })
return res.data
diff --git a/web_app/src/lib/states.ts b/web_app/src/lib/states.ts
index a9cde43..2d91142 100644
--- a/web_app/src/lib/states.ts
+++ b/web_app/src/lib/states.ts
@@ -207,6 +207,7 @@ type AppAction = {
updateInteractiveSegState: (newState: Partial) => void
resetInteractiveSegState: () => void
handleInteractiveSegAccept: () => void
+ handleFileManagerMaskSelect: (blob: Blob) => Promise
showPromptInput: () => boolean
runInpainting: () => Promise
@@ -903,6 +904,16 @@ export const useStore = createWithEqualityFn()(
})
},
+ handleFileManagerMaskSelect: async (blob: Blob) => {
+ const newMask = new Image()
+
+ await loadImage(newMask, URL.createObjectURL(blob))
+ set((state) => {
+ state.editorState.extraMasks.push(castDraft(newMask))
+ })
+ get().runInpainting()
+ },
+
setIsInpainting: (newValue: boolean) =>
set((state) => {
state.isInpainting = newValue