Skip to content

Commit

Permalink
2.0.5 环境变量添加
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaobaidadada committed Jan 16, 2025
1 parent dbba9d2 commit dafe3c1
Show file tree
Hide file tree
Showing 9 changed files with 95 additions and 47 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "filecat",
"version": "2.0.4",
"version": "2.0.5",
"description": "filecat 文件管理器",
"author": "xiaobaidadada",
"scripts": {
Expand Down
1 change: 1 addition & 0 deletions src/common/req/user.req.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ export enum UserAuth {
filecat_file_context_update = 27 , // 仅仅是内容更新 这个和上一个有一个可以,就可以更新
shell_cmd_check = 28 , // cmd shell 命令 检测是否能运行
role_manage = 29 , //角色管理
env_path_update = 30 // 环境路径管理
}

export class UserData extends UserLogin {
Expand Down
5 changes: 3 additions & 2 deletions src/main/domain/data/data_type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ export enum data_common_key {
token_setting = "token_setting",
files_pre_mulu_key = "files_pre_mulu_key", // 废弃 文件目录
sys_software = "sys_software",
extra_env_path = "extra_env_path",
protection_directory = "sys_protection_directory",
// extra_env_path = "extra_env_path",
// protection_directory = "sys_protection_directory",
self_auth_jscode = "self_auth_jscode",
navindex_video_key = "navindex_video_tag_key",
systemd_key = "systemd_key",
Expand All @@ -58,6 +58,7 @@ export enum data_common_key {
// 自定义shell cmd 检测
self_shell_cmd_check_open_status = "self_shell_cmd_check_open_status",
self_shell_cmd_jscode = "self_shell_cmd_jscode", // js code 文件名字
extra_env_path_list_key = "extra_env_path_list_key"
}


Expand Down
23 changes: 12 additions & 11 deletions src/main/domain/setting/setting.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -196,17 +196,18 @@ export class SettingController {



// // path路径
// @Get("/env/path/get")
// getEnvPath() {
// return Sucess(settingService.getEnvPath());
// }
//
// @Post('/env/path/save')
// setEnvPath(@Body() req:{path:string}) {
// settingService.setEnvPath(req.path);
// return Sucess("1");
// }
// path路径
@Get("/env/path/get")
getEnvPath() {
return Sucess(settingService.getEnvPath());
}

@Post('/env/path/save')
setEnvPath(@Body() req:{paths:any[]},@Req() ctx) {
userService.check_user_auth(ctx.headers.authorization,UserAuth.env_path_update);
settingService.setEnvPath(req.paths);
return Sucess("1");
}


// 获取保护目录
Expand Down
27 changes: 17 additions & 10 deletions src/main/domain/setting/setting.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {data_common_key, data_dir_tem_name} from "../data/data_type";
import * as vm from "node:vm";
import {userController} from "../user/user.controller";
import {userService} from "../user/user.service";
import {sysType} from "../shell/shell.service";

const needle = require('needle');

Expand Down Expand Up @@ -320,18 +321,24 @@ export class SettingService {
this.getFilesSetting(token);
}

extra_env_path = data_common_key.extra_env_path
// extra_env_path = data_common_key.extra_env_path

// public getEnvPath() {
// return DataUtil.get(this.extra_env_path) ?? "";
// }
//
// setEnvPath(path: string) {
// DataUtil.set(this.extra_env_path, path);
// return Sucess("1");
// }
public getEnvPath() {
return DataUtil.get(data_common_key.extra_env_path_list_key) ??[];
}

public get_env_list() {
const list:any[] = DataUtil.get(data_common_key.extra_env_path_list_key) ??[];
const s = sysType === "win" ? ";" : ":";
return list.map(v=>v.path).join(s);
}

setEnvPath(paths: any[]) {
DataUtil.set(data_common_key.extra_env_path_list_key, paths);
return Sucess("1");
}

protection_directory = data_common_key.protection_directory
// protection_directory = data_common_key.protection_directory

// 获取系统保护目录
protectionDirGet(token): { path: string }[] {
Expand Down
1 change: 1 addition & 0 deletions src/main/domain/shell/PtyShell.ts
Original file line number Diff line number Diff line change
Expand Up @@ -826,6 +826,7 @@ export class PtyShell {
this.child.stderr.on('data', (data) => {
const v = data.toString();
this.send_and_enter(v);
this.next_not_enter = false; // 下一次的换行输出 上一次没有换行
});
this.child.on('exit', (code) => {
this.close_child();
Expand Down
5 changes: 2 additions & 3 deletions src/main/domain/shell/shell.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ const pty: any = require("@xiaobaidadada/node-pty-prebuilt")


const socketMap: Map<string, any> = new Map();
const init_sys_env_path = process.env.PATH;

let line = "";

Expand All @@ -79,8 +78,7 @@ export class ShellService {
async open(data: WsData<ShellInitPojo>) {
const socketId = (data.wss as Wss).id;
// 要传递的环境变量
// process.env.PATH = init_sys_env_path +(sysType === "win" ? ";" : ":") + settingService.getEnvPath();
process.env.PATH = init_sys_env_path;
const PATH = process.env.PATH +(sysType === "win" ? ";" : ":") + settingService.get_env_list();
const pojo = data.context as ShellInitPojo;
if(pojo.init_path) pojo.init_path = decodeURIComponent(pojo.init_path);
const sysPath = path.join(settingService.getFileRootPath(pojo.http_token), (pojo.init_path !== null && pojo.init_path !== "null") ? pojo.init_path : "");
Expand All @@ -90,6 +88,7 @@ export class ShellService {
rows: pojo.rows,
cwd: sysPath,
node_pty:pty,
env:{PATH},
// prompt_call:()=>{
// re
// },
Expand Down
69 changes: 49 additions & 20 deletions src/web/project/component/setting/Env.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,14 @@ export function Env() {
const [rows, setRows] = useState([]);
const [rows_outside_software, setRows_outside_software] = useState([]);
const [prompt_card, set_prompt_card] = useRecoilState($stroe.prompt_card);
const [env_path,set_env_path] = useState("");
// const [env_path,set_env_path] = useState("");
const [protection_dir_rows,set_protection_dir_rows] = useState([]);
const [env_path_dir_rows,set_env_path_dir_rows] = useState([]);

const headers = [t("编号"),t("路径"), t("是否默认"), t("备注") ];
const headers_outside_software = [t("软件"),t("是否安装"), t("路径") ];
const protection_dir_headers = [t("编号"),t("路径"),t("备注")];
const env_path_dir_headers = [t("编号"),t("路径"),t("备注")];
const {check_user_auth} = use_auth_check();

const getItems = async () => {
Expand All @@ -38,11 +40,11 @@ export function Env() {
if (result1.code === RCode.Sucess) {
setRows_outside_software(result1.data);
}
// // env path
// const result2 = await settingHttp.get("env/path/get");
// if (result2.code === RCode.Sucess) {
// set_env_path(result2.data);
// }
// env path
const result2 = await settingHttp.get("env/path/get");
if (result2.code === RCode.Sucess) {
set_env_path_dir_rows(result2.data);
}
// 保护目录
const result3 = await settingHttp.get("protection_dir");
if (result3.code === RCode.Sucess) {
Expand Down Expand Up @@ -72,6 +74,7 @@ export function Env() {
reloadUserInfo();
}
}

const add = ()=>{
setRows([...rows,{note:"",default:false,path:""}]);
}
Expand All @@ -86,6 +89,13 @@ export function Env() {
protection_dir_rows.splice(index, 1);
set_protection_dir_rows([...protection_dir_rows]);
}
const env_path_dir_add = ()=>{
set_env_path_dir_rows([...env_path_dir_rows,{path:"",note:""}]);
}
const env_path_dir_del = (index)=>{
env_path_dir_rows.splice(index, 1);
set_env_path_dir_rows([...env_path_dir_rows]);
}
const onChange = (item,value,index)=> {
const list = [];
for (let i=0; i<rows.length; i++) {
Expand Down Expand Up @@ -134,6 +144,10 @@ export function Env() {
context = <div>
用于在文件夹下切换根目录
</div>
} else if(id === "环境路径") {
context = <div>
当在不同用户环境下运行的时候由于没有执行终端去加载PATH,这里可以添加额外的PATH路径
</div>
}
set_prompt_card({open:true,title:"信息",context_div : (
<div >
Expand All @@ -142,13 +156,13 @@ export function Env() {
)})
}

// const update_env_path = async ()=>{
// const result = await settingHttp.post("env/path/save", {path:env_path});
// if (result.code === RCode.Sucess) {
// NotySucess("保存成功")
// initUserInfo();
// }
// }
const update_env_path = async ()=>{
const result = await settingHttp.post("env/path/save", {paths:env_path_dir_rows});
if (result.code === RCode.Sucess) {
NotySucess("保存成功")
initUserInfo();
}
}
return (<Row>
<Column widthPer={50}>
<Dashboard>
Expand Down Expand Up @@ -205,12 +219,27 @@ export function Env() {
</Dashboard>

</Column>
{/*<Column>*/}
{/* <Dashboard>*/}
{/* <Card title={t("PATH路径")} rightBottomCom={<ButtonText text={t('更新')} clickFun={update_env_path}/>}>*/}
{/* <InputText placeholder={t('多个path路径使用:(linux)或者;(windwos)分割')} value={env_path} handleInputChange={(value)=>{set_env_path(value)}} />*/}
{/* </Card>*/}
{/* </Dashboard>*/}
{/*</Column>*/}
<Column>
<Dashboard>
<CardFull self_title={<span className={" div-row "}><h2>{t("PATH")}</h2>
<ActionButton icon={"info"} onClick={()=>{soft_ware_info_click("环境路径")}} title={"信息"}/></span>}
titleCom={<div><ActionButton icon={"add"} title={t("添加")} onClick={env_path_dir_add}/>
<ActionButton icon={"save"} title={t("保存")} onClick={update_env_path}/></div>}>
<Table headers={env_path_dir_headers} rows={env_path_dir_rows.map((item, index) => {
const new_list = [
<div>{index}</div>,
<InputText value={item.path} handleInputChange={(value) => {
item.path = value;
}} no_border={true}/>,
<InputText value={item.note} handleInputChange={(value) => {
item.note = value;
}} no_border={true}/>,
<ActionButton icon={"delete"} title={t("删除")} onClick={() => env_path_dir_del(index)}/> ,
];
return new_list;
})} width={"10rem"}/>
</CardFull>
</Dashboard>
</Column>
</Row>)
}
9 changes: 9 additions & 0 deletions src/web/project/component/setting/component/Permission.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,15 @@ export function Permission(props:{
}}/>
{t("shell命令检测")}
</div>
<div>
<input type="checkbox"
disabled={props.is_disable(UserAuth.env_path_update)}
checked={props.is_selected(UserAuth.env_path_update)}
onChange={() => {
props.select_auth(UserAuth.env_path_update)
}}/>
{t("PATH路径修改")}
</div>
</div>
<h3>{t("标签编辑权限")}</h3>
<div className={"checkbox_container"}>
Expand Down

0 comments on commit dafe3c1

Please sign in to comment.