diff --git a/frontend/src/App.tsx b/frontend/src/App.tsx index 0f796de..ea5017b 100644 --- a/frontend/src/App.tsx +++ b/frontend/src/App.tsx @@ -12,6 +12,7 @@ import { type ShareEvent, } from "tauri-plugin-sharetarget-api"; import { readFile } from "@tauri-apps/plugin-fs"; +import { sendImage, sendImageFile } from "./network"; export const App = () => { const [logs, setLogs] = createSignal([]); @@ -54,6 +55,15 @@ export const App = () => { }; }); + createEffect(() => { + const f = file(); + if (f == null) { + return; + } + + sendImageFile(f.name, f); + }); + return ( <> diff --git a/frontend/src/network/index.ts b/frontend/src/network/index.ts index 136b667..4f4ae0e 100644 --- a/frontend/src/network/index.ts +++ b/frontend/src/network/index.ts @@ -48,6 +48,23 @@ const sendImageResponseValidator = strictObject({ Status: string(), }); +export const sendImageFile = async ( + imageName: string, + file: File, +): Promise> => { + const request = getBaseAuthorizedRequest({ + path: `image/${imageName}`, + body: file, + method: "POST", + }); + + request.headers.set("Content-Type", "application/oclet-stream"); + + const res = await fetch(request).then((res) => res.json()); + + return parse(sendImageResponseValidator, res); +}; + export const sendImage = async ( imageName: string, base64Image: string,