Skip to content

Commit

Permalink
2.0.4 优化一些细节
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaobaidadada committed Jan 16, 2025
1 parent 3b7de3d commit 0131fff
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 9 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ url: http://116.198.245.137:5569/
4. studio 编辑器,右键文件夹可以打开一个类似vscode的编辑器页面,可用于linux程序临时开发环境。
5. [excalidraw](https://github.com/excalidraw/excalidraw)绘图编辑器,这是一个很好用白板工具。
5. 切换根目录,在设置中添加多个文件夹路径后,可以在右上角选择切换根目录,只对一个session生效。
6. 终端,内嵌了一个自定义终端,可以实现任意命令的过滤,防止用户执行恶意的rm -r / 命令,因为不是实际的pty环境,所以像node这样的软件想要交互式执行需要添加-i或者自定义处理函数。
6. 终端,内嵌了一个自定义终端,可以实现任意命令的过滤,防止用户执行恶意的类似rm -rf / 命令,因为不是实际的pty环境,所以像node这样的软件想要交互式执行需要添加-i或者自定义处理函数,对于pty执行的程序虽然可以不用输出绝对路径,但是要输入文件的后缀,比如 cmd不能执行但是cmd.exe可以执行
7. 超大文本日志查看器,对任意大小的文本右键使用作为日志类型查看,点击窗口后可以使用上下键来快速滚动翻页,还可以实时输出内容。
- ssh代理,ftp代理: 可以管理多个linux服务器,作用和winscp类似,让终端和文件管理更方便。
- http代理,类似postman 的发送http请求功能
Expand Down
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
{
"name": "filecat",
"version": "2.0.3",
"version": "2.0.4",
"description": "filecat 文件管理器",
"author": "xiaobaidadada",
"scripts": {
"dev": "node --require ts-node/register ./shell/dev.js --env ./env",
"server-debug-js": "tsc && node build/server/main/server.js --env ./env",
"server-dev-inspect": "node --inspect=0.0.0.0:9001 --require ts-node/register ./shell/dev.js --env ./env",
"dev-inspect": "node --inspect=0.0.0.0:9001 --require ts-node/register ./shell/dev.js --env ./env",
"server-dev-inspect": "node --inspect=0.0.0.0:9001 --require ts-node/register ./src/main/server.ts --env ./env ",
"server-dev": "node --require ts-node/register ./src/main/server.ts --env ./env",
"webpack-dev": "npx webpack serve --mode development --config shell/config/webpack.config.js",
"generate-proto": "node --require ts-node/register ./src/common/proto/proto.generate.ts",
Expand Down
13 changes: 8 additions & 5 deletions src/main/domain/shell/PtyShell.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
* 读取输出与写入输入:捕获输出并发送输入,模拟用户交互。
* 信号和控制字符支持:处理回车、换行等控制字符,并支持信号转发。
*/
import {getSys} from "./shell.service";
import {getShell, getSys} from "./shell.service";
import {SysEnum} from "../../../common/req/user.req";

/**
Expand Down Expand Up @@ -780,9 +780,9 @@ export class PtyShell {
// this.on_call(`\n\r`); // 先换个行
// }
if ((use_noe_pty || this.shell_set.has(exe)) && this.node_pty) {
if (!exe.includes('exe') && exe !== 'bash' && exe !== 'sh') {
exe += '.exe';
}
// if (!exe.includes('exe') && exe !== 'bash' && exe !== 'sh') {
// exe += '.exe';
// }
this.on_call(`\n\r`); // 先换个行
this.child = this.node_pty.spawn(exe, params, {
name: 'xterm-color',
Expand All @@ -800,6 +800,7 @@ export class PtyShell {
this.child.onExit(({exitCode, signal}) => {
this.close_child();
this.send_and_enter(`pty with ${exitCode}`);
this.next_not_enter = false; // 下一次的换行输出 上一次没有换行
if (this.on_child_kill_call)
this.on_child_kill_call(exitCode);
})
Expand All @@ -808,7 +809,7 @@ export class PtyShell {
this.is_pty = false;
// 其他的没有必要再创建一个 tty 都是资源消耗
this.child = this.node_require.child_process.spawn(exe, params, {
shell:true,
shell:getShell(),
cwd: this.cwd, // 设置子进程的工作目录
env: {...process.env, ...this.env,LANG: 'en_US.UTF-8'}, // 传递环境变量
// stdio: 'inherit' // 让子进程的输入输出与父进程共享 pipe ignore inherit
Expand All @@ -833,10 +834,12 @@ export class PtyShell {
} else {
this.send_and_enter(``);
}
this.next_not_enter = false; // 下一次的换行输出 上一次没有换行
if (this.on_child_kill_call)
this.on_child_kill_call(code);
});
this.child.on('error', (error) => {
this.next_not_enter = false; // 下一次的换行输出 上一次没有换行
this.close_child();
this.send_and_enter(JSON.stringify(error));
});
Expand Down
2 changes: 1 addition & 1 deletion src/main/domain/shell/shell.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ let line = "";

let prompt = `${process.env.USER ?? process.env.USERNAME}>`;

const shell_list = ['bash', 'sh', 'cmd', 'cmd.exe', 'pwsh', 'pwsh.exe', 'powershell', 'powershell.exe','vim','nano','cat','tail']; // 一些必须用 node_pty 执行的
const shell_list = ['bash', 'sh', 'cmd.exe', 'pwsh.exe', 'powershell.exe','vim','nano','cat','tail']; // 一些必须用 node_pty 执行的 powershell 不行 必须得 powershell.exe
// ANSI 转义序列,设置绿色、蓝色、重置颜色
const green = '\x1b[32m'; // 绿色
const blue = '\x1b[34m'; // 蓝色
Expand Down

0 comments on commit 0131fff

Please sign in to comment.