iboot-http-client 1.0.9 → 1.1.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/iboot-http-client.cjs.js +1 -1
- package/dist/iboot-http-client.cjs.js.map +1 -1
- package/dist/iboot-http-client.es.js +206 -191
- package/dist/iboot-http-client.es.js.map +1 -1
- package/dist/iboot-http-client.umd.js +1 -1
- package/dist/iboot-http-client.umd.js.map +1 -1
- package/dist/types/utils.d.ts +1 -0
- package/package.json +14 -3
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
import N from "pino";
|
|
2
|
+
import R from "pino-pretty";
|
|
2
3
|
import A from "js-md5";
|
|
3
|
-
import
|
|
4
|
-
const
|
|
4
|
+
import m from "crypto-js";
|
|
5
|
+
const H = {
|
|
5
6
|
GENERAL: 0,
|
|
6
7
|
PHONE: 1,
|
|
7
8
|
EMAIL: 2
|
|
8
|
-
},
|
|
9
|
+
}, U = {
|
|
9
10
|
TYPE_MGT: 0,
|
|
10
11
|
TYPE_C: 1,
|
|
11
12
|
TYPE_B: 2
|
|
12
|
-
},
|
|
13
|
+
}, j = {
|
|
13
14
|
FROM_WEB: 1,
|
|
14
15
|
FROM_PC: 2,
|
|
15
16
|
FROM_WX_MINI_PRO: 3,
|
|
@@ -17,47 +18,70 @@ const $ = {
|
|
|
17
18
|
FROM_WX_E: 5,
|
|
18
19
|
FROM_APP: 6,
|
|
19
20
|
FROM_DEVICE: 7
|
|
20
|
-
},
|
|
21
|
+
}, F = {
|
|
21
22
|
unknown: 0,
|
|
22
23
|
male: 1,
|
|
23
24
|
female: 2
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
|
|
25
|
+
}, M = R({
|
|
26
|
+
colorize: !0,
|
|
27
|
+
destination: process.stdout,
|
|
28
|
+
translateTime: "SYS:yyyy-mm-dd HH:MM:ss",
|
|
29
|
+
ignore: "pid,hostname",
|
|
30
|
+
messageFormat: "{msg}",
|
|
31
|
+
singleLine: !0
|
|
32
|
+
}), h = N({
|
|
27
33
|
name: process.env.APP_NAME ?? "iBoot",
|
|
28
|
-
level: process.env.NODE_ENV
|
|
29
|
-
nestedKey: "payload"
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
},
|
|
33
|
-
transport: {
|
|
34
|
-
target: "pino-pretty",
|
|
35
|
-
options: {
|
|
36
|
-
colorize: !0,
|
|
37
|
-
translateTime: "SYS:yyyy-mm-dd HH:MM:ss",
|
|
38
|
-
ignore: "pid,hostname",
|
|
39
|
-
messageFormat: "{msg}",
|
|
40
|
-
singleLine: !0
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
}), _ = (n) => Array.isArray(n) || typeof n == "object" && Object.prototype.toString.call(n) === "[object Array]", w = (n) => {
|
|
44
|
-
const t = n || 32, e = "ABCDEFGHJKMNPQRSTWXYZabcdefhijkmnprstwxyz2345678", s = e.length;
|
|
34
|
+
level: process.env.NODE_ENV !== "production" ? "debug" : "info",
|
|
35
|
+
nestedKey: "payload"
|
|
36
|
+
}, M), _ = (o) => Array.isArray(o) || typeof o == "object" && Object.prototype.toString.call(o) === "[object Array]", w = (o) => {
|
|
37
|
+
const t = o || 32, e = "ABCDEFGHJKMNPQRSTWXYZabcdefhijkmnprstwxyz2345678", s = e.length;
|
|
45
38
|
let r = "";
|
|
46
|
-
for (let
|
|
39
|
+
for (let n = 0; n < t; n++)
|
|
47
40
|
r += e.charAt(Math.floor(Math.random() * s));
|
|
48
41
|
return r;
|
|
49
|
-
},
|
|
42
|
+
}, k = (o, t) => {
|
|
50
43
|
const e = {};
|
|
51
|
-
return
|
|
52
|
-
const
|
|
53
|
-
|
|
44
|
+
return o.split("&").forEach((r) => {
|
|
45
|
+
const n = r.split("=");
|
|
46
|
+
n[1] && (!t || t.indexOf(n[0]) == -1) && (e[n[0]] = n[1]);
|
|
54
47
|
}), e;
|
|
55
|
-
}, b = (
|
|
48
|
+
}, b = (o) => !o || o == "" || o.length == 0 ? "" : encodeURIComponent(o).replace(/\(/g, "%28").replace(/\)/g, "%29").replace(/\'/g, "%27").replace(/\!/g, "%21").replace(/\~/g, "%7E"), K = (o, t) => {
|
|
49
|
+
const e = {
|
|
50
|
+
"M+": o.getMonth() + 1,
|
|
51
|
+
//月份
|
|
52
|
+
"d+": o.getDate(),
|
|
53
|
+
//日
|
|
54
|
+
"h+": o.getHours(),
|
|
55
|
+
//小时
|
|
56
|
+
"m+": o.getMinutes(),
|
|
57
|
+
//分
|
|
58
|
+
"s+": o.getSeconds(),
|
|
59
|
+
//秒
|
|
60
|
+
"q+": Math.floor((o.getMonth() + 3) / 3),
|
|
61
|
+
//季度
|
|
62
|
+
S: o.getMilliseconds()
|
|
63
|
+
//毫秒
|
|
64
|
+
};
|
|
65
|
+
if (/(y+)/.test(t)) {
|
|
66
|
+
const r = new RegExp(/(y+)/).exec(t);
|
|
67
|
+
let n = 0;
|
|
68
|
+
r && r.length > 0 && (n = r[0].length), t = t.replace(/(y+)/, o.getFullYear() + "").substring(4 - n);
|
|
69
|
+
}
|
|
70
|
+
for (const s in e) {
|
|
71
|
+
const r = "(" + s + ")", n = new RegExp(r);
|
|
72
|
+
if (n.test(t)) {
|
|
73
|
+
const i = n.exec(t);
|
|
74
|
+
let c = 0;
|
|
75
|
+
i && i.length > 0 && (c = i[0].length), t = t.replace(n, c == 1 ? e[s].toString() : ("00" + e[s]).substring(e[s].toString().length));
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
return t;
|
|
79
|
+
}, D = "zh-CN", O = "_device_id_key", v = "_current_website_key", S = "Get request error!", I = "Post request error!", T = {
|
|
56
80
|
"Device-Id": "Device-Id",
|
|
57
81
|
Lang: "Lang",
|
|
58
82
|
"Website-Id": "Website-Id",
|
|
59
83
|
"Website-No": "Website-No"
|
|
60
|
-
},
|
|
84
|
+
}, d = {
|
|
61
85
|
IBOOT_DEVICE_ID: "IBOOT_DEVICE_ID",
|
|
62
86
|
IBOOT_LOCALE: "IBOOT_LOCALE",
|
|
63
87
|
IBOOT_WEBSITE_ID: "IBOOT_WEBSITE_ID",
|
|
@@ -65,85 +89,79 @@ const h = N({
|
|
|
65
89
|
token: "token",
|
|
66
90
|
user: "user"
|
|
67
91
|
}, P = () => {
|
|
68
|
-
const
|
|
69
|
-
return
|
|
70
|
-
},
|
|
71
|
-
localStorage.setItem(
|
|
72
|
-
},
|
|
92
|
+
const o = localStorage.getItem(O) ?? "", t = localStorage.getItem(v), e = t != null ? JSON.parse(t) : null, s = {};
|
|
93
|
+
return o.length > 0 && (s["Device-Id"] = o), e && (s.Lang = e.language, e.websiteId && (s["Website-Id"] = e.websiteId), e.websiteNo && (s["Website-No"] = e.websiteNo)), s;
|
|
94
|
+
}, G = (o, t) => {
|
|
95
|
+
localStorage.setItem(O, o), t && localStorage.setItem(v, JSON.stringify(t));
|
|
96
|
+
}, L = async (o, t) => {
|
|
73
97
|
if (t?.data) {
|
|
74
98
|
const i = new URLSearchParams(t.data);
|
|
75
|
-
|
|
99
|
+
o.indexOf("?") != -1 ? o += `&${i}` : o += `?${i}`;
|
|
76
100
|
}
|
|
77
101
|
const e = P(), s = t?.headers;
|
|
78
102
|
if (s)
|
|
79
103
|
for (const i in s) {
|
|
80
|
-
const
|
|
81
|
-
|
|
104
|
+
const c = s[i];
|
|
105
|
+
c && (e[i] = c);
|
|
82
106
|
}
|
|
83
107
|
h.debug({
|
|
84
|
-
|
|
85
|
-
url: n,
|
|
108
|
+
url: o,
|
|
86
109
|
headers: e
|
|
87
|
-
});
|
|
88
|
-
const r = await fetch(
|
|
110
|
+
}, "GET");
|
|
111
|
+
const r = await fetch(o, {
|
|
89
112
|
method: "GET",
|
|
90
113
|
headers: e,
|
|
91
114
|
cache: t?.useCache ? "force-cache" : "default"
|
|
92
115
|
});
|
|
93
116
|
if (r.ok) {
|
|
94
117
|
const i = await r.json();
|
|
95
|
-
return h.debug(
|
|
96
|
-
GET_RESULT: i
|
|
97
|
-
}), i;
|
|
118
|
+
return h.debug(i, "GET_RESULT"), i;
|
|
98
119
|
}
|
|
99
|
-
const
|
|
120
|
+
const n = {
|
|
100
121
|
code: r.status,
|
|
101
122
|
success: !1,
|
|
102
123
|
msg: r.statusText
|
|
103
124
|
};
|
|
104
|
-
return h.error(
|
|
105
|
-
}, C = async (
|
|
125
|
+
return h.error(n), n;
|
|
126
|
+
}, C = async (o, t) => {
|
|
106
127
|
const e = t?.data ?? {}, s = t?.headers;
|
|
107
128
|
let r;
|
|
108
|
-
const
|
|
109
|
-
if (e instanceof FormData ? r = e : (r = JSON.stringify(e),
|
|
129
|
+
const n = new Headers(P());
|
|
130
|
+
if (e instanceof FormData ? r = e : (r = JSON.stringify(e), n.set("Content-Type", "application/json")), s)
|
|
110
131
|
for (let a in s) {
|
|
111
|
-
const
|
|
112
|
-
|
|
132
|
+
const l = s[a];
|
|
133
|
+
l && n.set(a, l);
|
|
113
134
|
}
|
|
114
135
|
h.debug({
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
const i = await fetch(n, {
|
|
136
|
+
url: o,
|
|
137
|
+
headers: n
|
|
138
|
+
}, "POST");
|
|
139
|
+
const i = await fetch(o, {
|
|
120
140
|
method: "POST",
|
|
121
|
-
headers:
|
|
141
|
+
headers: n,
|
|
122
142
|
body: r
|
|
123
143
|
});
|
|
124
144
|
if (i.ok) {
|
|
125
145
|
const a = await i.json();
|
|
126
|
-
return h.debug(
|
|
127
|
-
POST_RESULT: a
|
|
128
|
-
}), a;
|
|
146
|
+
return h.debug(a, "POST_RESULT"), a;
|
|
129
147
|
}
|
|
130
|
-
const
|
|
148
|
+
const c = {
|
|
131
149
|
code: i.status,
|
|
132
150
|
success: !1,
|
|
133
151
|
msg: i.statusText
|
|
134
152
|
};
|
|
135
|
-
return h.error(
|
|
136
|
-
},
|
|
137
|
-
const e = await
|
|
153
|
+
return h.error(c), c;
|
|
154
|
+
}, Y = async (o, t) => {
|
|
155
|
+
const e = await L(o, t);
|
|
138
156
|
if (e.success)
|
|
139
157
|
return e.data;
|
|
140
158
|
if (t?.showError) {
|
|
141
|
-
t.showError(e.msg ??
|
|
159
|
+
t.showError(e.msg ?? S);
|
|
142
160
|
return;
|
|
143
161
|
}
|
|
144
|
-
throw Error(e.msg ??
|
|
145
|
-
},
|
|
146
|
-
const e = await C(
|
|
162
|
+
throw Error(e.msg ?? S);
|
|
163
|
+
}, J = async (o, t) => {
|
|
164
|
+
const e = await C(o, t);
|
|
147
165
|
if (e.success)
|
|
148
166
|
return e.data;
|
|
149
167
|
if (t?.showError) {
|
|
@@ -151,17 +169,17 @@ const h = N({
|
|
|
151
169
|
return;
|
|
152
170
|
}
|
|
153
171
|
throw Error(e.msg ?? I);
|
|
154
|
-
},
|
|
155
|
-
const e = await C(
|
|
172
|
+
}, V = async (o, t) => {
|
|
173
|
+
const e = await C(o, t);
|
|
156
174
|
return e.success ? (t?.showSuccess && t.showSuccess(e.msg ?? "SUCCESS"), !0) : (t?.showError && t.showError(e.msg ?? I), !1);
|
|
157
|
-
},
|
|
158
|
-
const t =
|
|
159
|
-
return t && t.length > 0 && (
|
|
160
|
-
},
|
|
161
|
-
const t = {}, e =
|
|
162
|
-
return e && e.length > 0 && (t.deviceId = e), s && s.length > 0 && (t.lang = s), r && r.length > 0 && (t.websiteId = r),
|
|
175
|
+
}, X = (o) => {
|
|
176
|
+
const t = o.headers.get(T["Device-Id"]), e = o.headers.get(T.Lang), s = o.headers.get(T["Website-Id"]), r = o.headers.get(T["Website-No"]), n = {};
|
|
177
|
+
return t && t.length > 0 && (n.deviceId = t), e && e.length > 0 && (n.lang = e), s && s.length > 0 && (n.websiteId = s), r && r.length > 0 && (n.websiteNo = r), n;
|
|
178
|
+
}, z = (o) => {
|
|
179
|
+
const t = {}, e = o.get(d.IBOOT_DEVICE_ID)?.value, s = o.get(d.IBOOT_LOCALE)?.value, r = o.get(d.IBOOT_WEBSITE_ID)?.value, n = o.get(d.IBOOT_WEBSITE_NO)?.value;
|
|
180
|
+
return e && e.length > 0 && (t.deviceId = e), s && s.length > 0 && (t.lang = s), r && r.length > 0 && (t.websiteId = r), n && n.length > 0 && (t.websiteNo = n), t;
|
|
163
181
|
};
|
|
164
|
-
class
|
|
182
|
+
class q {
|
|
165
183
|
baseUrl;
|
|
166
184
|
helloMethod;
|
|
167
185
|
apiKey;
|
|
@@ -173,21 +191,21 @@ class Y {
|
|
|
173
191
|
websiteId;
|
|
174
192
|
websiteNo;
|
|
175
193
|
_isDebug;
|
|
176
|
-
constructor({ deviceId: t, lang: e, websiteId: s, websiteNo: r, userType:
|
|
177
|
-
this.baseUrl = process.env.BASE_URL ?? "", this.helloMethod = i ?? "", this.apiKey = process.env.API_KEY ?? "", this.userType =
|
|
194
|
+
constructor({ deviceId: t, lang: e, websiteId: s, websiteNo: r, userType: n, helloURL: i }) {
|
|
195
|
+
this.baseUrl = process.env.BASE_URL ?? "", this.helloMethod = i ?? "", this.apiKey = process.env.API_KEY ?? "", this.userType = n ?? U.TYPE_MGT, this.userFrom = process.env.USER_FROM || "1", this.deviceId = t ?? w(10), this.lang = e ?? D, this.websiteId = s, this.websiteNo = r, this._isDebug = process.env.NODE_ENV != "production";
|
|
178
196
|
}
|
|
179
197
|
isDebug() {
|
|
180
198
|
return this._isDebug;
|
|
181
199
|
}
|
|
182
200
|
encrypt(t) {
|
|
183
|
-
const e =
|
|
184
|
-
return
|
|
201
|
+
const e = m.enc.Utf8.parse(this.apiKey);
|
|
202
|
+
return m.AES.encrypt(t, e).toString();
|
|
185
203
|
}
|
|
186
204
|
decrypt(t) {
|
|
187
|
-
const e =
|
|
188
|
-
return
|
|
189
|
-
mode:
|
|
190
|
-
}).toString(
|
|
205
|
+
const e = m.enc.Utf8.parse(this.apiKey);
|
|
206
|
+
return m.AES.decrypt(t, e, {
|
|
207
|
+
mode: m.mode.ECB
|
|
208
|
+
}).toString(m.enc.Utf8);
|
|
191
209
|
}
|
|
192
210
|
getDeviceId() {
|
|
193
211
|
return this.deviceId;
|
|
@@ -203,35 +221,35 @@ class Y {
|
|
|
203
221
|
if (_(r)) {
|
|
204
222
|
if (r.length === 0)
|
|
205
223
|
continue;
|
|
206
|
-
for (let
|
|
207
|
-
const i = r[
|
|
208
|
-
for (const
|
|
209
|
-
const a = i[
|
|
224
|
+
for (let n = 0; n < r.length; n++) {
|
|
225
|
+
const i = r[n];
|
|
226
|
+
for (const c in i) {
|
|
227
|
+
const a = i[c] ?? void 0;
|
|
210
228
|
if (a) {
|
|
211
229
|
if (typeof a == "object")
|
|
212
|
-
_(a) && a.forEach((
|
|
213
|
-
if (
|
|
214
|
-
for (const
|
|
215
|
-
const
|
|
216
|
-
if (
|
|
217
|
-
const
|
|
218
|
-
e.push(s +
|
|
230
|
+
_(a) && a.forEach((l, u) => {
|
|
231
|
+
if (l)
|
|
232
|
+
for (const f in l) {
|
|
233
|
+
const g = l[f];
|
|
234
|
+
if (g && g.toString().length > 0) {
|
|
235
|
+
const p = `[${n.toString()}].${c + `[${u.toString()}].${f}`}=${b(g)}`;
|
|
236
|
+
e.push(s + p);
|
|
219
237
|
}
|
|
220
238
|
}
|
|
221
239
|
});
|
|
222
240
|
else if (a.toString().length > 0) {
|
|
223
|
-
const
|
|
224
|
-
e.push(s +
|
|
241
|
+
const l = `[${n.toString()}].${c}=${b(a.toString())}`;
|
|
242
|
+
e.push(s + l);
|
|
225
243
|
}
|
|
226
244
|
}
|
|
227
245
|
}
|
|
228
246
|
}
|
|
229
247
|
} else
|
|
230
|
-
for (const
|
|
231
|
-
const i = r[
|
|
248
|
+
for (const n in r) {
|
|
249
|
+
const i = r[n];
|
|
232
250
|
if (i != null && i != "" && i.length != 0) {
|
|
233
|
-
const
|
|
234
|
-
e.push(s +
|
|
251
|
+
const c = `.${n}=${b(i)}`;
|
|
252
|
+
e.push(s + c);
|
|
235
253
|
}
|
|
236
254
|
}
|
|
237
255
|
continue;
|
|
@@ -244,18 +262,17 @@ class Y {
|
|
|
244
262
|
const e = "&key=" + await this.helloIboot(), s = [];
|
|
245
263
|
for (const a in t)
|
|
246
264
|
s.push(a);
|
|
247
|
-
s.sort((a,
|
|
265
|
+
s.sort((a, l) => a.toLowerCase().localeCompare(l.toLowerCase()));
|
|
248
266
|
const r = [];
|
|
249
267
|
s.forEach((a) => {
|
|
250
|
-
let
|
|
251
|
-
typeof
|
|
268
|
+
let l = t[a];
|
|
269
|
+
typeof l == "object" && (l = JSON.stringify(l)), r.push(a + "=" + l);
|
|
252
270
|
});
|
|
253
|
-
const
|
|
254
|
-
|
|
255
|
-
params: o,
|
|
271
|
+
const n = r.join("&"), i = A.md5((n + e).toLocaleUpperCase()), c = {
|
|
272
|
+
params: n,
|
|
256
273
|
md5: i
|
|
257
274
|
};
|
|
258
|
-
return h.debug(
|
|
275
|
+
return h.debug(c, "API_SIGN"), i;
|
|
259
276
|
}
|
|
260
277
|
//eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
261
278
|
assemblyParameter(t, e) {
|
|
@@ -272,8 +289,8 @@ class Y {
|
|
|
272
289
|
"Api-Key": this.apiKey
|
|
273
290
|
};
|
|
274
291
|
this.lang && this.lang.length > 0 && (s.Lang = this.lang), this.websiteId && this.websiteId.length > 0 && (s["Web-Id"] = this.websiteId), this.websiteNo && this.websiteNo.length > 0 && (s["Web-No"] = this.websiteNo), e && (e.token && e.token.length > 0 && e.username && e.username.length > 0 && (s.Authorization = e.token, s.Username = e.username), e.xcsrf && (s[e.xcsrf.csrfHeader] = e.xcsrf.csrfToken));
|
|
275
|
-
const r =
|
|
276
|
-
return s.Sign =
|
|
292
|
+
const r = k(t), n = await this.sign(r);
|
|
293
|
+
return s.Sign = n, s;
|
|
277
294
|
}
|
|
278
295
|
async helloIboot() {
|
|
279
296
|
if (this.helloMethod.length <= 0)
|
|
@@ -286,7 +303,7 @@ class Y {
|
|
|
286
303
|
url: t,
|
|
287
304
|
headers: e
|
|
288
305
|
};
|
|
289
|
-
h.debug(s);
|
|
306
|
+
h.debug(s, "HELLO");
|
|
290
307
|
const r = await fetch(t, {
|
|
291
308
|
method: "GET",
|
|
292
309
|
headers: e,
|
|
@@ -294,8 +311,8 @@ class Y {
|
|
|
294
311
|
cache: "force-cache"
|
|
295
312
|
});
|
|
296
313
|
if (r.ok) {
|
|
297
|
-
const
|
|
298
|
-
return h.debug(
|
|
314
|
+
const n = await r.json();
|
|
315
|
+
return h.debug(n.data, "HELLO RESULT"), n.data;
|
|
299
316
|
}
|
|
300
317
|
throw new Error("hello iBoot error!");
|
|
301
318
|
}
|
|
@@ -314,88 +331,85 @@ class Y {
|
|
|
314
331
|
}
|
|
315
332
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
316
333
|
async get({ url: t, data: e, token: s, cache: r = "default" }) {
|
|
317
|
-
const
|
|
318
|
-
method: "GET",
|
|
334
|
+
const n = this.assemblyParameter(e), i = this.convertUrlParameter(n), c = await this.assemblyHeader({ urlParams: i, token: s }), a = `${this.getApiUrl(t)}?${i.toString()}`, l = {
|
|
319
335
|
url: a,
|
|
320
|
-
headers:
|
|
336
|
+
headers: c
|
|
321
337
|
};
|
|
322
|
-
h.info(
|
|
338
|
+
h.info(l, "GET");
|
|
323
339
|
const u = await fetch(a, {
|
|
324
340
|
method: "GET",
|
|
325
|
-
headers:
|
|
341
|
+
headers: c,
|
|
326
342
|
credentials: "include",
|
|
327
343
|
cache: r
|
|
328
344
|
});
|
|
329
345
|
if (u.ok) {
|
|
330
|
-
const
|
|
331
|
-
return h.debug(
|
|
346
|
+
const g = await u.json();
|
|
347
|
+
return h.debug(g, "GET_RESULT"), g;
|
|
332
348
|
}
|
|
333
|
-
const
|
|
349
|
+
const f = {
|
|
334
350
|
code: u.status,
|
|
335
351
|
success: !1,
|
|
336
352
|
msg: u.statusText
|
|
337
353
|
};
|
|
338
|
-
return h.error(
|
|
354
|
+
return h.error(f), f;
|
|
339
355
|
}
|
|
340
356
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
341
357
|
async post({ url: t, data: e, token: s, cache: r = "default" }) {
|
|
342
358
|
e = e ? { ...e } : {};
|
|
343
|
-
const
|
|
344
|
-
|
|
345
|
-
const
|
|
346
|
-
|
|
347
|
-
const u = this.getApiUrl(t),
|
|
348
|
-
method: "POST",
|
|
359
|
+
const n = e.buffer ?? void 0, i = e.boundary ?? void 0;
|
|
360
|
+
n && delete e.buffer, i && delete e.boundary;
|
|
361
|
+
const c = this.assemblyParameter(e), a = this.convertUrlParameter(c), l = await this.assemblyHeader({ urlParams: a, token: s });
|
|
362
|
+
n && i && (l["Content-Type"] = `multipart/form-data; boundary=${i}`);
|
|
363
|
+
const u = this.getApiUrl(t), f = {
|
|
349
364
|
url: u,
|
|
350
|
-
headers:
|
|
351
|
-
params:
|
|
365
|
+
headers: l,
|
|
366
|
+
params: c
|
|
352
367
|
};
|
|
353
|
-
h.info(
|
|
354
|
-
const
|
|
368
|
+
h.info(f, "POST");
|
|
369
|
+
const g = n ? `${u}?${a}` : u, p = await fetch(g, {
|
|
355
370
|
method: "POST",
|
|
356
|
-
headers:
|
|
357
|
-
body:
|
|
371
|
+
headers: l,
|
|
372
|
+
body: n || a.toString(),
|
|
358
373
|
credentials: "include",
|
|
359
374
|
cache: r
|
|
360
375
|
});
|
|
361
|
-
if (
|
|
362
|
-
const E = await
|
|
363
|
-
return h.debug(
|
|
376
|
+
if (p.ok) {
|
|
377
|
+
const E = await p.json();
|
|
378
|
+
return h.debug(E, "POST_RESULT"), E;
|
|
364
379
|
}
|
|
365
380
|
const y = {
|
|
366
|
-
code:
|
|
381
|
+
code: p.status,
|
|
367
382
|
success: !1,
|
|
368
|
-
msg:
|
|
383
|
+
msg: p.statusText
|
|
369
384
|
};
|
|
370
385
|
return h.error(y), y;
|
|
371
386
|
}
|
|
372
387
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
373
388
|
async stream({ url: t, data: e, token: s }) {
|
|
374
389
|
e = e ? { ...e } : {};
|
|
375
|
-
const r = e.buffer ?? void 0,
|
|
376
|
-
r && delete e.buffer,
|
|
377
|
-
const i = this.assemblyParameter(e),
|
|
378
|
-
r &&
|
|
379
|
-
const
|
|
390
|
+
const r = e.buffer ?? void 0, n = e.boundary ?? void 0;
|
|
391
|
+
r && delete e.buffer, n && delete e.boundary;
|
|
392
|
+
const i = this.assemblyParameter(e), c = this.convertUrlParameter(i), a = await this.assemblyHeader({ urlParams: c, token: s });
|
|
393
|
+
r && n && (a["Content-Type"] = `multipart/form-data; boundary=${n}`), a.Connection = "keep-alive", a["X-Accel-Buffering"] = "no", a["Cache-Control"] = "no-cache";
|
|
394
|
+
const l = this.getApiUrl(t);
|
|
380
395
|
try {
|
|
381
|
-
const u = r ? `${
|
|
382
|
-
|
|
383
|
-
url: c,
|
|
396
|
+
const u = r ? `${l}?${c}` : l, f = {
|
|
397
|
+
url: l,
|
|
384
398
|
headers: a,
|
|
385
399
|
params: i
|
|
386
400
|
};
|
|
387
|
-
h.info(
|
|
388
|
-
const
|
|
401
|
+
h.info(f, "STREAM");
|
|
402
|
+
const g = await fetch(u, {
|
|
389
403
|
method: "POST",
|
|
390
404
|
headers: a,
|
|
391
|
-
body: r ||
|
|
405
|
+
body: r || c.toString(),
|
|
392
406
|
credentials: "include"
|
|
393
407
|
});
|
|
394
|
-
if (!
|
|
395
|
-
throw new Error(`HTTP error! status: ${
|
|
396
|
-
if (!
|
|
408
|
+
if (!g.ok)
|
|
409
|
+
throw new Error(`HTTP error! status: ${g.status}`);
|
|
410
|
+
if (!g.body)
|
|
397
411
|
throw new Error("No response body");
|
|
398
|
-
return new Response(
|
|
412
|
+
return new Response(g.body, {
|
|
399
413
|
headers: {
|
|
400
414
|
"Content-Type": "text/event-stream",
|
|
401
415
|
"Cache-Control": "no-cache",
|
|
@@ -407,48 +421,48 @@ class Y {
|
|
|
407
421
|
}
|
|
408
422
|
}
|
|
409
423
|
getUserInfo(t) {
|
|
410
|
-
const e = t.get(
|
|
424
|
+
const e = t.get(d.user)?.value;
|
|
411
425
|
return e && e.length > 0 ? JSON.parse(e) : null;
|
|
412
426
|
}
|
|
413
427
|
getToken(t) {
|
|
414
428
|
const e = t.get("user")?.value;
|
|
415
429
|
let s = "", r = this.userType;
|
|
416
430
|
if (e && e.length > 0) {
|
|
417
|
-
const
|
|
418
|
-
s =
|
|
431
|
+
const n = JSON.parse(e);
|
|
432
|
+
s = n.username, r = n.userType.toString();
|
|
419
433
|
}
|
|
420
434
|
return {
|
|
421
435
|
username: s,
|
|
422
436
|
utype: r,
|
|
423
|
-
token: t.get(
|
|
437
|
+
token: t.get(d.token)?.value ?? ""
|
|
424
438
|
};
|
|
425
439
|
}
|
|
426
440
|
getTokenByCookies = (t) => {
|
|
427
441
|
const e = t.get("user")?.value;
|
|
428
442
|
let s = "", r = this.userType;
|
|
429
443
|
if (e && e.length > 0) {
|
|
430
|
-
const
|
|
431
|
-
s =
|
|
444
|
+
const n = JSON.parse(e);
|
|
445
|
+
s = n.username, r = n.userType.toString();
|
|
432
446
|
}
|
|
433
447
|
return {
|
|
434
448
|
username: s,
|
|
435
449
|
utype: r,
|
|
436
|
-
token: t.get(
|
|
450
|
+
token: t.get(d.token)?.value ?? ""
|
|
437
451
|
};
|
|
438
452
|
};
|
|
439
453
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
440
454
|
setToken(t, e) {
|
|
441
|
-
const { id: s, name: r, username:
|
|
455
|
+
const { id: s, name: r, username: n, nickname: i, sex: c, headImg: a, token: l, lastLoginTime: u, tokenExpired: f, deviceId: g, userType: p, mustChangePwd: y } = t, E = {
|
|
442
456
|
id: s,
|
|
443
457
|
name: r,
|
|
444
|
-
username:
|
|
458
|
+
username: n,
|
|
445
459
|
nickname: i,
|
|
446
|
-
sex:
|
|
460
|
+
sex: c,
|
|
447
461
|
headImg: a,
|
|
448
462
|
lastLoginTime: u,
|
|
449
|
-
tokenExpired:
|
|
450
|
-
deviceId:
|
|
451
|
-
userType:
|
|
463
|
+
tokenExpired: f,
|
|
464
|
+
deviceId: g,
|
|
465
|
+
userType: p,
|
|
452
466
|
status: 0,
|
|
453
467
|
accountType: 0,
|
|
454
468
|
enabled: !1,
|
|
@@ -458,7 +472,7 @@ class Y {
|
|
|
458
472
|
createTime: "",
|
|
459
473
|
mustChangePwd: y
|
|
460
474
|
};
|
|
461
|
-
return e.cookies.set(
|
|
475
|
+
return e.cookies.set(d.token, l, {
|
|
462
476
|
httpOnly: !0,
|
|
463
477
|
secure: !this._isDebug,
|
|
464
478
|
// 在生产环境中启用Secure
|
|
@@ -466,43 +480,44 @@ class Y {
|
|
|
466
480
|
// 防止 CSRF 攻击
|
|
467
481
|
path: "/"
|
|
468
482
|
// Cookie 的路径
|
|
469
|
-
}), e.cookies.set(
|
|
483
|
+
}), e.cookies.set(d.user, JSON.stringify(E)), e;
|
|
470
484
|
}
|
|
471
485
|
cleanToken(t) {
|
|
472
|
-
return t.cookies.set(
|
|
486
|
+
return t.cookies.set(d.token, "", {
|
|
473
487
|
maxAge: -1,
|
|
474
488
|
//设置为 -1表示立即过期
|
|
475
489
|
httpOnly: !0,
|
|
476
490
|
path: "/"
|
|
477
|
-
}), t.cookies.set(
|
|
491
|
+
}), t.cookies.set(d.user, "", {
|
|
478
492
|
maxAge: -1,
|
|
479
493
|
//设置为 -1表示立即过期
|
|
480
494
|
httpOnly: !0,
|
|
481
495
|
path: "/"
|
|
482
|
-
}), t.cookies.delete(
|
|
496
|
+
}), t.cookies.delete(d.token), t.cookies.delete(d.user), t;
|
|
483
497
|
}
|
|
484
498
|
}
|
|
485
499
|
export {
|
|
486
|
-
|
|
500
|
+
H as ACCOUNT_TYPE_MAP,
|
|
487
501
|
v as CURRENT_WEBSITE_KEY,
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
502
|
+
D as DEFAULT_LOCALE,
|
|
503
|
+
O as DEVICE_ID_KEY,
|
|
504
|
+
q as HttpClient,
|
|
505
|
+
j as USER_FORM_MAP,
|
|
506
|
+
F as USER_SEX_MAP,
|
|
507
|
+
U as USER_TYPE_MAP,
|
|
508
|
+
K as dateFormat,
|
|
509
|
+
L as get,
|
|
510
|
+
X as getHttpClientOpts,
|
|
511
|
+
z as getHttpClientOptsByCookie,
|
|
512
|
+
Y as iGet,
|
|
513
|
+
J as iPost,
|
|
514
|
+
V as iPostSuccess,
|
|
500
515
|
_ as isArray,
|
|
501
516
|
h as logger,
|
|
502
517
|
C as post,
|
|
503
518
|
w as randomString,
|
|
504
|
-
|
|
519
|
+
G as setDefaultRequestHeader,
|
|
505
520
|
b as urlEncode,
|
|
506
|
-
|
|
521
|
+
k as urlParamToJson
|
|
507
522
|
};
|
|
508
523
|
//# sourceMappingURL=iboot-http-client.es.js.map
|