提交 4451d07a authored 作者: vipcxj's avatar vipcxj

dmPath提前

上级 2ccea0b4
...@@ -11,25 +11,24 @@ const defaultOptions = { ...@@ -11,25 +11,24 @@ const defaultOptions = {
}, },
}; };
const sortBodyForToken = (keys) => { const sortBody = (keys) => {
const idxToken = keys.indexOf('token'); const idxToken = keys.indexOf('token');
let tokens = [];
let dmPaths = [];
if (idxToken !== -1) { if (idxToken !== -1) {
if (idxToken === 0) { tokens = keys.splice(idxToken, 1);
return keys;
} else if (idxToken === keys.length - 1) {
return ['token', ...keys.slice(0, keys.length - 1)];
} else {
return ['token', ...keys.slice(0, idxToken), ...keys.slice(idxToken + 1)];
} }
} else { const idxDmPath = keys.indexOf('dmPath');
return keys; if (idxDmPath !== -1) {
dmPaths = keys.splice(idxDmPath, 1);
} }
return [...tokens, ...dmPaths, ...keys];
}; };
const orderedStringify = (obj) => { const orderedStringify = (obj) => {
const allKeys = []; const allKeys = [];
JSON.stringify(obj, (k, v) => { allKeys.push(k); return v; }); JSON.stringify(obj, (k, v) => { allKeys.push(k); return v; });
return JSON.stringify(obj, sortBodyForToken(allKeys)); return JSON.stringify(obj, sortBody(allKeys));
}; };
export default async function post(url, data, params = {}, options = {}, auth = true) { export default async function post(url, data, params = {}, options = {}, auth = true) {
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论