From 6cf36fb56637264ca1a65683f9fcc412d8345291 Mon Sep 17 00:00:00 2001 From: adrieljss Date: Tue, 11 Mar 2025 23:57:44 +0800 Subject: [PATCH] fix: revert command back to fetch_read_body to comply with permissions --- plugins/http/guest-js/index.ts | 28 +++++++++---------- .../permissions/autogenerated/reference.md | 2 +- plugins/http/permissions/schemas/schema.json | 10 +++++++ plugins/http/src/commands.rs | 2 +- plugins/http/src/lib.rs | 2 +- 5 files changed, 27 insertions(+), 17 deletions(-) diff --git a/plugins/http/guest-js/index.ts b/plugins/http/guest-js/index.ts index 6b48e730..770cbc5f 100644 --- a/plugins/http/guest-js/index.ts +++ b/plugins/http/guest-js/index.ts @@ -186,6 +186,19 @@ export async function fetch( throw new Error(ERROR_REQUEST_CANCELLED) } + const rid = await invoke('plugin:http|fetch', { + clientConfig: { + method: req.method, + url: req.url, + headers: mappedHeaders, + data, + maxRedirections, + connectTimeout, + proxy, + danger + } + }) + const readableStreamBody = new ReadableStream({ start: (controller) => { const streamChannel = new Channel() @@ -212,7 +225,7 @@ export async function fetch( } // run a non-blocking body stream fetch - invoke('plugin:http|fetch_stream_body', { + invoke('plugin:http|fetch_read_body', { rid, streamChannel }).catch((e) => { @@ -221,19 +234,6 @@ export async function fetch( } }) - const rid = await invoke('plugin:http|fetch', { - clientConfig: { - method: req.method, - url: req.url, - headers: mappedHeaders, - data, - maxRedirections, - connectTimeout, - proxy, - danger - } - }) - const abort = () => invoke('plugin:http|fetch_cancel', { rid }) // abort early here if needed diff --git a/plugins/http/permissions/autogenerated/reference.md b/plugins/http/permissions/autogenerated/reference.md index aade2fda..19a3c4eb 100644 --- a/plugins/http/permissions/autogenerated/reference.md +++ b/plugins/http/permissions/autogenerated/reference.md @@ -15,7 +15,7 @@ All fetch operations are enabled. - `allow-fetch` - `allow-fetch-cancel` -- `allow-fetch-read-body` +- `allow-fetch-stream-body` - `allow-fetch-send` ## Permission Table diff --git a/plugins/http/permissions/schemas/schema.json b/plugins/http/permissions/schemas/schema.json index eb7e4763..03caf56e 100644 --- a/plugins/http/permissions/schemas/schema.json +++ b/plugins/http/permissions/schemas/schema.json @@ -314,6 +314,16 @@ "type": "string", "const": "deny-fetch-cancel" }, + { + "description": "Enables the fetch_read_body command without any pre-configured scope.", + "type": "string", + "const": "allow-fetch-read-body" + }, + { + "description": "Denies the fetch_read_body command without any pre-configured scope.", + "type": "string", + "const": "deny-fetch-read-body" + }, { "description": "Enables the fetch_send command without any pre-configured scope.", "type": "string", diff --git a/plugins/http/src/commands.rs b/plugins/http/src/commands.rs index 4ed7bee0..b6113c29 100644 --- a/plugins/http/src/commands.rs +++ b/plugins/http/src/commands.rs @@ -360,7 +360,7 @@ pub fn fetch_cancel(webview: Webview, rid: ResourceId) -> crate:: } #[command] -pub async fn fetch_stream_body( +pub async fn fetch_read_body( webview: Webview, rid: ResourceId, stream_channel: Channel, diff --git a/plugins/http/src/lib.rs b/plugins/http/src/lib.rs index d9613ed5..d775760c 100644 --- a/plugins/http/src/lib.rs +++ b/plugins/http/src/lib.rs @@ -37,7 +37,7 @@ pub fn init() -> TauriPlugin { commands::fetch, commands::fetch_cancel, commands::fetch_send, - commands::fetch_stream_body, + commands::fetch_read_body, ]) .build() }