@base-web-kits/base-tools-web 1.1.0 → 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/base-tools-web.umd.global.js +53 -3
- package/dist/base-tools-web.umd.global.js.map +1 -1
- package/dist/index.cjs +53 -3
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +53 -3
- package/dist/index.js.map +1 -1
- package/dist/network/request.d.ts +2 -2
- package/dist/network/request.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/web/network/request.ts +73 -10
package/dist/index.cjs
CHANGED
|
@@ -1560,7 +1560,7 @@ function request(config) {
|
|
|
1560
1560
|
let chunkCallback = null;
|
|
1561
1561
|
const task = {
|
|
1562
1562
|
abort: () => controller.abort(),
|
|
1563
|
-
|
|
1563
|
+
onProgressUpdate: (cb) => {
|
|
1564
1564
|
chunkCallback = cb;
|
|
1565
1565
|
},
|
|
1566
1566
|
offChunkReceived: () => {
|
|
@@ -1593,11 +1593,27 @@ function request(config) {
|
|
|
1593
1593
|
const isArrayData = !isObjectData && Array.isArray(data);
|
|
1594
1594
|
const fillData = isObjectData ? (0, ts_exports.pickBy)(data, (val) => val !== void 0) : data;
|
|
1595
1595
|
const fillHeader = header ? (0, ts_exports.pickBy)(header, (val) => !!val) : {};
|
|
1596
|
-
|
|
1596
|
+
const contentTypeKey = Object.keys(fillHeader).find(
|
|
1597
|
+
(k) => k.toLowerCase() === "content-type"
|
|
1598
|
+
);
|
|
1599
|
+
const contentType = contentTypeKey ? fillHeader[contentTypeKey].toLowerCase() : "";
|
|
1600
|
+
if (!isGet && fillData && (isObjectData || isArrayData) && !contentType) {
|
|
1597
1601
|
fillHeader["Content-Type"] = "application/json";
|
|
1598
1602
|
}
|
|
1599
1603
|
const fillUrl = isGet && isObjectData ? appendUrlParam(url, fillData) : url;
|
|
1600
|
-
|
|
1604
|
+
let fillBody;
|
|
1605
|
+
if (!isGet && fillData) {
|
|
1606
|
+
if (isObjectData && contentType.includes("application/x-www-form-urlencoded")) {
|
|
1607
|
+
fillBody = toSearchParams(fillData);
|
|
1608
|
+
} else if (isObjectData && contentType.includes("multipart/form-data")) {
|
|
1609
|
+
fillBody = toFormData(fillData);
|
|
1610
|
+
if (contentTypeKey) delete fillHeader[contentTypeKey];
|
|
1611
|
+
} else if (isObjectData || isArrayData) {
|
|
1612
|
+
fillBody = JSON.stringify(fillData);
|
|
1613
|
+
} else {
|
|
1614
|
+
fillBody = fillData;
|
|
1615
|
+
}
|
|
1616
|
+
}
|
|
1601
1617
|
const logConfig = { ...config, data: fillData, header: fillHeader, url: fillUrl };
|
|
1602
1618
|
const startTime = Date.now();
|
|
1603
1619
|
const isCache = cacheTime && cacheTime > 0;
|
|
@@ -1752,6 +1768,40 @@ async function parseResponse(response, responseType) {
|
|
|
1752
1768
|
}
|
|
1753
1769
|
return resData;
|
|
1754
1770
|
}
|
|
1771
|
+
function toSearchParams(data) {
|
|
1772
|
+
const params = new URLSearchParams();
|
|
1773
|
+
for (const key in data) {
|
|
1774
|
+
const val = data[key];
|
|
1775
|
+
if (val === null) continue;
|
|
1776
|
+
if (Array.isArray(val)) {
|
|
1777
|
+
val.forEach((v) => params.append(key, typeof v === "object" ? JSON.stringify(v) : String(v)));
|
|
1778
|
+
} else {
|
|
1779
|
+
params.append(key, typeof val === "object" ? JSON.stringify(val) : String(val));
|
|
1780
|
+
}
|
|
1781
|
+
}
|
|
1782
|
+
return params;
|
|
1783
|
+
}
|
|
1784
|
+
function toFormData(data) {
|
|
1785
|
+
const formData = new FormData();
|
|
1786
|
+
for (const key in data) {
|
|
1787
|
+
const val = data[key];
|
|
1788
|
+
if (val === null) continue;
|
|
1789
|
+
if (Array.isArray(val)) {
|
|
1790
|
+
val.forEach(
|
|
1791
|
+
(v) => formData.append(
|
|
1792
|
+
key,
|
|
1793
|
+
v instanceof Blob ? v : typeof v === "object" ? JSON.stringify(v) : String(v)
|
|
1794
|
+
)
|
|
1795
|
+
);
|
|
1796
|
+
} else {
|
|
1797
|
+
formData.append(
|
|
1798
|
+
key,
|
|
1799
|
+
val instanceof Blob ? val : typeof val === "object" ? JSON.stringify(val) : String(val)
|
|
1800
|
+
);
|
|
1801
|
+
}
|
|
1802
|
+
}
|
|
1803
|
+
return formData;
|
|
1804
|
+
}
|
|
1755
1805
|
|
|
1756
1806
|
// src/web/storage/index.ts
|
|
1757
1807
|
var WK = {
|