@seayoo-web/request 3.5.0 → 3.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +11 -12
- package/dist/node.js +1 -1
- package/dist/request.fetch-BHmmkAon.js +48 -0
- package/package.json +1 -1
- package/dist/request.fetch-U_igg1Ax.js +0 -49
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { h as m, r as q, R as T, c as x, H as R, a as w, v as E, b as C, N as H, X as L } from "./retry-DodVI8cA.js";
|
|
2
2
|
import { g as Q } from "./retry-DodVI8cA.js";
|
|
3
|
-
import { f as v } from "./request.fetch-
|
|
3
|
+
import { f as v } from "./request.fetch-BHmmkAon.js";
|
|
4
4
|
const j = async function(t, s, e) {
|
|
5
5
|
return m(await q(y, t, s, e), t, s, e);
|
|
6
6
|
};
|
|
@@ -16,31 +16,31 @@ async function k(t, s, e, n) {
|
|
|
16
16
|
}
|
|
17
17
|
const a = new FormData(), d = { ...s };
|
|
18
18
|
r instanceof Object && Object.entries(r).forEach(([i, u]) => {
|
|
19
|
-
u instanceof Blob ? d[i] = u : Array.isArray(u) ? u.forEach((o,
|
|
20
|
-
a.append(`${i}[${
|
|
19
|
+
u instanceof Blob ? d[i] = u : Array.isArray(u) ? u.forEach((o, h) => {
|
|
20
|
+
a.append(`${i}[${h}]`, String(o));
|
|
21
21
|
}) : a.append(i, String(u));
|
|
22
22
|
});
|
|
23
23
|
for (const i in d)
|
|
24
24
|
a.append(i, d[i]);
|
|
25
|
-
const b = new T(n),
|
|
25
|
+
const b = new T(n), g = await y(t, b, {
|
|
26
26
|
...e,
|
|
27
27
|
method: l,
|
|
28
28
|
body: a
|
|
29
29
|
});
|
|
30
|
-
return m(
|
|
30
|
+
return m(g, t, b, e);
|
|
31
31
|
}
|
|
32
32
|
const y = async function(t, s, e) {
|
|
33
33
|
const n = await x(t, s, e), r = n.method, l = e?.onUploadProgress, a = R(n.url, n.params);
|
|
34
34
|
return await new Promise((d) => {
|
|
35
|
-
let b = null,
|
|
35
|
+
let b = null, g = !1;
|
|
36
36
|
const i = function() {
|
|
37
|
-
|
|
37
|
+
g || (o.abort(), g = !0);
|
|
38
38
|
};
|
|
39
39
|
function u() {
|
|
40
40
|
b !== null && clearTimeout(b), n.abort && n.abort.removeEventListener("abort", i);
|
|
41
41
|
}
|
|
42
42
|
const o = new XMLHttpRequest();
|
|
43
|
-
let
|
|
43
|
+
let h = !1;
|
|
44
44
|
if (o.open(r, a, !0), l) {
|
|
45
45
|
let f = 1;
|
|
46
46
|
o.upload.addEventListener("progress", (p) => {
|
|
@@ -76,15 +76,14 @@ const y = async function(t, s, e) {
|
|
|
76
76
|
u(), d({
|
|
77
77
|
url: a,
|
|
78
78
|
method: r,
|
|
79
|
-
status:
|
|
80
|
-
|
|
81
|
-
statusText: g ? w.Timeout : w.Aborted,
|
|
79
|
+
status: -1,
|
|
80
|
+
statusText: h ? w.Timeout : w.Aborted,
|
|
82
81
|
body: ""
|
|
83
82
|
});
|
|
84
83
|
}), Object.entries(n.headers).forEach(([f, p]) => {
|
|
85
84
|
o.setRequestHeader(f, p);
|
|
86
85
|
}), n.credentials === "include" && (o.withCredentials = !0), o.send(n.body || void 0), n.abort && n.abort.addEventListener("abort", i), n.timeout > 0 && (b = setTimeout(function() {
|
|
87
|
-
|
|
86
|
+
h = !0, i();
|
|
88
87
|
}, n.timeout));
|
|
89
88
|
});
|
|
90
89
|
};
|
package/dist/node.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { h as b, r as q, c as w, n as g, a as d, f as E, N as f, X as x } from "./retry-DodVI8cA.js";
|
|
2
2
|
import { g as z } from "./retry-DodVI8cA.js";
|
|
3
|
-
import { f as C } from "./request.fetch-
|
|
3
|
+
import { f as C } from "./request.fetch-BHmmkAon.js";
|
|
4
4
|
import N from "node:http";
|
|
5
5
|
import T from "node:https";
|
|
6
6
|
const j = async function(o, a, u) {
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { h as w, r as y, c as E, d as T, f as g, a as c } from "./retry-DodVI8cA.js";
|
|
2
|
+
const x = async function(o, a, s) {
|
|
3
|
+
return w(await y(R, o, a, s), o, a, s);
|
|
4
|
+
}, R = async function(o, a, s) {
|
|
5
|
+
const t = await E(o, a, s), n = new URL(t.url), u = t.params;
|
|
6
|
+
u instanceof Object && Object.keys(u).forEach((e) => n.searchParams.set(e, u[e]));
|
|
7
|
+
const r = T() ? new AbortController() : null;
|
|
8
|
+
function d(e) {
|
|
9
|
+
r && !r.signal.aborted && r.abort(e);
|
|
10
|
+
}
|
|
11
|
+
t.abort && t.abort.addEventListener("abort", d);
|
|
12
|
+
let h = !1;
|
|
13
|
+
const b = t.timeout > 0 ? setTimeout(function() {
|
|
14
|
+
h = !0, d("TimeoutTriggered");
|
|
15
|
+
}, t.timeout) : null, m = t.method === "HEAD";
|
|
16
|
+
return await fetch(n, {
|
|
17
|
+
method: t.method,
|
|
18
|
+
headers: Object.keys(t.headers).length > 0 ? new Headers(t.headers) : void 0,
|
|
19
|
+
body: t.body,
|
|
20
|
+
credentials: t.credentials,
|
|
21
|
+
signal: r?.signal,
|
|
22
|
+
redirect: "follow"
|
|
23
|
+
}).then(async (e) => {
|
|
24
|
+
const i = {
|
|
25
|
+
url: n.toString(),
|
|
26
|
+
method: t.method,
|
|
27
|
+
status: e.status,
|
|
28
|
+
statusText: e.statusText,
|
|
29
|
+
headers: g([...e.headers.entries()])
|
|
30
|
+
}, l = m || e.status === 204 ? "" : await e.text().catch((f) => f);
|
|
31
|
+
return l instanceof Error ? { ...i, body: "", statusText: c.Unknown, rawError: l } : { ...i, body: l };
|
|
32
|
+
}).catch((e) => {
|
|
33
|
+
const i = r?.signal.aborted;
|
|
34
|
+
return {
|
|
35
|
+
url: n.toString(),
|
|
36
|
+
method: t.method,
|
|
37
|
+
status: -1,
|
|
38
|
+
statusText: h ? c.Timeout : i ? c.Aborted : c.NetworkError,
|
|
39
|
+
body: "",
|
|
40
|
+
rawError: e
|
|
41
|
+
};
|
|
42
|
+
}).finally(() => {
|
|
43
|
+
b !== null && clearTimeout(b), t.abort && t.abort.removeEventListener("abort", d);
|
|
44
|
+
});
|
|
45
|
+
};
|
|
46
|
+
export {
|
|
47
|
+
x as f
|
|
48
|
+
};
|
package/package.json
CHANGED
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
import { h as w, r as y, c as E, d as T, f as R, a as c } from "./retry-DodVI8cA.js";
|
|
2
|
-
const x = async function(a, s, n) {
|
|
3
|
-
return w(await y(g, a, s, n), a, s, n);
|
|
4
|
-
}, g = async function(a, s, n) {
|
|
5
|
-
const t = await E(a, s, n), i = new URL(t.url), u = t.params;
|
|
6
|
-
u instanceof Object && Object.keys(u).forEach((e) => i.searchParams.set(e, u[e]));
|
|
7
|
-
const r = T() ? new AbortController() : null;
|
|
8
|
-
function d() {
|
|
9
|
-
r && !r.signal.aborted && r.abort();
|
|
10
|
-
}
|
|
11
|
-
t.abort && t.abort.addEventListener("abort", d);
|
|
12
|
-
let l = !1;
|
|
13
|
-
const b = t.timeout > 0 ? setTimeout(function() {
|
|
14
|
-
l = !0, d();
|
|
15
|
-
}, t.timeout) : null, f = t.method === "HEAD";
|
|
16
|
-
return await fetch(i, {
|
|
17
|
-
method: t.method,
|
|
18
|
-
headers: Object.keys(t.headers).length > 0 ? new Headers(t.headers) : void 0,
|
|
19
|
-
body: t.body,
|
|
20
|
-
credentials: t.credentials,
|
|
21
|
-
signal: r?.signal,
|
|
22
|
-
redirect: "follow"
|
|
23
|
-
}).then(async (e) => {
|
|
24
|
-
const o = {
|
|
25
|
-
url: i.toString(),
|
|
26
|
-
method: t.method,
|
|
27
|
-
status: e.status,
|
|
28
|
-
statusText: e.statusText,
|
|
29
|
-
headers: R([...e.headers.entries()])
|
|
30
|
-
}, h = f || e.status === 204 ? "" : await e.text().catch((m) => m);
|
|
31
|
-
return h instanceof Error ? { ...o, body: "", statusText: c.Unknown, rawError: h } : { ...o, body: h };
|
|
32
|
-
}).catch((e) => {
|
|
33
|
-
const o = r?.signal.aborted;
|
|
34
|
-
return {
|
|
35
|
-
url: i.toString(),
|
|
36
|
-
method: t.method,
|
|
37
|
-
status: o && !l ? 0 : -1,
|
|
38
|
-
// 设置为 0 可以防止自动重试的默认策略
|
|
39
|
-
statusText: l ? c.Timeout : o ? c.Aborted : c.NetworkError,
|
|
40
|
-
body: "",
|
|
41
|
-
rawError: e
|
|
42
|
-
};
|
|
43
|
-
}).finally(() => {
|
|
44
|
-
b !== null && clearTimeout(b), t.abort && t.abort.removeEventListener("abort", d);
|
|
45
|
-
});
|
|
46
|
-
};
|
|
47
|
-
export {
|
|
48
|
-
x as f
|
|
49
|
-
};
|