mirror of
https://github.com/whyour/qinglong.git
synced 2026-07-17 17:54:32 +08:00
系统设置增加依赖代理和镜像设置
This commit is contained in:
@@ -15,6 +15,7 @@ import CodeMirror from '@uiw/react-codemirror';
|
||||
import { useOutletContext } from '@umijs/max';
|
||||
import { SharedContext } from '@/layouts';
|
||||
import { langs } from '@uiw/codemirror-extensions-langs';
|
||||
import { useHotkeys } from 'react-hotkeys-hook';
|
||||
|
||||
const Config = () => {
|
||||
const { headerStyle, isPhone, theme } = useOutletContext<SharedContext>();
|
||||
@@ -68,6 +69,14 @@ const Config = () => {
|
||||
getConfig(node.value);
|
||||
};
|
||||
|
||||
useHotkeys(
|
||||
'meta+s',
|
||||
(e) => {
|
||||
updateConfig();
|
||||
},
|
||||
{ enableOnFormTags: ['textarea'], preventDefault: true },
|
||||
);
|
||||
|
||||
useEffect(() => {
|
||||
getFiles();
|
||||
getConfig('config.sh');
|
||||
|
||||
@@ -4,6 +4,15 @@ import { Button, InputNumber, Form, message, Input, Alert } from 'antd';
|
||||
import config from '@/utils/config';
|
||||
import { request } from '@/utils/http';
|
||||
import './index.less';
|
||||
import Ansi from 'ansi-to-react';
|
||||
import pick from 'lodash/pick';
|
||||
|
||||
const dataMap = {
|
||||
'dependence-proxy': 'dependenceProxy',
|
||||
'node-mirror': 'nodeMirror',
|
||||
'python-mirror': 'pythonMirror',
|
||||
'linux-mirror': 'linuxMirror',
|
||||
};
|
||||
|
||||
const Dependence = () => {
|
||||
const [systemConfig, setSystemConfig] = useState<{
|
||||
@@ -13,6 +22,7 @@ const Dependence = () => {
|
||||
linuxMirror?: string;
|
||||
}>();
|
||||
const [form] = Form.useForm();
|
||||
const [log, setLog] = useState<string>('');
|
||||
|
||||
const getSystemConfig = () => {
|
||||
request
|
||||
@@ -27,9 +37,31 @@ const Dependence = () => {
|
||||
});
|
||||
};
|
||||
|
||||
const updateSystemConfig = () => {
|
||||
const updateSystemConfigStream = (path: keyof typeof dataMap) => {
|
||||
setLog('执行中...');
|
||||
request
|
||||
.put(`${config.apiPrefix}system/config`, systemConfig)
|
||||
.put<string>(
|
||||
`${config.apiPrefix}system/config/${path}`,
|
||||
pick(systemConfig, dataMap[path]),
|
||||
{
|
||||
responseType: 'stream',
|
||||
},
|
||||
)
|
||||
.then((res) => {
|
||||
setLog(() => res);
|
||||
})
|
||||
.catch((error: any) => {
|
||||
console.log(error);
|
||||
});
|
||||
};
|
||||
|
||||
const updateSystemConfig = (path: keyof typeof dataMap) => {
|
||||
setLog('');
|
||||
request
|
||||
.put(
|
||||
`${config.apiPrefix}system/config/${path}`,
|
||||
pick(systemConfig, dataMap[path]),
|
||||
)
|
||||
.then(({ code, data }) => {
|
||||
if (code === 200) {
|
||||
message.success(intl.get('更新成功'));
|
||||
@@ -45,94 +77,120 @@ const Dependence = () => {
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<Form layout="vertical" form={form}>
|
||||
<Form.Item
|
||||
label={intl.get('代理')}
|
||||
name="proxy"
|
||||
extra={intl.get('代理与镜像源二选一即可')}
|
||||
<div className="dependence-config-wrapper">
|
||||
<Form layout="vertical" form={form}>
|
||||
<Form.Item
|
||||
label={intl.get('代理')}
|
||||
name="proxy"
|
||||
extra={intl.get('代理与镜像源二选一即可')}
|
||||
>
|
||||
<Input.Group compact>
|
||||
<Input
|
||||
placeholder={intl.get('代理地址, 支持HTTP(S)/SOCK5, ip:port')}
|
||||
style={{ width: 330 }}
|
||||
value={systemConfig?.dependenceProxy}
|
||||
onChange={(e) => {
|
||||
setSystemConfig({
|
||||
...systemConfig,
|
||||
dependenceProxy: e.target.value,
|
||||
});
|
||||
}}
|
||||
/>
|
||||
<Button
|
||||
type="primary"
|
||||
onClick={() => {
|
||||
updateSystemConfig('dependence-proxy');
|
||||
}}
|
||||
style={{ width: 84 }}
|
||||
>
|
||||
{intl.get('确认')}
|
||||
</Button>
|
||||
</Input.Group>
|
||||
</Form.Item>
|
||||
<Form.Item label={intl.get('Node 软件包镜像源')} name="node">
|
||||
<Input.Group compact>
|
||||
<Input
|
||||
style={{ width: 330 }}
|
||||
placeholder={intl.get('NPM 镜像源')}
|
||||
value={systemConfig?.nodeMirror}
|
||||
onChange={(e) => {
|
||||
setSystemConfig({
|
||||
...systemConfig,
|
||||
nodeMirror: e.target.value,
|
||||
});
|
||||
}}
|
||||
/>
|
||||
<Button
|
||||
type="primary"
|
||||
onClick={() => {
|
||||
updateSystemConfigStream('node-mirror');
|
||||
}}
|
||||
style={{ width: 84 }}
|
||||
>
|
||||
{intl.get('确认')}
|
||||
</Button>
|
||||
</Input.Group>
|
||||
</Form.Item>
|
||||
<Form.Item label={intl.get('Python 软件包镜像源')} name="python">
|
||||
<Input.Group compact>
|
||||
<Input
|
||||
style={{ width: 330 }}
|
||||
placeholder={intl.get('PyPI 镜像源')}
|
||||
value={systemConfig?.pythonMirror}
|
||||
onChange={(e) => {
|
||||
setSystemConfig({
|
||||
...systemConfig,
|
||||
pythonMirror: e.target.value,
|
||||
});
|
||||
}}
|
||||
/>
|
||||
<Button
|
||||
type="primary"
|
||||
onClick={() => {
|
||||
updateSystemConfig('python-mirror');
|
||||
}}
|
||||
style={{ width: 84 }}
|
||||
>
|
||||
{intl.get('确认')}
|
||||
</Button>
|
||||
</Input.Group>
|
||||
</Form.Item>
|
||||
<Form.Item label={intl.get('Linux 软件包镜像源')} name="linux">
|
||||
<Input.Group compact>
|
||||
<Input
|
||||
style={{ width: 330 }}
|
||||
placeholder={intl.get('alpine linux 镜像源')}
|
||||
value={systemConfig?.linuxMirror}
|
||||
onChange={(e) => {
|
||||
setSystemConfig({
|
||||
...systemConfig,
|
||||
linuxMirror: e.target.value,
|
||||
});
|
||||
}}
|
||||
/>
|
||||
<Button
|
||||
type="primary"
|
||||
onClick={() => {
|
||||
updateSystemConfigStream('linux-mirror');
|
||||
}}
|
||||
style={{ width: 84 }}
|
||||
>
|
||||
{intl.get('确认')}
|
||||
</Button>
|
||||
</Input.Group>
|
||||
</Form.Item>
|
||||
</Form>
|
||||
<pre
|
||||
style={{
|
||||
fontFamily: 'Source Code Pro',
|
||||
zoom: 0.83,
|
||||
maxHeight: '100%',
|
||||
overflowY: 'auto'
|
||||
}}
|
||||
>
|
||||
<Input.Group compact>
|
||||
<Input
|
||||
placeholder={intl.get('代理地址, 支持HTTP(S)/SOCK5')}
|
||||
style={{ width: 330 }}
|
||||
value={systemConfig?.dependenceProxy}
|
||||
onChange={(e) => {
|
||||
setSystemConfig({
|
||||
...systemConfig,
|
||||
dependenceProxy: e.target.value,
|
||||
});
|
||||
}}
|
||||
/>
|
||||
<Button
|
||||
type="primary"
|
||||
onClick={updateSystemConfig}
|
||||
style={{ width: 84 }}
|
||||
>
|
||||
{intl.get('确认')}
|
||||
</Button>
|
||||
</Input.Group>
|
||||
</Form.Item>
|
||||
<Form.Item label={intl.get('Node 软件包镜像源')} name="node">
|
||||
<Input.Group compact>
|
||||
<Input
|
||||
style={{ width: 330 }}
|
||||
placeholder={intl.get('NPM 镜像源')}
|
||||
value={systemConfig?.nodeMirror}
|
||||
onChange={(e) => {
|
||||
setSystemConfig({ ...systemConfig, nodeMirror: e.target.value });
|
||||
}}
|
||||
/>
|
||||
<Button
|
||||
type="primary"
|
||||
onClick={updateSystemConfig}
|
||||
style={{ width: 84 }}
|
||||
>
|
||||
{intl.get('确认')}
|
||||
</Button>
|
||||
</Input.Group>
|
||||
</Form.Item>
|
||||
<Form.Item label={intl.get('Python 软件包镜像源')} name="python">
|
||||
<Input.Group compact>
|
||||
<Input
|
||||
style={{ width: 330 }}
|
||||
placeholder={intl.get('PyPI 镜像源')}
|
||||
value={systemConfig?.pythonMirror}
|
||||
onChange={(e) => {
|
||||
setSystemConfig({
|
||||
...systemConfig,
|
||||
pythonMirror: e.target.value,
|
||||
});
|
||||
}}
|
||||
/>
|
||||
<Button
|
||||
type="primary"
|
||||
onClick={updateSystemConfig}
|
||||
style={{ width: 84 }}
|
||||
>
|
||||
{intl.get('确认')}
|
||||
</Button>
|
||||
</Input.Group>
|
||||
</Form.Item>
|
||||
<Form.Item label={intl.get('Linux 软件包镜像源')} name="linux">
|
||||
<Input.Group compact>
|
||||
<Input
|
||||
style={{ width: 330 }}
|
||||
placeholder={intl.get('alpine linux 镜像源')}
|
||||
value={systemConfig?.linuxMirror}
|
||||
onChange={(e) => {
|
||||
setSystemConfig({ ...systemConfig, linuxMirror: e.target.value });
|
||||
}}
|
||||
/>
|
||||
<Button
|
||||
type="primary"
|
||||
onClick={updateSystemConfig}
|
||||
style={{ width: 84 }}
|
||||
>
|
||||
{intl.get('确认')}
|
||||
</Button>
|
||||
</Input.Group>
|
||||
</Form.Item>
|
||||
</Form>
|
||||
<Ansi>{log}</Ansi>
|
||||
</pre>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
|
||||
@@ -27,3 +27,8 @@
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.dependence-config-wrapper {
|
||||
display: flex;
|
||||
gap: 40px;
|
||||
}
|
||||
|
||||
@@ -21,6 +21,12 @@ import './index.less';
|
||||
import { UploadOutlined } from '@ant-design/icons';
|
||||
import Countdown from 'antd/lib/statistic/Countdown';
|
||||
import useProgress from './progress';
|
||||
import pick from 'lodash/pick';
|
||||
|
||||
const dataMap = {
|
||||
'log-remove-frequency': 'logRemoveFrequency',
|
||||
'cron-concurrency': 'cronConcurrency',
|
||||
};
|
||||
|
||||
const Other = ({
|
||||
systemInfo,
|
||||
@@ -32,7 +38,6 @@ const Other = ({
|
||||
cronConcurrency?: number | null;
|
||||
}>();
|
||||
const [form] = Form.useForm();
|
||||
const modalRef = useRef<any>();
|
||||
const [exportLoading, setExportLoading] = useState(false);
|
||||
const showUploadProgress = useProgress(intl.get('上传'));
|
||||
const showDownloadProgress = useProgress(intl.get('下载'));
|
||||
@@ -80,9 +85,12 @@ const Other = ({
|
||||
});
|
||||
};
|
||||
|
||||
const updateSystemConfig = () => {
|
||||
const updateSystemConfig = (path: keyof typeof dataMap) => {
|
||||
request
|
||||
.put(`${config.apiPrefix}system/config`, systemConfig)
|
||||
.put(
|
||||
`${config.apiPrefix}system/config/${path}`,
|
||||
pick(systemConfig, dataMap[path]),
|
||||
)
|
||||
.then(({ code, data }) => {
|
||||
if (code === 200) {
|
||||
message.success(intl.get('更新成功'));
|
||||
@@ -207,7 +215,9 @@ const Other = ({
|
||||
/>
|
||||
<Button
|
||||
type="primary"
|
||||
onClick={updateSystemConfig}
|
||||
onClick={() => {
|
||||
updateSystemConfig('log-remove-frequency');
|
||||
}}
|
||||
style={{ width: 84 }}
|
||||
>
|
||||
{intl.get('确认')}
|
||||
@@ -226,7 +236,9 @@ const Other = ({
|
||||
/>
|
||||
<Button
|
||||
type="primary"
|
||||
onClick={updateSystemConfig}
|
||||
onClick={() => {
|
||||
updateSystemConfig('cron-concurrency');
|
||||
}}
|
||||
style={{ width: 84 }}
|
||||
>
|
||||
{intl.get('确认')}
|
||||
|
||||
Reference in New Issue
Block a user