@base-web-kits/base-tools-web 1.1.0-alpha.0 → 1.1.0-alpha.2
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 +55 -5
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +55 -5
- 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
|
@@ -1734,7 +1734,7 @@ var baseToolsWeb = (() => {
|
|
|
1734
1734
|
let chunkCallback = null;
|
|
1735
1735
|
const task = {
|
|
1736
1736
|
abort: () => controller.abort(),
|
|
1737
|
-
|
|
1737
|
+
onProgressUpdate: (cb) => {
|
|
1738
1738
|
chunkCallback = cb;
|
|
1739
1739
|
},
|
|
1740
1740
|
offChunkReceived: () => {
|
|
@@ -1767,11 +1767,27 @@ var baseToolsWeb = (() => {
|
|
|
1767
1767
|
const isArrayData = !isObjectData && Array.isArray(data);
|
|
1768
1768
|
const fillData = isObjectData ? pickBy(data, (val) => val !== void 0) : data;
|
|
1769
1769
|
const fillHeader = header ? pickBy(header, (val) => !!val) : {};
|
|
1770
|
-
|
|
1770
|
+
const contentTypeKey = Object.keys(fillHeader).find(
|
|
1771
|
+
(k) => k.toLowerCase() === "content-type"
|
|
1772
|
+
);
|
|
1773
|
+
const contentType = contentTypeKey ? fillHeader[contentTypeKey].toLowerCase() : "";
|
|
1774
|
+
if (!isGet && fillData && (isObjectData || isArrayData) && !contentType) {
|
|
1771
1775
|
fillHeader["Content-Type"] = "application/json";
|
|
1772
1776
|
}
|
|
1773
1777
|
const fillUrl = isGet && isObjectData ? appendUrlParam(url, fillData) : url;
|
|
1774
|
-
|
|
1778
|
+
let fillBody;
|
|
1779
|
+
if (!isGet && fillData) {
|
|
1780
|
+
if (isObjectData && contentType.includes("application/x-www-form-urlencoded")) {
|
|
1781
|
+
fillBody = toSearchParams(fillData);
|
|
1782
|
+
} else if (isObjectData && contentType.includes("multipart/form-data")) {
|
|
1783
|
+
fillBody = toFormData(fillData);
|
|
1784
|
+
if (contentTypeKey) delete fillHeader[contentTypeKey];
|
|
1785
|
+
} else if (isObjectData || isArrayData) {
|
|
1786
|
+
fillBody = JSON.stringify(fillData);
|
|
1787
|
+
} else {
|
|
1788
|
+
fillBody = fillData;
|
|
1789
|
+
}
|
|
1790
|
+
}
|
|
1775
1791
|
const logConfig = { ...config, data: fillData, header: fillHeader, url: fillUrl };
|
|
1776
1792
|
const startTime = Date.now();
|
|
1777
1793
|
const isCache = cacheTime && cacheTime > 0;
|
|
@@ -1926,6 +1942,40 @@ var baseToolsWeb = (() => {
|
|
|
1926
1942
|
}
|
|
1927
1943
|
return resData;
|
|
1928
1944
|
}
|
|
1945
|
+
function toSearchParams(data) {
|
|
1946
|
+
const params = new URLSearchParams();
|
|
1947
|
+
for (const key in data) {
|
|
1948
|
+
const val = data[key];
|
|
1949
|
+
if (val === null) continue;
|
|
1950
|
+
if (Array.isArray(val)) {
|
|
1951
|
+
val.forEach((v) => params.append(key, typeof v === "object" ? JSON.stringify(v) : String(v)));
|
|
1952
|
+
} else {
|
|
1953
|
+
params.append(key, typeof val === "object" ? JSON.stringify(val) : String(val));
|
|
1954
|
+
}
|
|
1955
|
+
}
|
|
1956
|
+
return params;
|
|
1957
|
+
}
|
|
1958
|
+
function toFormData(data) {
|
|
1959
|
+
const formData = new FormData();
|
|
1960
|
+
for (const key in data) {
|
|
1961
|
+
const val = data[key];
|
|
1962
|
+
if (val === null) continue;
|
|
1963
|
+
if (Array.isArray(val)) {
|
|
1964
|
+
val.forEach(
|
|
1965
|
+
(v) => formData.append(
|
|
1966
|
+
key,
|
|
1967
|
+
v instanceof Blob ? v : typeof v === "object" ? JSON.stringify(v) : String(v)
|
|
1968
|
+
)
|
|
1969
|
+
);
|
|
1970
|
+
} else {
|
|
1971
|
+
formData.append(
|
|
1972
|
+
key,
|
|
1973
|
+
val instanceof Blob ? val : typeof val === "object" ? JSON.stringify(val) : String(val)
|
|
1974
|
+
);
|
|
1975
|
+
}
|
|
1976
|
+
}
|
|
1977
|
+
return formData;
|
|
1978
|
+
}
|
|
1929
1979
|
|
|
1930
1980
|
// src/web/storage/index.ts
|
|
1931
1981
|
var WK = {
|