mirror of
https://github.com/whyour/qinglong.git
synced 2025-07-07 11:56:08 +08:00
脚本管理支持新增文件夹
This commit is contained in:
parent
d23fcfaa5a
commit
967071ad4e
|
@ -77,12 +77,14 @@ export default (app: Router) => {
|
||||||
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, content, originFilename } = req.body as {
|
let { filename, path, content, originFilename, directory } =
|
||||||
filename: string;
|
req.body as {
|
||||||
path: string;
|
filename: string;
|
||||||
content: string;
|
path: string;
|
||||||
originFilename: string;
|
content: string;
|
||||||
};
|
originFilename: string;
|
||||||
|
directory: string;
|
||||||
|
};
|
||||||
|
|
||||||
if (!path) {
|
if (!path) {
|
||||||
path = config.scriptPath;
|
path = config.scriptPath;
|
||||||
|
@ -105,6 +107,11 @@ export default (app: Router) => {
|
||||||
return res.send({ code: 200 });
|
return res.send({ code: 200 });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (directory) {
|
||||||
|
fs.mkdirSync(join(path, directory), { recursive: true });
|
||||||
|
return res.send({ code: 200 });
|
||||||
|
}
|
||||||
|
|
||||||
if (!originFilename) {
|
if (!originFilename) {
|
||||||
originFilename = filename;
|
originFilename = filename;
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,25 +32,26 @@ const EditScriptNameModal = ({
|
||||||
const [loading, setLoading] = useState(false);
|
const [loading, setLoading] = useState(false);
|
||||||
const [dirs, setDirs] = useState<any[]>([]);
|
const [dirs, setDirs] = useState<any[]>([]);
|
||||||
const [file, setFile] = useState<File>();
|
const [file, setFile] = useState<File>();
|
||||||
const [type, setType] = useState<'blank' | 'upload'>('blank');
|
const [type, setType] = useState<'blank' | 'upload' | 'directory'>('blank');
|
||||||
|
|
||||||
const handleOk = async (values: any) => {
|
const handleOk = async (values: any) => {
|
||||||
setLoading(true);
|
setLoading(true);
|
||||||
values.path = values.path || '';
|
const { path = '', filename: inputFilename, directory } = values;
|
||||||
const formData = new FormData();
|
const formData = new FormData();
|
||||||
formData.append('file', file as any);
|
formData.append('file', file as any);
|
||||||
formData.append('filename', values.filename);
|
formData.append('filename', inputFilename);
|
||||||
formData.append('path', values.path);
|
formData.append('path', path);
|
||||||
formData.append('content', '');
|
formData.append('content', '');
|
||||||
|
formData.append('directory', directory);
|
||||||
request
|
request
|
||||||
.post(`${config.apiPrefix}scripts`, {
|
.post(`${config.apiPrefix}scripts`, {
|
||||||
data: formData,
|
data: formData,
|
||||||
})
|
})
|
||||||
.then(({ code, data }) => {
|
.then(({ code, data }) => {
|
||||||
if (code === 200) {
|
if (code === 200) {
|
||||||
message.success('新建文件成功');
|
message.success(directory ? '新建文件夹成功' : '新建文件成功');
|
||||||
const key = values.path ? `${values.path}/` : '';
|
const key = path ? `${values.path}/` : '';
|
||||||
const filename = file ? file.name : values.filename;
|
const filename = file ? file.name : inputFilename;
|
||||||
handleCancel({
|
handleCancel({
|
||||||
filename,
|
filename,
|
||||||
path: values.path,
|
path: values.path,
|
||||||
|
@ -99,7 +100,7 @@ const EditScriptNameModal = ({
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Modal
|
<Modal
|
||||||
title="新建脚本"
|
title="新建"
|
||||||
visible={visible}
|
visible={visible}
|
||||||
forceRender
|
forceRender
|
||||||
centered
|
centered
|
||||||
|
@ -126,18 +127,36 @@ const EditScriptNameModal = ({
|
||||||
>
|
>
|
||||||
<Radio.Group onChange={typeChange}>
|
<Radio.Group onChange={typeChange}>
|
||||||
<Radio value="blank">空文件</Radio>
|
<Radio value="blank">空文件</Radio>
|
||||||
<Radio value="upload">本地上传</Radio>
|
<Radio value="upload">本地文件</Radio>
|
||||||
|
<Radio value="directory">文件夹</Radio>
|
||||||
</Radio.Group>
|
</Radio.Group>
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
{type === 'blank' && (
|
{type === 'blank' && (
|
||||||
<Form.Item
|
<Form.Item
|
||||||
name="filename"
|
name="filename"
|
||||||
label="文件名"
|
label="文件名"
|
||||||
rules={[{ required: true, message: '请输入文件名' }]}
|
rules={[
|
||||||
|
{ required: true, message: '请输入文件名' },
|
||||||
|
{
|
||||||
|
validator: (_, value) =>
|
||||||
|
value.includes('/')
|
||||||
|
? Promise.reject(new Error('文件名不能包含斜杠'))
|
||||||
|
: Promise.resolve(),
|
||||||
|
},
|
||||||
|
]}
|
||||||
>
|
>
|
||||||
<Input placeholder="请输入文件名" />
|
<Input placeholder="请输入文件名" />
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
)}
|
)}
|
||||||
|
{type === 'directory' && (
|
||||||
|
<Form.Item
|
||||||
|
name="directory"
|
||||||
|
label="文件夹名"
|
||||||
|
rules={[{ required: true, message: '请输入文件夹名' }]}
|
||||||
|
>
|
||||||
|
<Input placeholder="请输入文件夹名" />
|
||||||
|
</Form.Item>
|
||||||
|
)}
|
||||||
<Form.Item label="父目录" name="path">
|
<Form.Item label="父目录" name="path">
|
||||||
<TreeSelect
|
<TreeSelect
|
||||||
allowClear
|
allowClear
|
||||||
|
|
Loading…
Reference in New Issue
Block a user