fix problem with file name

This commit is contained in:
xiaofeng.mxf 2020-01-20 20:27:41 +08:00
parent fe3aa51bd5
commit 7908cbad4f
10 changed files with 122 additions and 8 deletions

View File

@ -53,10 +53,10 @@ export function isApiSuccess (response) {
return response.status === 'success'; return response.status === 'success';
} }
const ApiUtil = { const apiUtil = {
getJSON, getJSON,
postJSON, postJSON,
isApiSuccess isApiSuccess
}; };
export default ApiUtil; export default apiUtil;

View File

@ -39,3 +39,4 @@ export function initWs(wsPort = location.port, path = 'do-not-proxy') {
export default { export default {
initWs: initWs initWs: initWs
}; };

62
web/src/common/apiUtil.js Normal file
View File

@ -0,0 +1,62 @@
/**
* AJAX操作工具类
*/
import PromiseUtil from './promiseUtil';
export function getJSON(url, data) {
const d = PromiseUtil.defer();
fetch(url + serializeQuery(data))
.then((data) => {
d.resolve(data.json());
})
.catch((error) => {
console.error(error);
d.reject(error);
});
return d.promise;
}
export function postJSON(url, data) {
const d = PromiseUtil.defer();
fetch(url, {
method: 'POST',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json'
},
body: JSON.stringify(data)
})
.then((data) => {
d.resolve(data.json());
})
.catch((error) => {
console.error(error);
d.reject(error);
});
return d.promise;
}
function serializeQuery (data = {}) {
data['__t'] = Date.now();// disable the cache
const queryArray = [];
for (let key in data) {
queryArray.push(`${key}=${data[key]}`);
}
const queryStr = queryArray.join('&');
return queryStr ? '?' + queryStr : '';
}
export function isApiSuccess (response) {
return response.status === 'success';
}
const apiUtil = {
getJSON,
postJSON,
isApiSuccess
};
export default apiUtil;

View File

@ -0,0 +1,9 @@
/**
* define all constant variables here
*/
module.exports.MenuKeyMap = {
RECORD_FILTER: 'RECORD_FILTER',
MAP_LOCAL: 'MAP_LOCAL',
ROOT_CA: 'ROOT_CA'
};

42
web/src/common/wsUtil.js Normal file
View File

@ -0,0 +1,42 @@
/*
* Utility for websocket
*
*/
import { message } from 'antd';
/**
* Initiate a ws connection.
* The default path `do-not-proxy` means the ws do not need to be proxied.
* This is very important for AnyProxys own server, such as WEB UI,
* and the websocket detail panel in it, to prevent a recursive proxy.
* @param {wsPort} wsPort the port of websocket
* @param {key} path the path of the ws url
*
*/
export function initWs(wsPort = location.port, path = 'do-not-proxy') {
if(!WebSocket){
throw (new Error('WebSocket is not supported on this browser'));
}
const wsClient = new WebSocket(`ws://${location.hostname}:${wsPort}/${path}`);
wsClient.onerror = (error) => {
console.error(error);
message.error('error happened when setup websocket');
};
wsClient.onopen = (e) => {
console.info('websocket opened: ', e);
};
wsClient.onclose = (e) => {
console.info('websocket closed: ', e);
};
return wsClient;
}
export default {
initWs: initWs
};

View File

@ -11,7 +11,7 @@ import { message, Button, Spin } from 'antd';
import ResizablePanel from 'component/resizable-panel'; import ResizablePanel from 'component/resizable-panel';
import { hideRootCA, updateIsRootCAExists } from 'action/globalStatusAction'; import { hideRootCA, updateIsRootCAExists } from 'action/globalStatusAction';
import { MenuKeyMap } from 'common/constant'; import { MenuKeyMap } from 'common/constant';
import { getJSON, ajaxGet, postJSON } from 'common/ApiUtil'; import { getJSON, ajaxGet, postJSON } from 'common/apiUtil';
import Style from './download-root-ca.less'; import Style from './download-root-ca.less';
import CommonStyle from '../style/common.less'; import CommonStyle from '../style/common.less';

View File

@ -27,7 +27,7 @@ const {
RECORD_FILTER: RECORD_FILTER_MENU_KEY RECORD_FILTER: RECORD_FILTER_MENU_KEY
} = MenuKeyMap; } = MenuKeyMap;
import { getJSON } from 'common/ApiUtil'; import { getJSON } from 'common/apiUtil';
import Style from './header-menu.less'; import Style from './header-menu.less';

View File

@ -6,7 +6,7 @@
import React, { PropTypes } from 'react'; import React, { PropTypes } from 'react';
import { message, Button, Icon } from 'antd'; import { message, Button, Icon } from 'antd';
import { formatDate } from 'common/commonUtil'; import { formatDate } from 'common/commonUtil';
import { initWs } from 'common/WsUtil'; import { initWs } from 'common/wsUtil';
import ClassBind from 'classnames/bind'; import ClassBind from 'classnames/bind';
import Style from './record-ws-message-detail.less'; import Style from './record-ws-message-detail.less';

View File

@ -5,14 +5,14 @@
import React, { PropTypes } from 'react'; import React, { PropTypes } from 'react';
import { message } from 'antd'; import { message } from 'antd';
import { initWs } from 'common/WsUtil'; import { initWs } from 'common/wsUtil';
import { updateWholeRequest } from 'action/recordAction'; import { updateWholeRequest } from 'action/recordAction';
import { import {
updateShouldClearRecord, updateShouldClearRecord,
updateShowNewRecordTip updateShowNewRecordTip
} from 'action/globalStatusAction'; } from 'action/globalStatusAction';
const RecordWorker = require('worker-loader?inline!./record-worker.jsx'); const RecordWorker = require('worker-loader?inline!./record-worker.jsx');
import { getJSON } from 'common/ApiUtil'; import { getJSON } from 'common/apiUtil';
const myRecordWorker = new RecordWorker(window.URL.createObjectURL(new Blob([RecordWorker.toString()]))); const myRecordWorker = new RecordWorker(window.URL.createObjectURL(new Blob([RecordWorker.toString()])));
const fetchLatestLog = function () { const fetchLatestLog = function () {

View File

@ -29,7 +29,7 @@ import {
updateLocalGlobalProxyFlag updateLocalGlobalProxyFlag
} from 'action/globalStatusAction'; } from 'action/globalStatusAction';
import { getJSON, postJSON, isApiSuccess } from 'common/ApiUtil'; import { getJSON, postJSON, isApiSuccess } from 'common/apiUtil';
function* doFetchRequestList() { function* doFetchRequestList() {
const data = yield call(getJSON, '/latestLog'); const data = yield call(getJSON, '/latestLog');