|
@@ -18,19 +18,29 @@ For commercial licensing, please contact support@quantumnous.com
|
|
|
*/
|
|
*/
|
|
|
|
|
|
|
|
import React, { useEffect, useState, useRef } from 'react';
|
|
import React, { useEffect, useState, useRef } from 'react';
|
|
|
-import { Button, Col, Form, Row, Spin } from '@douyinfe/semi-ui';
|
|
|
|
|
|
|
+import {
|
|
|
|
|
+ Button,
|
|
|
|
|
+ Col,
|
|
|
|
|
+ Form,
|
|
|
|
|
+ Row,
|
|
|
|
|
+ Spin,
|
|
|
|
|
+ Tag,
|
|
|
|
|
+ Typography,
|
|
|
|
|
+} from '@douyinfe/semi-ui';
|
|
|
import {
|
|
import {
|
|
|
compareObjects,
|
|
compareObjects,
|
|
|
API,
|
|
API,
|
|
|
showError,
|
|
showError,
|
|
|
showSuccess,
|
|
showSuccess,
|
|
|
showWarning,
|
|
showWarning,
|
|
|
|
|
+ parseHttpStatusCodeRules,
|
|
|
verifyJSON,
|
|
verifyJSON,
|
|
|
} from '../../../helpers';
|
|
} from '../../../helpers';
|
|
|
import { useTranslation } from 'react-i18next';
|
|
import { useTranslation } from 'react-i18next';
|
|
|
|
|
|
|
|
export default function SettingsMonitoring(props) {
|
|
export default function SettingsMonitoring(props) {
|
|
|
const { t } = useTranslation();
|
|
const { t } = useTranslation();
|
|
|
|
|
+ const { Text } = Typography;
|
|
|
const [loading, setLoading] = useState(false);
|
|
const [loading, setLoading] = useState(false);
|
|
|
const [inputs, setInputs] = useState({
|
|
const [inputs, setInputs] = useState({
|
|
|
ChannelDisableThreshold: '',
|
|
ChannelDisableThreshold: '',
|
|
@@ -38,21 +48,37 @@ export default function SettingsMonitoring(props) {
|
|
|
AutomaticDisableChannelEnabled: false,
|
|
AutomaticDisableChannelEnabled: false,
|
|
|
AutomaticEnableChannelEnabled: false,
|
|
AutomaticEnableChannelEnabled: false,
|
|
|
AutomaticDisableKeywords: '',
|
|
AutomaticDisableKeywords: '',
|
|
|
|
|
+ AutomaticDisableStatusCodes: '401',
|
|
|
'monitor_setting.auto_test_channel_enabled': false,
|
|
'monitor_setting.auto_test_channel_enabled': false,
|
|
|
'monitor_setting.auto_test_channel_minutes': 10,
|
|
'monitor_setting.auto_test_channel_minutes': 10,
|
|
|
});
|
|
});
|
|
|
const refForm = useRef();
|
|
const refForm = useRef();
|
|
|
const [inputsRow, setInputsRow] = useState(inputs);
|
|
const [inputsRow, setInputsRow] = useState(inputs);
|
|
|
|
|
+ const parsedAutoDisableStatusCodes = parseHttpStatusCodeRules(
|
|
|
|
|
+ inputs.AutomaticDisableStatusCodes || '',
|
|
|
|
|
+ );
|
|
|
|
|
|
|
|
function onSubmit() {
|
|
function onSubmit() {
|
|
|
const updateArray = compareObjects(inputs, inputsRow);
|
|
const updateArray = compareObjects(inputs, inputsRow);
|
|
|
if (!updateArray.length) return showWarning(t('你似乎并没有修改什么'));
|
|
if (!updateArray.length) return showWarning(t('你似乎并没有修改什么'));
|
|
|
|
|
+ if (!parsedAutoDisableStatusCodes.ok) {
|
|
|
|
|
+ const details =
|
|
|
|
|
+ parsedAutoDisableStatusCodes.invalidTokens &&
|
|
|
|
|
+ parsedAutoDisableStatusCodes.invalidTokens.length > 0
|
|
|
|
|
+ ? `: ${parsedAutoDisableStatusCodes.invalidTokens.join(', ')}`
|
|
|
|
|
+ : '';
|
|
|
|
|
+ return showError(`${t('自动禁用状态码格式不正确')}${details}`);
|
|
|
|
|
+ }
|
|
|
const requestQueue = updateArray.map((item) => {
|
|
const requestQueue = updateArray.map((item) => {
|
|
|
let value = '';
|
|
let value = '';
|
|
|
if (typeof inputs[item.key] === 'boolean') {
|
|
if (typeof inputs[item.key] === 'boolean') {
|
|
|
value = String(inputs[item.key]);
|
|
value = String(inputs[item.key]);
|
|
|
} else {
|
|
} else {
|
|
|
- value = inputs[item.key];
|
|
|
|
|
|
|
+ if (item.key === 'AutomaticDisableStatusCodes') {
|
|
|
|
|
+ value = parsedAutoDisableStatusCodes.normalized;
|
|
|
|
|
+ } else {
|
|
|
|
|
+ value = inputs[item.key];
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
return API.put('/api/option/', {
|
|
return API.put('/api/option/', {
|
|
|
key: item.key,
|
|
key: item.key,
|
|
@@ -207,6 +233,45 @@ export default function SettingsMonitoring(props) {
|
|
|
</Row>
|
|
</Row>
|
|
|
<Row gutter={16}>
|
|
<Row gutter={16}>
|
|
|
<Col xs={24} sm={16}>
|
|
<Col xs={24} sm={16}>
|
|
|
|
|
+ <Form.Input
|
|
|
|
|
+ label={t('自动禁用状态码')}
|
|
|
|
|
+ placeholder={t('例如:401, 403, 429, 500-599')}
|
|
|
|
|
+ extraText={t(
|
|
|
|
|
+ '支持填写单个状态码或范围(含首尾),使用逗号分隔',
|
|
|
|
|
+ )}
|
|
|
|
|
+ field={'AutomaticDisableStatusCodes'}
|
|
|
|
|
+ onChange={(value) =>
|
|
|
|
|
+ setInputs({ ...inputs, AutomaticDisableStatusCodes: value })
|
|
|
|
|
+ }
|
|
|
|
|
+ />
|
|
|
|
|
+ {parsedAutoDisableStatusCodes.ok &&
|
|
|
|
|
+ parsedAutoDisableStatusCodes.tokens.length > 0 && (
|
|
|
|
|
+ <div
|
|
|
|
|
+ style={{
|
|
|
|
|
+ display: 'flex',
|
|
|
|
|
+ flexWrap: 'wrap',
|
|
|
|
|
+ gap: 8,
|
|
|
|
|
+ marginTop: 8,
|
|
|
|
|
+ }}
|
|
|
|
|
+ >
|
|
|
|
|
+ {parsedAutoDisableStatusCodes.tokens.map((token) => (
|
|
|
|
|
+ <Tag key={token} size='small'>
|
|
|
|
|
+ {token}
|
|
|
|
|
+ </Tag>
|
|
|
|
|
+ ))}
|
|
|
|
|
+ </div>
|
|
|
|
|
+ )}
|
|
|
|
|
+ {!parsedAutoDisableStatusCodes.ok && (
|
|
|
|
|
+ <Text type='danger' style={{ display: 'block', marginTop: 8 }}>
|
|
|
|
|
+ {t('自动禁用状态码格式不正确')}
|
|
|
|
|
+ {parsedAutoDisableStatusCodes.invalidTokens &&
|
|
|
|
|
+ parsedAutoDisableStatusCodes.invalidTokens.length > 0
|
|
|
|
|
+ ? `: ${parsedAutoDisableStatusCodes.invalidTokens.join(
|
|
|
|
|
+ ', ',
|
|
|
|
|
+ )}`
|
|
|
|
|
+ : ''}
|
|
|
|
|
+ </Text>
|
|
|
|
|
+ )}
|
|
|
<Form.TextArea
|
|
<Form.TextArea
|
|
|
label={t('自动禁用关键词')}
|
|
label={t('自动禁用关键词')}
|
|
|
placeholder={t('一行一个,不区分大小写')}
|
|
placeholder={t('一行一个,不区分大小写')}
|