Skip to content

DeepSeek Harness Tauri 桌面版 | Only 8mb installer, zero environment setup, preset plugins, Windows / macOS / Linux.

5.7 KB
Raw Blame
diff --git a/dist-js/index.cjs b/dist-js/index.cjs
index f1bba4502af349efbde8b94ac1b1773a490f4836..305702b4b5420d3b0660476cf544778edab67010 100644
--- a/dist-js/index.cjs
+++ b/dist-js/index.cjs
@@ -29,6 +29,13 @@ var core = require('@tauri-apps/api/core');
  * @module
  */
 const ERROR_REQUEST_CANCELLED = 'Request cancelled';
+// Header names/values must be ISO-8859-1: GitHub adds a `content-disposition`
+// carrying the raw file name, so any asset with a non-Latin name (all dsh-pet
+// animations) makes `new Headers(...)` throw and fails the whole fetch.
+const ISO_8859_1_ONLY = /^[\u0000-\u00ff]*$/;
+function toResponseHeaders(rawHeaders) {
+    return new Headers(rawHeaders.filter(([name, value]) => ISO_8859_1_ONLY.test(name) && ISO_8859_1_ONLY.test(value)));
+}
 /**
  * Fetch a resource from the network. It returns a `Promise` that resolves to the
  * `Response` to that `Request`, whether it is successful or not.
@@ -103,7 +110,11 @@ async function fetch(input, init) {
             danger
         }
     });
-    const abort = () => core.invoke('plugin:http|fetch_cancel', { rid });
+    // Cancellation cleanup is best-effort: `fetch_read_body` closes the response
+    // resource at EOF, so these fire-and-forget commands legitimately fail with
+    // "The resource id ... is invalid" — swallow it, otherwise every aborted
+    // fetch leaks an unhandled rejection (hosts often forward those to logs).
+    const abort = () => core.invoke('plugin:http|fetch_cancel', { rid }).catch(() => {});
     // Optimistically check for abort signal
     // and avoid doing any work after doing intial work on the Rust side
     if (signal?.aborted) {
@@ -117,7 +128,7 @@ async function fetch(input, init) {
         rid
     });
     const dropBody = () => {
-        return core.invoke('plugin:http|fetch_cancel_body', { rid: responseRid });
+        return core.invoke('plugin:http|fetch_cancel_body', { rid: responseRid }).catch(() => {});
     };
     const readChunk = async (controller) => {
         let data;
@@ -172,7 +183,7 @@ async function fetch(input, init) {
     // browsers, where `set-cookie` is treated as a forbidden response
     // header and is generally not readable from JavaScript.
     Object.defineProperty(res, 'headers', {
-        value: new Headers(responseHeaders),
+        value: toResponseHeaders(responseHeaders),
         writable: false
     });
     // Patch clone() per-instance so cloning preserves the overridden properties
@@ -182,7 +193,7 @@ async function fetch(input, init) {
             const cloned = originalClone();
             Object.defineProperty(cloned, 'url', { value: url, writable: false });
             Object.defineProperty(cloned, 'headers', {
-                value: new Headers(responseHeaders),
+                value: toResponseHeaders(responseHeaders),
                 writable: false
             });
             return cloned;
diff --git a/dist-js/index.js b/dist-js/index.js
index 01f0ea49e0fe45425adcb8596f57e97a92c8c958..a35a916bf78f219f9012a7609e06b04c3ac9c149 100644
--- a/dist-js/index.js
+++ b/dist-js/index.js
@@ -27,6 +27,13 @@ import { invoke } from '@tauri-apps/api/core';
  * @module
  */
 const ERROR_REQUEST_CANCELLED = 'Request cancelled';
+// Header names/values must be ISO-8859-1: GitHub adds a `content-disposition`
+// carrying the raw file name, so any asset with a non-Latin name (all dsh-pet
+// animations) makes `new Headers(...)` throw and fails the whole fetch.
+const ISO_8859_1_ONLY = /^[\u0000-\u00ff]*$/;
+function toResponseHeaders(rawHeaders) {
+    return new Headers(rawHeaders.filter(([name, value]) => ISO_8859_1_ONLY.test(name) && ISO_8859_1_ONLY.test(value)));
+}
 /**
  * Fetch a resource from the network. It returns a `Promise` that resolves to the
  * `Response` to that `Request`, whether it is successful or not.
@@ -101,7 +108,11 @@ async function fetch(input, init) {
             danger
         }
     });
-    const abort = () => invoke('plugin:http|fetch_cancel', { rid });
+    // Cancellation cleanup is best-effort: `fetch_read_body` closes the response
+    // resource at EOF, so these fire-and-forget commands legitimately fail with
+    // "The resource id ... is invalid" — swallow it, otherwise every aborted
+    // fetch leaks an unhandled rejection (hosts often forward those to logs).
+    const abort = () => invoke('plugin:http|fetch_cancel', { rid }).catch(() => {});
     // Optimistically check for abort signal
     // and avoid doing any work after doing intial work on the Rust side
     if (signal?.aborted) {
@@ -115,7 +126,7 @@ async function fetch(input, init) {
         rid
     });
     const dropBody = () => {
-        return invoke('plugin:http|fetch_cancel_body', { rid: responseRid });
+        return invoke('plugin:http|fetch_cancel_body', { rid: responseRid }).catch(() => {});
     };
     const readChunk = async (controller) => {
         let data;
@@ -170,7 +181,7 @@ async function fetch(input, init) {
     // browsers, where `set-cookie` is treated as a forbidden response
     // header and is generally not readable from JavaScript.
     Object.defineProperty(res, 'headers', {
-        value: new Headers(responseHeaders),
+        value: toResponseHeaders(responseHeaders),
         writable: false
     });
     // Patch clone() per-instance so cloning preserves the overridden properties
@@ -180,7 +191,7 @@ async function fetch(input, init) {
             const cloned = originalClone();
             Object.defineProperty(cloned, 'url', { value: url, writable: false });
             Object.defineProperty(cloned, 'headers', {
-                value: new Headers(responseHeaders),
+                value: toResponseHeaders(responseHeaders),
                 writable: false
             });
             return cloned;