25/09/24 10:00~11:30 停机维护
This commit is contained in:
@@ -1,6 +1,21 @@
|
||||
let vs_socket = null;
|
||||
let debounceTimeout;
|
||||
|
||||
// 定义代码类型到文件后缀的映射
|
||||
const typeToExtension = {
|
||||
'python': 'py',
|
||||
'cpp': 'cpp',
|
||||
'javascript': 'js',
|
||||
'java': 'java',
|
||||
'html': 'html',
|
||||
'css': 'css',
|
||||
'php': 'php',
|
||||
'ruby': 'rb',
|
||||
'go': 'go',
|
||||
'c': 'c',
|
||||
'cs': 'cs'
|
||||
// 可以根据需要添加更多映射
|
||||
};
|
||||
|
||||
// 缓冲器函数(防抖)
|
||||
function debounceSendToServer(data, delay) {
|
||||
if (debounceTimeout) {
|
||||
@@ -50,6 +65,7 @@ vs_socket.on('connect', () => {
|
||||
// vscode.window.showInformationMessage('Connected to server');
|
||||
console.log('Connected to server');
|
||||
vs_socket.emit('login', { config: code_like_config });
|
||||
vs_socket.emit('load_chapter',{config: code_like_config})
|
||||
});
|
||||
vs_socket.on('disconnect', () => {
|
||||
// vscode.window.showInformationMessage('Disconnected from server');
|
||||
@@ -60,4 +76,29 @@ vs_socket.on('terminal',(data)=>{
|
||||
socket.emit("pty_input", {"input": data.data+'\r\n'}, function(response) {
|
||||
});
|
||||
})
|
||||
|
||||
vs_socket.on('code-file',(data)=>{
|
||||
if (data.type=='create'){
|
||||
let title = data.chapter_title
|
||||
let content = data.data
|
||||
const codeBlockRegex = /^```(\w+)\s([\s\S]*?)\s```$/;
|
||||
const match = content.match(codeBlockRegex);
|
||||
|
||||
if (match && match.length >= 3) {
|
||||
const codeType = match[1].toLowerCase();
|
||||
const codeContent = match[2].trim();
|
||||
// 根据代码类型获取后缀,如果没有匹配的则使用txt
|
||||
const fileExtension = typeToExtension[codeType] || 'txt';
|
||||
|
||||
console.log('代码类型:', codeType);
|
||||
console.log('文件后缀:', fileExtension);
|
||||
console.log('代码内容:', codeContent);
|
||||
|
||||
createAndWriteNewFile(title+'.'+fileExtension, codeContent)
|
||||
|
||||
// 这里可以使用解析出的结果进行后续操作
|
||||
} else {
|
||||
console.error('无效的代码格式');
|
||||
// 处理格式错误的情况
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
@@ -262,6 +262,12 @@ function loadFileContent(item) {
|
||||
}
|
||||
|
||||
|
||||
function createAndWriteNewFile(path, content){
|
||||
fetch(`/vsc-like/create-file`, { method: 'POST', body: JSON.stringify({ path: path, parent: '.' }) , headers: { 'Content-Type': 'application/json' } })
|
||||
.then(() => {
|
||||
postSaveFile('./'+path, content)
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
// 新建文件
|
||||
@@ -303,6 +309,12 @@ function createNewFolder(event) {
|
||||
}
|
||||
}
|
||||
|
||||
function postSaveFile(path, content){
|
||||
|
||||
fetch(`/vsc-like/save-file`, { method: 'POST', body: JSON.stringify({ path: path, content: content }) , headers: { 'Content-Type': 'application/json' } })
|
||||
.then(() => loadFileTree());
|
||||
}
|
||||
|
||||
// 保存文件
|
||||
function saveFile(event) {
|
||||
event.stopPropagation();
|
||||
@@ -311,8 +323,7 @@ function saveFile(event) {
|
||||
if (selectedItem.path==undefined){
|
||||
selectedItem.path='.';
|
||||
}
|
||||
fetch(`/vsc-like/save-file`, { method: 'POST', body: JSON.stringify({ path: selectedItem.path+'/'+selectedItem.name, content: content }) , headers: { 'Content-Type': 'application/json' } })
|
||||
.then(() => loadFileTree());
|
||||
postSaveFile(selectedItem.path+'/'+selectedItem.name, content)
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user