修改获取切换 node 和 linux 源日志

This commit is contained in:
whyour 2023-11-30 23:39:14 +08:00
parent c6a25e5359
commit 5afec03548
6 changed files with 51 additions and 25 deletions

View File

@ -17,4 +17,6 @@ export type SockMessageType =
| 'updateSystemVersion' | 'updateSystemVersion'
| 'manuallyRunScript' | 'manuallyRunScript'
| 'runSubscriptionEnd' | 'runSubscriptionEnd'
| 'reloadSystem'; | 'reloadSystem'
| 'updateNodeMirror'
| 'updateLinuxMirror';

View File

@ -142,15 +142,19 @@ export default class SystemService {
{ {
onStart: async (cp) => { onStart: async (cp) => {
res.setHeader('QL-Task-Pid', `${cp.pid}`); res.setHeader('QL-Task-Pid', `${cp.pid}`);
},
onEnd: async () => {
res.end(); res.end();
}, },
onEnd: async () => {
this.sockService.sendMessage({
type: 'updateNodeMirror',
message: 'update node mirror end',
});
},
onError: async (message: string) => { onError: async (message: string) => {
res.write(`\n${message}`); this.sockService.sendMessage({ type: 'updateNodeMirror', message });
}, },
onLog: async (message: string) => { onLog: async (message: string) => {
res.write(`\n${message}`); this.sockService.sendMessage({ type: 'updateNodeMirror', message });
}, },
}, },
{ {
@ -192,15 +196,19 @@ export default class SystemService {
{ {
onStart: async (cp) => { onStart: async (cp) => {
res.setHeader('QL-Task-Pid', `${cp.pid}`); res.setHeader('QL-Task-Pid', `${cp.pid}`);
},
onEnd: async () => {
res.end(); res.end();
}, },
onEnd: async () => {
this.sockService.sendMessage({
type: 'updateLinuxMirror',
message: 'update linux mirror end',
});
},
onError: async (message: string) => { onError: async (message: string) => {
res.write(`\n${message}`); this.sockService.sendMessage({ type: 'updateLinuxMirror', message });
}, },
onLog: async (message: string) => { onLog: async (message: string) => {
res.write(`\n${message}`); this.sockService.sendMessage({ type: 'updateLinuxMirror', message });
}, },
}, },
{ {

View File

@ -475,5 +475,5 @@
"代理地址, 支持HTTP(S)/SOCK5": "Proxy Address, supports HTTP(S)/SOCK5", "代理地址, 支持HTTP(S)/SOCK5": "Proxy Address, supports HTTP(S)/SOCK5",
"NPM 镜像源": "NPM Mirror Source", "NPM 镜像源": "NPM Mirror Source",
"PyPI 镜像源": "PyPI Mirror Source", "PyPI 镜像源": "PyPI Mirror Source",
"alpine linux 镜像源": "Alpine Linux Mirror Source" "alpine linux 镜像源, 例如 mirrors.aliyun.com": "Alpine Linux Mirror Source, e.g. mirrors.aliyun.com"
} }

View File

@ -475,5 +475,5 @@
"代理地址, 支持HTTP(S)/SOCK5": "代理地址, 支持HTTP(S)/SOCK5", "代理地址, 支持HTTP(S)/SOCK5": "代理地址, 支持HTTP(S)/SOCK5",
"NPM 镜像源": "NPM 镜像源", "NPM 镜像源": "NPM 镜像源",
"PyPI 镜像源": "PyPI 镜像源", "PyPI 镜像源": "PyPI 镜像源",
"alpine linux 镜像源": "alpine linux 镜像源" "alpine linux 镜像源, 例如 mirrors.aliyun.com": "alpine linux 镜像源, 例如 mirrors.aliyun.com"
} }

View File

@ -6,6 +6,7 @@ import { request } from '@/utils/http';
import './index.less'; import './index.less';
import Ansi from 'ansi-to-react'; import Ansi from 'ansi-to-react';
import pick from 'lodash/pick'; import pick from 'lodash/pick';
import WebSocketManager from '@/utils/websocket';
const dataMap = { const dataMap = {
'dependence-proxy': 'dependenceProxy', 'dependence-proxy': 'dependenceProxy',
@ -38,18 +39,13 @@ const Dependence = () => {
}; };
const updateSystemConfigStream = (path: keyof typeof dataMap) => { const updateSystemConfigStream = (path: keyof typeof dataMap) => {
setLog('执行中...'); setLog('执行中...\n');
request request
.put<string>( .put<string>(
`${config.apiPrefix}system/config/${path}`, `${config.apiPrefix}system/config/${path}`,
pick(systemConfig, dataMap[path]), pick(systemConfig, dataMap[path]),
{
responseType: 'stream',
},
) )
.then((res) => { .then((res) => {})
setLog(() => res);
})
.catch((error: any) => { .catch((error: any) => {
console.log(error); console.log(error);
}); });
@ -72,6 +68,22 @@ const Dependence = () => {
}); });
}; };
const handleMessage = (payload: any) => {
const { message } = payload;
setLog((p) => `${p}${message}`);
};
useEffect(() => {
const ws = WebSocketManager.getInstance();
ws.subscribe('updateNodeMirror', handleMessage);
ws.subscribe('updateLinuxMirror', handleMessage);
return () => {
ws.subscribe('updateNodeMirror', handleMessage);
ws.unsubscribe('updateLinuxMirror', handleMessage);
};
}, []);
useEffect(() => { useEffect(() => {
getSystemConfig(); getSystemConfig();
}, []); }, []);
@ -87,7 +99,7 @@ const Dependence = () => {
<Input.Group compact> <Input.Group compact>
<Input <Input
placeholder={intl.get('代理地址, 支持HTTP(S)/SOCK5')} placeholder={intl.get('代理地址, 支持HTTP(S)/SOCK5')}
style={{ width: 330 }} style={{ width: 360 }}
value={systemConfig?.dependenceProxy} value={systemConfig?.dependenceProxy}
onChange={(e) => { onChange={(e) => {
setSystemConfig({ setSystemConfig({
@ -110,7 +122,7 @@ const Dependence = () => {
<Form.Item label={intl.get('Node 软件包镜像源')} name="node"> <Form.Item label={intl.get('Node 软件包镜像源')} name="node">
<Input.Group compact> <Input.Group compact>
<Input <Input
style={{ width: 330 }} style={{ width: 360 }}
placeholder={intl.get('NPM 镜像源')} placeholder={intl.get('NPM 镜像源')}
value={systemConfig?.nodeMirror} value={systemConfig?.nodeMirror}
onChange={(e) => { onChange={(e) => {
@ -134,7 +146,7 @@ const Dependence = () => {
<Form.Item label={intl.get('Python 软件包镜像源')} name="python"> <Form.Item label={intl.get('Python 软件包镜像源')} name="python">
<Input.Group compact> <Input.Group compact>
<Input <Input
style={{ width: 330 }} style={{ width: 360 }}
placeholder={intl.get('PyPI 镜像源')} placeholder={intl.get('PyPI 镜像源')}
value={systemConfig?.pythonMirror} value={systemConfig?.pythonMirror}
onChange={(e) => { onChange={(e) => {
@ -158,8 +170,10 @@ const Dependence = () => {
<Form.Item label={intl.get('Linux 软件包镜像源')} name="linux"> <Form.Item label={intl.get('Linux 软件包镜像源')} name="linux">
<Input.Group compact> <Input.Group compact>
<Input <Input
style={{ width: 330 }} style={{ width: 360 }}
placeholder={intl.get('alpine linux 镜像源')} placeholder={intl.get(
'alpine linux 镜像源, 例如 mirrors.aliyun.com',
)}
value={systemConfig?.linuxMirror} value={systemConfig?.linuxMirror}
onChange={(e) => { onChange={(e) => {
setSystemConfig({ setSystemConfig({
@ -185,7 +199,7 @@ const Dependence = () => {
fontFamily: 'Source Code Pro', fontFamily: 'Source Code Pro',
zoom: 0.83, zoom: 0.83,
maxHeight: '100%', maxHeight: '100%',
overflowY: 'auto' overflowY: 'auto',
}} }}
> >
<Ansi>{log}</Ansi> <Ansi>{log}</Ansi>

View File

@ -5,4 +5,6 @@ export type SockMessageType =
| 'updateSystemVersion' | 'updateSystemVersion'
| 'manuallyRunScript' | 'manuallyRunScript'
| 'runSubscriptionEnd' | 'runSubscriptionEnd'
| 'reloadSystem'; | 'reloadSystem'
| 'updateNodeMirror'
| 'updateLinuxMirror';