diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs index 652510aa..323a3cf0 100644 --- a/src-tauri/src/main.rs +++ b/src-tauri/src/main.rs @@ -333,6 +333,7 @@ async fn streamed_fetch( headers: String, body: String, app: AppHandle, + method: String, ) -> String { //parse headers let headers_json: Value = match serde_json::from_str(&headers) { @@ -357,14 +358,51 @@ async fn streamed_fetch( return format!(r#"{{"success":false,"body":"Invalid header JSON"}}"#); } - let body_decoded = general_purpose::STANDARD.decode(body.as_bytes()).unwrap(); - let client = reqwest::Client::new(); - let response = client + let builder: reqwest::RequestBuilder; + if method == "POST" { + + let body_decoded = general_purpose::STANDARD.decode(body.as_bytes()).unwrap(); + + builder = client .post(&url) .headers(headers) .timeout(Duration::from_secs(240)) .body(body_decoded) + } + else if method == "GET" { + builder = client + .get(&url) + .headers(headers) + .timeout(Duration::from_secs(240)); + } + else if method == "PUT" { + + let body_decoded = general_purpose::STANDARD.decode(body.as_bytes()).unwrap(); + + builder = client + .put(&url) + .headers(headers) + .timeout(Duration::from_secs(240)) + .body(body_decoded) + } + else if method == "DELETE" { + + let body_decoded = general_purpose::STANDARD.decode(body.as_bytes()).unwrap(); + + builder = client + .delete(&url) + .headers(headers) + .timeout(Duration::from_secs(240)) + .body(body_decoded) + } + else { + return format!(r#"{{"success":false, body:"Invalid method"}}"#); + } + + + + let response = builder .send() .await; diff --git a/src/ts/globalApi.svelte.ts b/src/ts/globalApi.svelte.ts index d2ed95bb..6c7dbe45 100644 --- a/src/ts/globalApi.svelte.ts +++ b/src/ts/globalApi.svelte.ts @@ -1811,7 +1811,7 @@ const pipeFetchLog = (fetchLogIndex: number, readableStream: ReadableStream { try { const parsedRes = JSON.parse(res as string) @@ -1973,7 +1979,7 @@ export async function fetchNative(url:string, arg:{ "risu-url": encodeURIComponent(url), "Content-Type": "application/json" }, - method: "POST", + method: arg.method, signal: arg.signal }) @@ -1990,7 +1996,7 @@ export async function fetchNative(url:string, arg:{ body: realBody, headers: headers, method: arg.method, - signal: arg.signal + signal: arg.signal, }) } }