mirror of
https://github.com/whyour/qinglong.git
synced 2025-07-29 16:06:07 +08:00
移除无用的代码
This commit is contained in:
parent
23380c0ca0
commit
d708fba22f
|
@ -1,6 +1,8 @@
|
||||||
import { Router } from 'express';
|
import { Router } from 'express';
|
||||||
import * as pty from 'node-pty';
|
import * as pty from 'node-pty';
|
||||||
import os from 'os';
|
import os from 'os';
|
||||||
|
import Container from 'typedi';
|
||||||
|
import { Logger } from 'winston';
|
||||||
// Whether to use binary transport.
|
// Whether to use binary transport.
|
||||||
const USE_BINARY = os.platform() !== 'win32';
|
const USE_BINARY = os.platform() !== 'win32';
|
||||||
const route = Router();
|
const route = Router();
|
||||||
|
@ -10,6 +12,7 @@ export default (app: Router) => {
|
||||||
const logs = {};
|
const logs = {};
|
||||||
app.use('/', route);
|
app.use('/', route);
|
||||||
route.post('/terminals', (req, res) => {
|
route.post('/terminals', (req, res) => {
|
||||||
|
const logger: Logger = Container.get('logger');
|
||||||
const env = Object.assign({}, process.env);
|
const env = Object.assign({}, process.env);
|
||||||
env['COLORTERM'] = 'truecolor';
|
env['COLORTERM'] = 'truecolor';
|
||||||
const cols = parseInt(req.query.cols),
|
const cols = parseInt(req.query.cols),
|
||||||
|
@ -23,7 +26,7 @@ export default (app: Router) => {
|
||||||
encoding: USE_BINARY ? null : 'utf8',
|
encoding: USE_BINARY ? null : 'utf8',
|
||||||
});
|
});
|
||||||
|
|
||||||
console.log('Created terminal with PID: ' + term.pid);
|
logger.info('Created terminal with PID: ' + term.pid);
|
||||||
terminals[term.pid] = term;
|
terminals[term.pid] = term;
|
||||||
logs[term.pid] = '';
|
logs[term.pid] = '';
|
||||||
term.on('data', function (data) {
|
term.on('data', function (data) {
|
||||||
|
@ -34,13 +37,14 @@ export default (app: Router) => {
|
||||||
});
|
});
|
||||||
|
|
||||||
route.post('/terminals/:pid/size', (req, res) => {
|
route.post('/terminals/:pid/size', (req, res) => {
|
||||||
|
const logger: Logger = Container.get('logger');
|
||||||
const pid = parseInt(req.params.pid),
|
const pid = parseInt(req.params.pid),
|
||||||
cols = parseInt(req.query.cols),
|
cols = parseInt(req.query.cols),
|
||||||
rows = parseInt(req.query.rows),
|
rows = parseInt(req.query.rows),
|
||||||
term = terminals[pid];
|
term = terminals[pid];
|
||||||
|
|
||||||
term.resize(cols, rows);
|
term.resize(cols, rows);
|
||||||
console.log(
|
logger.info(
|
||||||
'Resized terminal ' +
|
'Resized terminal ' +
|
||||||
pid +
|
pid +
|
||||||
' to ' +
|
' to ' +
|
||||||
|
@ -53,8 +57,9 @@ export default (app: Router) => {
|
||||||
});
|
});
|
||||||
|
|
||||||
route.ws('/terminals/:pid', function (ws, req) {
|
route.ws('/terminals/:pid', function (ws, req) {
|
||||||
|
const logger: Logger = Container.get('logger');
|
||||||
const term = terminals[parseInt(req.params.pid)];
|
const term = terminals[parseInt(req.params.pid)];
|
||||||
console.log('Connected to terminal ' + term.pid);
|
logger.info('Connected to terminal ' + term.pid);
|
||||||
ws.send(logs[term.pid]);
|
ws.send(logs[term.pid]);
|
||||||
|
|
||||||
// string message buffering
|
// string message buffering
|
||||||
|
@ -104,7 +109,7 @@ export default (app: Router) => {
|
||||||
});
|
});
|
||||||
ws.on('close', function () {
|
ws.on('close', function () {
|
||||||
term.kill();
|
term.kill();
|
||||||
console.log('Closed terminal ' + term.pid);
|
logger.info('Closed terminal ' + term.pid);
|
||||||
// Clean things up
|
// Clean things up
|
||||||
delete terminals[term.pid];
|
delete terminals[term.pid];
|
||||||
delete logs[term.pid];
|
delete logs[term.pid];
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import { useState, useEffect, useCallback, Key, useRef } from 'react';
|
import { useState, useEffect, useRef } from 'react';
|
||||||
import config from '@/utils/config';
|
import config from '@/utils/config';
|
||||||
import { PageContainer } from '@ant-design/pro-layout';
|
import { PageContainer } from '@ant-design/pro-layout';
|
||||||
import { request } from '@/utils/http';
|
import { request } from '@/utils/http';
|
||||||
|
@ -8,112 +8,31 @@ import { AttachAddon } from 'xterm-addon-attach';
|
||||||
import { FitAddon } from 'xterm-addon-fit';
|
import { FitAddon } from 'xterm-addon-fit';
|
||||||
import { getToken } from '@/utils/auth';
|
import { getToken } from '@/utils/auth';
|
||||||
|
|
||||||
function getFilterData(keyword: string, data: any) {
|
|
||||||
const expandedKeys: string[] = [];
|
|
||||||
if (keyword) {
|
|
||||||
const tree: any = [];
|
|
||||||
data.forEach((item) => {
|
|
||||||
if (item.title.includes(keyword)) {
|
|
||||||
tree.push(item);
|
|
||||||
expandedKeys.push(...item.children.map((x) => x.key));
|
|
||||||
} else {
|
|
||||||
const children: any[] = [];
|
|
||||||
(item.children || []).forEach((subItem: any) => {
|
|
||||||
if (subItem.title.includes(keyword)) {
|
|
||||||
children.push(subItem);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
if (children.length > 0) {
|
|
||||||
tree.push({
|
|
||||||
...item,
|
|
||||||
children,
|
|
||||||
});
|
|
||||||
expandedKeys.push(...children.map((x) => x.key));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
return { tree, expandedKeys };
|
|
||||||
}
|
|
||||||
return { tree: data, expandedKeys };
|
|
||||||
}
|
|
||||||
|
|
||||||
const Log = () => {
|
const Log = () => {
|
||||||
const [width, setWdith] = useState('100%');
|
const [width, setWdith] = useState('100%');
|
||||||
const [marginLeft, setMarginLeft] = useState(0);
|
const [marginLeft, setMarginLeft] = useState(0);
|
||||||
const [marginTop, setMarginTop] = useState(-72);
|
const [marginTop, setMarginTop] = useState(-72);
|
||||||
const [title, setTitle] = useState('请选择日志文件');
|
|
||||||
const [value, setValue] = useState('请选择日志文件');
|
|
||||||
const [select, setSelect] = useState();
|
|
||||||
const [data, setData] = useState<any[]>([]);
|
|
||||||
const [filterData, setFilterData] = useState<any[]>([]);
|
|
||||||
const [loading, setLoading] = useState(false);
|
|
||||||
const [isPhone, setIsPhone] = useState(false);
|
|
||||||
|
|
||||||
const getConfig = () => {
|
|
||||||
request.get(`${config.apiPrefix}logs`).then((data) => {
|
|
||||||
const result = formatData(data.dirs) as any;
|
|
||||||
setData(result);
|
|
||||||
setFilterData(result);
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
const formatData = (tree: any[]) => {
|
|
||||||
return tree.map((x) => {
|
|
||||||
x.title = x.name;
|
|
||||||
x.value = x.name;
|
|
||||||
x.disabled = x.isDir;
|
|
||||||
x.key = x.name;
|
|
||||||
x.children = x.files.map((y: string) => ({
|
|
||||||
title: y,
|
|
||||||
value: `${x.name}/${y}`,
|
|
||||||
key: `${x.name}/${y}`,
|
|
||||||
parent: x.name,
|
|
||||||
isLeaf: true,
|
|
||||||
}));
|
|
||||||
return x;
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
const getLog = (node: any) => {
|
|
||||||
setLoading(true);
|
|
||||||
request
|
|
||||||
.get(`${config.apiPrefix}logs/${node.value}`)
|
|
||||||
.then((data) => {
|
|
||||||
setValue(data.data);
|
|
||||||
})
|
|
||||||
.finally(() => setLoading(false));
|
|
||||||
};
|
|
||||||
|
|
||||||
const onSelect = (value: any, node: any) => {
|
|
||||||
setSelect(value);
|
|
||||||
setTitle(node.parent || node.value);
|
|
||||||
getLog(node);
|
|
||||||
};
|
|
||||||
|
|
||||||
const ref = useRef<HTMLElement>(null);
|
const ref = useRef<HTMLElement>(null);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
setLoading(true);
|
request.post(`${config.apiPrefix}terminals?cols=80&rows=24`).then((pid) => {
|
||||||
request
|
const ws = new WebSocket(
|
||||||
.post(`${config.apiPrefix}terminals?cols=80&rows=24`)
|
`ws://${location.host}${
|
||||||
.then((pid) => {
|
config.apiPrefix
|
||||||
const ws = new WebSocket(
|
}terminals/${pid}?token=${getToken()}`,
|
||||||
`ws://${location.host}${
|
);
|
||||||
config.apiPrefix
|
ws.onopen = () => {
|
||||||
}terminals/${pid}?token=${getToken()}`,
|
const term = new Terminal();
|
||||||
);
|
const attachAddon = new AttachAddon(ws);
|
||||||
ws.onopen = () => {
|
const fitAddon = new FitAddon();
|
||||||
const term = new Terminal();
|
term.loadAddon(attachAddon);
|
||||||
const attachAddon = new AttachAddon(ws);
|
term.loadAddon(fitAddon);
|
||||||
const fitAddon = new FitAddon();
|
term.open(ref.current);
|
||||||
term.loadAddon(attachAddon);
|
fitAddon.fit();
|
||||||
term.loadAddon(fitAddon);
|
term.focus();
|
||||||
term.open(ref.current);
|
};
|
||||||
fitAddon.fit();
|
});
|
||||||
term.focus();
|
|
||||||
};
|
|
||||||
})
|
|
||||||
.finally(() => setLoading(false));
|
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
@ -121,20 +40,17 @@ const Log = () => {
|
||||||
setWdith('auto');
|
setWdith('auto');
|
||||||
setMarginLeft(0);
|
setMarginLeft(0);
|
||||||
setMarginTop(0);
|
setMarginTop(0);
|
||||||
setIsPhone(true);
|
|
||||||
} else {
|
} else {
|
||||||
setWdith('100%');
|
setWdith('100%');
|
||||||
setMarginLeft(0);
|
setMarginLeft(0);
|
||||||
setMarginTop(-72);
|
setMarginTop(-72);
|
||||||
setIsPhone(false);
|
|
||||||
}
|
}
|
||||||
getConfig();
|
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<PageContainer
|
<PageContainer
|
||||||
className="ql-container-wrapper terminal-wrapper"
|
className="ql-container-wrapper terminal-wrapper"
|
||||||
title={title}
|
title={'终端管理'}
|
||||||
header={{
|
header={{
|
||||||
style: {
|
style: {
|
||||||
padding: '4px 16px 4px 15px',
|
padding: '4px 16px 4px 15px',
|
||||||
|
|
Loading…
Reference in New Issue
Block a user