提交 1d916386 authored 作者: 钟是志's avatar 钟是志

TRANSFORM_BIN: true, // 鉴权加密 禅道 28321

上级 6c5757c4
......@@ -11,7 +11,7 @@ import { strToBinary } from '@/webPublic/one_stop_public/Base16/strToBinary';
import { binaryToStr } from '@/webPublic/one_stop_public/Base16/binaryToStr';
import { getUrlInfo } from '@/webPublic/one_stop_public/DetailForAudit/utils';
const isTest = getUrlInfo().test || true;
const isTest = getUrlInfo().test;
function getApi(apiUrl) {
......@@ -52,14 +52,11 @@ function getApi(apiUrl) {
if (res.rbin && isJSON(binaryToStr(res.rbin))) {
const u = JSON.parse(binaryToStr(res.rbin)).url;
const g = encodeURIComponent(u);
if(isTest){
console.log('转换接口返回的结果为: ', g);
}
const newUrl = window.CONFIG.API_ACTION_PATH + '/apis/' + g;
if(isTest){
console.log('转换后的接口地址为: ', newUrl);
}
// setLocalStorageTransformApi(apiUrl, g); // TODO 暂时不存入缓存
setLocalStorageTransformApi(apiUrl, g); // 存入缓存
return newUrl;
} else {
return false;
......@@ -91,18 +88,23 @@ function setLocalStorageTransformApi(api = '', transformApi = '') {
localStorage.setItem('oneStopTransformApi', JSON.stringify(old));
}
export function getTransformApi(url) { // api 表示一站式接口后缀.
export async function getTransformApi(url) { //
let apiUrl = '';
if (url && typeof url === 'string' && url.indexOf('/onestop') > -1 && url.includes(window.CONFIG.API_ACTION_PATH)) {
let needTransform = true;
const t = getToken();
const TRANSFORM_BIN = window.CONFIG?.TRANSFORM_BIN;
if(!TRANSFORM_BIN){
needTransform = false;
}
if (needTransform && url && typeof url === 'string' && url.indexOf('/onestop') > -1 && url.includes(window.CONFIG.API_ACTION_PATH)) {
apiUrl = url.replace(window.CONFIG.API_ACTION_PATH, '');
} else {
return new Promise((resolve, reject) => {
resolve(url);
});
}
const t = getToken();
const openIsBinary = window.CONFIG?.IS_BINARY;
if (!t || t.length < 11 || !openIsBinary) { // 没有token 或者没有开启二进制加密 直接返回 不需要转换
if (!t || t.length < 11 || !needTransform) { // 没有token 或者没有开启二进制加密 直接返回 不需要转换
return new Promise((resolve, reject) => {
resolve(url);
});
......
......@@ -16,8 +16,8 @@ const test = !!(getUrlInfo().test);
function formatDatas(datas, url = '') {
let datasCode = JSON.stringify(datas);
const openIsBinary = window.CONFIG?.IS_BINARY;
if(test){
console.log(url,datas);
if (test) {
console.log(url, datas);
}
if (openIsBinary) {
datasCode = strToBinary(datasCode);
......@@ -104,7 +104,13 @@ export async function requestFileInfo(url, datas) {
}
let trueUrl = url && url.indexOf('http') > -1 ? url : queryApiActionPath() + url;
if (test) {
console.log('转换前', trueUrl);
}
const transformApi = await getTransformApi(trueUrl);
if (test) {
console.log('转换后' + transformApi);
}
return fetch(transformApi, {
headers: {
Accept: 'application/json',
......
......@@ -143,7 +143,7 @@ export const request = (url, data, options = {}) => {
};
export const requestOrigin = (url, data, options = {}) => {
export async function requestOrigin(url, data, options = {}){
......@@ -171,6 +171,7 @@ export const requestOrigin = (url, data, options = {}) => {
url = url + '?token=' + getToken() + objectToQuery(pp);
}
// 由于自动添加前缀 这里暂时修改getUrl(url)
// GET请求
return umiRequest(url, {
data: pp,
// method: "POST",
......@@ -266,8 +267,11 @@ export const requestOrigin = (url, data, options = {}) => {
if (getToken()) {
options.headers = getHeaders(url).headers;
}
return fetchRequest(url, {
let trueUrl = (options.prefix || '') + url;
trueUrl = await getTransformApi(trueUrl);
delete options.prefix;
// POST请求
return fetchRequest(trueUrl, {
data: pp,
// method: "POST",
requestType: 'form',
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论