mirror of
https://github.com/whyour/qinglong.git
synced 2025-05-23 06:46:09 +08:00
脚本管理支持删除文件夹
This commit is contained in:
parent
4e8f36d9a4
commit
25b03d4345
|
@ -4,6 +4,7 @@ import {
|
||||||
readDirs,
|
readDirs,
|
||||||
getLastModifyFilePath,
|
getLastModifyFilePath,
|
||||||
readDir,
|
readDir,
|
||||||
|
emptyDir,
|
||||||
} from '../config/util';
|
} from '../config/util';
|
||||||
import { Router, Request, Response, NextFunction } from 'express';
|
import { Router, Request, Response, NextFunction } from 'express';
|
||||||
import { Container } from 'typedi';
|
import { Container } from 'typedi';
|
||||||
|
@ -169,17 +170,23 @@ export default (app: Router) => {
|
||||||
body: Joi.object({
|
body: Joi.object({
|
||||||
filename: Joi.string().required(),
|
filename: Joi.string().required(),
|
||||||
path: Joi.string().allow(''),
|
path: Joi.string().allow(''),
|
||||||
|
type: Joi.string().optional()
|
||||||
}),
|
}),
|
||||||
}),
|
}),
|
||||||
async (req: Request, res: Response, next: NextFunction) => {
|
async (req: Request, res: Response, next: NextFunction) => {
|
||||||
const logger: Logger = Container.get('logger');
|
const logger: Logger = Container.get('logger');
|
||||||
try {
|
try {
|
||||||
let { filename, path } = req.body as {
|
let { filename, path, type } = req.body as {
|
||||||
filename: string;
|
filename: string;
|
||||||
path: string;
|
path: string;
|
||||||
|
type: string;
|
||||||
};
|
};
|
||||||
const filePath = join(config.scriptPath, path, filename);
|
const filePath = join(config.scriptPath, path, filename);
|
||||||
fs.unlinkSync(filePath);
|
if (type === 'directory') {
|
||||||
|
emptyDir(filePath);
|
||||||
|
} else {
|
||||||
|
fs.unlinkSync(filePath);
|
||||||
|
}
|
||||||
res.send({ code: 200 });
|
res.send({ code: 200 });
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
return next(e);
|
return next(e);
|
||||||
|
|
|
@ -302,7 +302,6 @@ export function readDirs(
|
||||||
title: file,
|
title: file,
|
||||||
key,
|
key,
|
||||||
type: 'directory',
|
type: 'directory',
|
||||||
disabled: true,
|
|
||||||
parent: relativePath,
|
parent: relativePath,
|
||||||
children: readDirs(subPath, baseDir).sort(
|
children: readDirs(subPath, baseDir).sort(
|
||||||
(a: any, b: any) =>
|
(a: any, b: any) =>
|
||||||
|
@ -345,6 +344,21 @@ export function readDir(
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function emptyDir(path: string) {
|
||||||
|
const files = fs.readdirSync(path);
|
||||||
|
files.forEach(file => {
|
||||||
|
const filePath = `${path}/${file}`;
|
||||||
|
const stats = fs.statSync(filePath);
|
||||||
|
if (stats.isDirectory()) {
|
||||||
|
emptyDir(filePath);
|
||||||
|
} else {
|
||||||
|
fs.unlinkSync(filePath);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
fs.rmdirSync(path);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
export function promiseExec(command: string): Promise<string> {
|
export function promiseExec(command: string): Promise<string> {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
exec(
|
exec(
|
||||||
|
|
|
@ -139,12 +139,17 @@ const Script = () => {
|
||||||
if (node.key === select || !value) {
|
if (node.key === select || !value) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
setValue('加载中...');
|
|
||||||
const newMode = value ? LangMap[value.slice(-3)] : '';
|
|
||||||
setMode(isPhone && newMode === 'typescript' ? 'javascript' : newMode);
|
|
||||||
setSelect(node.key);
|
setSelect(node.key);
|
||||||
setTitle(node.key);
|
setTitle(node.key);
|
||||||
setCurrentNode(node);
|
setCurrentNode(node);
|
||||||
|
if (node.type === 'directory') {
|
||||||
|
setValue('请选择脚本文件');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const newMode = value ? LangMap[value.slice(-3)] : '';
|
||||||
|
setMode(isPhone && newMode === 'typescript' ? 'javascript' : newMode);
|
||||||
|
setValue('加载中...');
|
||||||
getDetail(node);
|
getDetail(node);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -257,11 +262,11 @@ const Script = () => {
|
||||||
title: `确认删除`,
|
title: `确认删除`,
|
||||||
content: (
|
content: (
|
||||||
<>
|
<>
|
||||||
确认删除文件
|
确认删除
|
||||||
<Text style={{ wordBreak: 'break-all' }} type="warning">
|
<Text style={{ wordBreak: 'break-all' }} type="warning">
|
||||||
{select}
|
{select}
|
||||||
</Text>{' '}
|
</Text>
|
||||||
,删除后不可恢复
|
文件{currentNode.type === 'directory' ? '夹及其子文件':''},删除后不可恢复
|
||||||
</>
|
</>
|
||||||
),
|
),
|
||||||
onOk() {
|
onOk() {
|
||||||
|
@ -270,6 +275,7 @@ const Script = () => {
|
||||||
data: {
|
data: {
|
||||||
filename: currentNode.title,
|
filename: currentNode.title,
|
||||||
path: currentNode.parent || '',
|
path: currentNode.parent || '',
|
||||||
|
type: currentNode.type
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
.then(({ code }) => {
|
.then(({ code }) => {
|
||||||
|
@ -520,6 +526,7 @@ const Script = () => {
|
||||||
></Input.Search>
|
></Input.Search>
|
||||||
<div className={styles['left-tree-scroller']} ref={treeDom}>
|
<div className={styles['left-tree-scroller']} ref={treeDom}>
|
||||||
<Tree
|
<Tree
|
||||||
|
expandAction="click"
|
||||||
className={styles['left-tree']}
|
className={styles['left-tree']}
|
||||||
treeData={filterData}
|
treeData={filterData}
|
||||||
showIcon={true}
|
showIcon={true}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user