mirror of
https://github.com/whyour/qinglong.git
synced 2025-05-22 22:36:06 +08:00
脚本管理增加可预览检查
This commit is contained in:
parent
f9f78b4e05
commit
64fcbff715
|
@ -801,7 +801,7 @@ export default class NotificationService {
|
||||||
webhookContentType,
|
webhookContentType,
|
||||||
} = this.params;
|
} = this.params;
|
||||||
|
|
||||||
if (!webhookUrl.includes('$title') && !webhookBody.includes('$title')) {
|
if (!webhookUrl?.includes('$title') && !webhookBody?.includes('$title')) {
|
||||||
throw new Error('Url 或者 Body 中必须包含 $title');
|
throw new Error('Url 或者 Body 中必须包含 $title');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -186,6 +186,7 @@
|
||||||
"秒后重试": "Retry after seconds",
|
"秒后重试": "Retry after seconds",
|
||||||
"在您的设备上打开两步验证应用程序以查看您的身份验证代码并验证您的身份。": "Open the two-factor authentication application on your device to view your authentication code and verify your identity.",
|
"在您的设备上打开两步验证应用程序以查看您的身份验证代码并验证您的身份。": "Open the two-factor authentication application on your device to view your authentication code and verify your identity.",
|
||||||
"请选择脚本文件": "Please select a script file",
|
"请选择脚本文件": "Please select a script file",
|
||||||
|
"当前文件不支持预览": "The current file does not support preview",
|
||||||
"清空日志": "Clear Logs",
|
"清空日志": "Clear Logs",
|
||||||
"设置": "Settings",
|
"设置": "Settings",
|
||||||
"退出": "Exit",
|
"退出": "Exit",
|
||||||
|
|
|
@ -186,6 +186,7 @@
|
||||||
"秒后重试": "秒后重试",
|
"秒后重试": "秒后重试",
|
||||||
"在您的设备上打开两步验证应用程序以查看您的身份验证代码并验证您的身份。": "在您的设备上打开两步验证应用程序以查看您的身份验证代码并验证您的身份。",
|
"在您的设备上打开两步验证应用程序以查看您的身份验证代码并验证您的身份。": "在您的设备上打开两步验证应用程序以查看您的身份验证代码并验证您的身份。",
|
||||||
"请选择脚本文件": "请选择脚本文件",
|
"请选择脚本文件": "请选择脚本文件",
|
||||||
|
"当前文件不支持预览": "当前文件不支持预览",
|
||||||
"清空日志": "清空日志",
|
"清空日志": "清空日志",
|
||||||
"设置": "设置",
|
"设置": "设置",
|
||||||
"退出": "退出",
|
"退出": "退出",
|
||||||
|
|
|
@ -46,6 +46,7 @@ import RenameModal from './renameModal';
|
||||||
import { langs } from '@uiw/codemirror-extensions-langs';
|
import { langs } from '@uiw/codemirror-extensions-langs';
|
||||||
import { useHotkeys } from 'react-hotkeys-hook';
|
import { useHotkeys } from 'react-hotkeys-hook';
|
||||||
import prettyBytes from 'pretty-bytes';
|
import prettyBytes from 'pretty-bytes';
|
||||||
|
import { canPreviewInMonaco } from '@/utils/monaco';
|
||||||
const { Text } = Typography;
|
const { Text } = Typography;
|
||||||
|
|
||||||
const Script = () => {
|
const Script = () => {
|
||||||
|
@ -67,6 +68,10 @@ const Script = () => {
|
||||||
const [currentNode, setCurrentNode] = useState<any>();
|
const [currentNode, setCurrentNode] = useState<any>();
|
||||||
const [expandedKeys, setExpandedKeys] = useState<string[]>([]);
|
const [expandedKeys, setExpandedKeys] = useState<string[]>([]);
|
||||||
|
|
||||||
|
const handleIsEditing = (filename: string, value: boolean) => {
|
||||||
|
setIsEditing(value && canPreviewInMonaco(filename));
|
||||||
|
};
|
||||||
|
|
||||||
const getScripts = (needLoading: boolean = true) => {
|
const getScripts = (needLoading: boolean = true) => {
|
||||||
needLoading && setLoading(true);
|
needLoading && setLoading(true);
|
||||||
request
|
request
|
||||||
|
@ -128,6 +133,11 @@ const Script = () => {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!canPreviewInMonaco(node.title)) {
|
||||||
|
setValue(intl.get('当前文件不支持预览'));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const newMode = getEditorMode(value);
|
const newMode = getEditorMode(value);
|
||||||
setMode(isPhone && newMode === 'typescript' ? 'javascript' : newMode);
|
setMode(isPhone && newMode === 'typescript' ? 'javascript' : newMode);
|
||||||
setValue(intl.get('加载中...'));
|
setValue(intl.get('加载中...'));
|
||||||
|
@ -149,14 +159,14 @@ const Script = () => {
|
||||||
content: <>{intl.get('当前修改未保存,确定离开吗')}</>,
|
content: <>{intl.get('当前修改未保存,确定离开吗')}</>,
|
||||||
onOk() {
|
onOk() {
|
||||||
onSelect(keys[0], e.node);
|
onSelect(keys[0], e.node);
|
||||||
setIsEditing(false);
|
handleIsEditing(e.node.title, false);
|
||||||
},
|
},
|
||||||
onCancel() {
|
onCancel() {
|
||||||
console.log('Cancel');
|
console.log('Cancel');
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
setIsEditing(false);
|
handleIsEditing(e.node.title, false);
|
||||||
onSelect(keys[0], e.node);
|
onSelect(keys[0], e.node);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -196,18 +206,18 @@ const Script = () => {
|
||||||
if (node.type === 'file') {
|
if (node.type === 'file') {
|
||||||
setSelect(node.key);
|
setSelect(node.key);
|
||||||
setCurrentNode(node);
|
setCurrentNode(node);
|
||||||
setIsEditing(true);
|
handleIsEditing(node.title, true);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const editFile = () => {
|
const editFile = () => {
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
setIsEditing(true);
|
handleIsEditing(currentNode.title, true);
|
||||||
}, 300);
|
}, 300);
|
||||||
};
|
};
|
||||||
|
|
||||||
const cancelEdit = () => {
|
const cancelEdit = () => {
|
||||||
setIsEditing(false);
|
handleIsEditing(currentNode.title, false);
|
||||||
setValue(intl.get('加载中...'));
|
setValue(intl.get('加载中...'));
|
||||||
getDetail(currentNode);
|
getDetail(currentNode);
|
||||||
};
|
};
|
||||||
|
@ -240,7 +250,7 @@ const Script = () => {
|
||||||
if (code === 200) {
|
if (code === 200) {
|
||||||
message.success(`保存成功`);
|
message.success(`保存成功`);
|
||||||
setValue(content);
|
setValue(content);
|
||||||
setIsEditing(false);
|
handleIsEditing(currentNode.title, false);
|
||||||
}
|
}
|
||||||
resolve(null);
|
resolve(null);
|
||||||
})
|
})
|
||||||
|
@ -342,7 +352,7 @@ const Script = () => {
|
||||||
}
|
}
|
||||||
setData(newData);
|
setData(newData);
|
||||||
onSelect(_file.title, _file);
|
onSelect(_file.title, _file);
|
||||||
setIsEditing(true);
|
handleIsEditing(_file.title, true);
|
||||||
}
|
}
|
||||||
setIsAddFileModalVisible(false);
|
setIsAddFileModalVisible(false);
|
||||||
};
|
};
|
||||||
|
@ -472,7 +482,9 @@ const Script = () => {
|
||||||
label: intl.get('编辑'),
|
label: intl.get('编辑'),
|
||||||
key: 'edit',
|
key: 'edit',
|
||||||
icon: <EditOutlined />,
|
icon: <EditOutlined />,
|
||||||
disabled: !select,
|
disabled:
|
||||||
|
!select ||
|
||||||
|
(currentNode && !canPreviewInMonaco(currentNode?.title)),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
label: intl.get('重命名'),
|
label: intl.get('重命名'),
|
||||||
|
@ -554,7 +566,10 @@ const Script = () => {
|
||||||
</Tooltip>,
|
</Tooltip>,
|
||||||
<Tooltip title={intl.get('编辑')}>
|
<Tooltip title={intl.get('编辑')}>
|
||||||
<Button
|
<Button
|
||||||
disabled={!select}
|
disabled={
|
||||||
|
!select ||
|
||||||
|
(currentNode && !canPreviewInMonaco(currentNode?.title))
|
||||||
|
}
|
||||||
type="primary"
|
type="primary"
|
||||||
onClick={editFile}
|
onClick={editFile}
|
||||||
icon={<EditOutlined />}
|
icon={<EditOutlined />}
|
||||||
|
|
7
src/utils/monaco/index.ts
Normal file
7
src/utils/monaco/index.ts
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
import * as monaco from 'monaco-editor';
|
||||||
|
|
||||||
|
export function canPreviewInMonaco(fileName: string): boolean {
|
||||||
|
const supportedLanguages = monaco.languages.getLanguages();
|
||||||
|
const ext = fileName.slice(fileName.lastIndexOf('.')).toLowerCase();
|
||||||
|
return supportedLanguages.some((lang) => lang.extensions?.includes(ext));
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user