aigems commited on
Commit
fed74fd
·
1 Parent(s): 518a557
Files changed (2) hide show
  1. out.py +0 -35
  2. routes/command.js +1 -0
out.py DELETED
@@ -1,35 +0,0 @@
1
- import os
2
-
3
- def get_all_files(directory, exclude=None):
4
- if exclude is None:
5
- exclude = {'.git', '.gitattributes'}
6
-
7
- file_list = []
8
- for root, dirs, files in os.walk(directory, topdown=True):
9
- # 从 dirs 列表中移除要排除的目录
10
- dirs[:] = [d for d in dirs if d not in exclude]
11
-
12
- for file in files:
13
- if file not in exclude:
14
- file_list.append(os.path.join(root, file))
15
- return file_list
16
-
17
- def write_file_contents(file_list, output_file):
18
- with open(output_file, 'w', encoding='utf-8') as out:
19
- for file_path in file_list:
20
- out.write(f"文件名:{file_path}\n")
21
- out.write("文件内容:\n")
22
- try:
23
- with open(file_path, 'r', encoding='utf-8') as f:
24
- content = f.read()
25
- out.write(content)
26
- except Exception as e:
27
- out.write(f"无法读取文件内容: {str(e)}\n")
28
- out.write("\n\n" + "-"*50 + "\n\n")
29
-
30
- if __name__ == "__main__":
31
- current_directory = os.getcwd()
32
- exclude_list = {'.git', '.gitattributes'} # 可以根据需要添加更多要排除的项
33
- file_list = get_all_files(current_directory, exclude_list)
34
- write_file_contents(file_list, 'output.txt')
35
- print("文件内容已输出到 output.txt")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
routes/command.js CHANGED
@@ -60,6 +60,7 @@ router.post('/execute', async (req, res) => {
60
  await fs.writeFile(historyFilePath, JSON.stringify(history, null, 2));
61
  } catch (writeError) {
62
  logger.error('写入命令历史失败:', writeError);
 
63
  }
64
 
65
  logger.info(`用户 ${req.user.username} 成功执行命令: ${command}`);
 
60
  await fs.writeFile(historyFilePath, JSON.stringify(history, null, 2));
61
  } catch (writeError) {
62
  logger.error('写入命令历史失败:', writeError);
63
+ return res.status(500).json({ error: '写入命令历史失败' });
64
  }
65
 
66
  logger.info(`用户 ${req.user.username} 成功执行命令: ${command}`);