+ 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

View File

@@ -15,7 +15,7 @@ export const getLogs = config => async (dispatch) => {
dispatch(getLogsRequest());
try {
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 }));
} catch (error) {
dispatch(addErrorToast({ error }));

View File

@@ -1,5 +1,7 @@
import axios from 'axios';
import { getPathWithQueryParams } from '../helpers/helpers';
class Api {
baseUrl = 'control';
@@ -90,16 +92,16 @@ class Api {
}
// 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_REMOVE_FILTER = { path: 'filtering/remove_url', method: 'POST' };
FILTERING_SET_RULES = { path: 'filtering/set_rules', method: 'POST' };
FILTERING_REFRESH = { path: 'filtering/refresh', 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() {
const { path, method } = this.FILTERING_INFO;
const { path, method } = this.FILTERING_STATUS;
return this.makeRequest(path, method);
}
@@ -482,18 +484,15 @@ class Api {
}
// 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_INFO = { path: 'querylog_info', method: 'GET' };
QUERY_LOG_CLEAR = { path: 'querylog_clear', method: 'POST' };
getQueryLog(data) {
getQueryLog(params) {
const { path, method } = this.GET_QUERY_LOG;
const config = {
data,
headers: { 'Content-Type': 'application/json' },
};
return this.makeRequest(path, method, config);
const url = getPathWithQueryParams(path, params);
return this.makeRequest(url, method);
}
getQueryLogInfo() {

View File

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

View File

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

View File

@@ -1,3 +1,4 @@
import 'url-polyfill';
import dateParse from 'date-fns/parse';
import dateFormat from 'date-fns/format';
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 getPathWithQueryParams = (path, params) => {
const searchParams = new URLSearchParams(params);
return `${path}?${searchParams.toString()}`;
};