+ client: use search params for querylog request

This commit is contained in:
Ildar Kamalov 2019-10-15 12:28:49 +03:00
parent 92b6adbdc1
commit 7b29c56791
7 changed files with 32 additions and 20 deletions

5
client/package-lock.json generated vendored
View File

@ -12725,6 +12725,11 @@
"requires-port": "^1.0.0" "requires-port": "^1.0.0"
} }
}, },
"url-polyfill": {
"version": "1.1.7",
"resolved": "https://registry.npmjs.org/url-polyfill/-/url-polyfill-1.1.7.tgz",
"integrity": "sha512-ZrAxYWCREjmMtL8gSbSiKKLZZticgihCvVBtrFbUVpyoETt8GQJeG2okMWA8XryDAaHMjJfhnc+rnhXRbI4DXA=="
},
"use": { "use": {
"version": "3.1.1", "version": "3.1.1",
"resolved": "https://registry.npmjs.org/use/-/use-3.1.1.tgz", "resolved": "https://registry.npmjs.org/use/-/use-3.1.1.tgz",

3
client/package.json vendored
View File

@ -33,7 +33,8 @@
"redux-actions": "^2.4.0", "redux-actions": "^2.4.0",
"redux-form": "^7.4.2", "redux-form": "^7.4.2",
"redux-thunk": "^2.3.0", "redux-thunk": "^2.3.0",
"svg-url-loader": "^2.3.2" "svg-url-loader": "^2.3.2",
"url-polyfill": "^1.1.7"
}, },
"devDependencies": { "devDependencies": {
"autoprefixer": "^8.6.3", "autoprefixer": "^8.6.3",

View File

@ -15,7 +15,7 @@ export const getLogs = config => async (dispatch) => {
dispatch(getLogsRequest()); dispatch(getLogsRequest());
try { try {
const { filter, lastRowTime: older_than } = config; const { filter, lastRowTime: older_than } = config;
const logs = normalizeLogs(await apiClient.getQueryLog({ filter, older_than })); const logs = normalizeLogs(await apiClient.getQueryLog({ ...filter, older_than }));
dispatch(getLogsSuccess({ logs, ...config })); dispatch(getLogsSuccess({ logs, ...config }));
} catch (error) { } catch (error) {
dispatch(addErrorToast({ error })); dispatch(addErrorToast({ error }));

View File

@ -1,5 +1,7 @@
import axios from 'axios'; import axios from 'axios';
import { getPathWithQueryParams } from '../helpers/helpers';
class Api { class Api {
baseUrl = 'control'; baseUrl = 'control';
@ -90,16 +92,16 @@ class Api {
} }
// Filtering // Filtering
FILTERING_INFO = { path: 'filtering_info', method: 'GET' }; FILTERING_STATUS = { path: 'filtering/status', method: 'GET' };
FILTERING_ADD_FILTER = { path: 'filtering/add_url', method: 'POST' }; FILTERING_ADD_FILTER = { path: 'filtering/add_url', method: 'POST' };
FILTERING_REMOVE_FILTER = { path: 'filtering/remove_url', method: 'POST' }; FILTERING_REMOVE_FILTER = { path: 'filtering/remove_url', method: 'POST' };
FILTERING_SET_RULES = { path: 'filtering/set_rules', method: 'POST' }; FILTERING_SET_RULES = { path: 'filtering/set_rules', method: 'POST' };
FILTERING_REFRESH = { path: 'filtering/refresh', method: 'POST' }; FILTERING_REFRESH = { path: 'filtering/refresh', method: 'POST' };
FILTERING_SET_URL = { path: 'filtering/set_url', method: 'POST' }; FILTERING_SET_URL = { path: 'filtering/set_url', method: 'POST' };
FILTERING_CONFIG = { path: 'filtering_config', method: 'POST' }; FILTERING_CONFIG = { path: 'filtering/config', method: 'POST' };
getFilteringStatus() { getFilteringStatus() {
const { path, method } = this.FILTERING_INFO; const { path, method } = this.FILTERING_STATUS;
return this.makeRequest(path, method); return this.makeRequest(path, method);
} }
@ -482,18 +484,15 @@ class Api {
} }
// Query log // Query log
GET_QUERY_LOG = { path: 'querylog', method: 'POST' }; GET_QUERY_LOG = { path: 'querylog', method: 'GET' };
QUERY_LOG_CONFIG = { path: 'querylog_config', method: 'POST' }; QUERY_LOG_CONFIG = { path: 'querylog_config', method: 'POST' };
QUERY_LOG_INFO = { path: 'querylog_info', method: 'GET' }; QUERY_LOG_INFO = { path: 'querylog_info', method: 'GET' };
QUERY_LOG_CLEAR = { path: 'querylog_clear', method: 'POST' }; QUERY_LOG_CLEAR = { path: 'querylog_clear', method: 'POST' };
getQueryLog(data) { getQueryLog(params) {
const { path, method } = this.GET_QUERY_LOG; const { path, method } = this.GET_QUERY_LOG;
const config = { const url = getPathWithQueryParams(path, params);
data, return this.makeRequest(url, method);
headers: { 'Content-Type': 'application/json' },
};
return this.makeRequest(path, method, config);
} }
getQueryLogInfo() { getQueryLogInfo() {

View File

@ -255,10 +255,10 @@ class Logs extends Component {
} = filteredObj; } = filteredObj;
return { return {
domain: domain || '', filter_domain: domain || '',
client: client || '', filter_client: client || '',
question_type: isValidQuestionType(type) ? type.toUpperCase() : '', filter_question_type: isValidQuestionType(type) ? type.toUpperCase() : '',
response_status: response === RESPONSE_FILTER.FILTERED ? response : '', filter_response_status: response === RESPONSE_FILTER.FILTERED ? response : '',
}; };
}; };

View File

@ -372,8 +372,8 @@ export const DNS_RECORD_TYPES = [
]; ];
export const DEFAULT_LOGS_FILTER = { export const DEFAULT_LOGS_FILTER = {
domain: '', filter_domain: '',
client: '', filter_client: '',
question_type: '', filter_question_type: '',
response_status: '', filter_response_status: '',
}; };

View File

@ -1,3 +1,4 @@
import 'url-polyfill';
import dateParse from 'date-fns/parse'; import dateParse from 'date-fns/parse';
import dateFormat from 'date-fns/format'; import dateFormat from 'date-fns/format';
import subHours from 'date-fns/sub_hours'; import subHours from 'date-fns/sub_hours';
@ -321,3 +322,9 @@ export const normalizeWhois = (whois) => {
}; };
export const isValidQuestionType = type => type && DNS_RECORD_TYPES.includes(type.toUpperCase()); export const isValidQuestionType = type => type && DNS_RECORD_TYPES.includes(type.toUpperCase());
export const getPathWithQueryParams = (path, params) => {
const searchParams = new URLSearchParams(params);
return `${path}?${searchParams.toString()}`;
};