@varlet/axle 0.2.18-alpha.1702624592933 → 0.2.18
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/es/index.js +19 -14
- package/package.json +1 -1
package/es/index.js
CHANGED
|
@@ -343,28 +343,33 @@ import { minimatch as minimatch3 } from "minimatch";
|
|
|
343
343
|
import { set, get } from "lodash-es";
|
|
344
344
|
import { MD5 } from "crypto-js";
|
|
345
345
|
import { isString } from "@varlet/shared";
|
|
346
|
-
function
|
|
346
|
+
function withCtxMd5(ctx, mappingValue) {
|
|
347
347
|
mappingValue.path.forEach((path) => {
|
|
348
|
-
const targetValue = get(
|
|
348
|
+
const targetValue = get(ctx, path);
|
|
349
349
|
if (targetValue != null) {
|
|
350
|
-
set(
|
|
350
|
+
set(ctx, path, MD5(String(targetValue)).toString());
|
|
351
351
|
}
|
|
352
352
|
});
|
|
353
353
|
}
|
|
354
354
|
function withMd5(config, mappingValue) {
|
|
355
|
-
const { data, headers = {} } = config;
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
}
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
355
|
+
const { data = {}, params = {}, headers = {} } = config;
|
|
356
|
+
const ctx = {
|
|
357
|
+
data: isFormData(data) ? data : JSON.parse(JSON.stringify(data)),
|
|
358
|
+
params: JSON.parse(JSON.stringify(params)),
|
|
359
|
+
headers: JSON.parse(JSON.stringify(headers))
|
|
360
|
+
};
|
|
361
|
+
if (isString(ctx.data) && ctx.data.length > 0 && ctx.headers["Content-Type"] === "application/x-www-form-urlencoded") {
|
|
362
|
+
ctx.data = qs2.parse(ctx.data);
|
|
363
|
+
withCtxMd5(ctx, mappingValue);
|
|
364
|
+
ctx.data = qs2.stringify(ctx.data);
|
|
365
|
+
} else if (isFormData(ctx.data)) {
|
|
366
|
+
ctx.data = formDataToObject(ctx.data);
|
|
367
|
+
withCtxMd5(ctx, mappingValue);
|
|
368
|
+
ctx.data = objectToFormData(ctx.data);
|
|
364
369
|
} else {
|
|
365
|
-
|
|
370
|
+
withCtxMd5(ctx, mappingValue);
|
|
366
371
|
}
|
|
367
|
-
return config;
|
|
372
|
+
return __spreadValues(__spreadValues({}, config), ctx);
|
|
368
373
|
}
|
|
369
374
|
function requestMd5Interceptor(options = {}) {
|
|
370
375
|
return {
|