aigems commited on
Commit
3563586
·
1 Parent(s): 8a37762
Files changed (1) hide show
  1. public/js/main.js +25 -28
public/js/main.js CHANGED
@@ -17,35 +17,32 @@ async function executeCommand() {
17
  showLoading(true);
18
  output.textContent = '正在执行命令...';
19
 
20
- async function executeCommand() {
21
-
22
- try {
23
- const response = await fetch('/api/execute', {
24
- method: 'POST',
25
- headers: {
26
- 'Content-Type': 'application/json',
27
- 'Authorization': `Bearer ${localStorage.getItem('token')}`
28
- },
29
- body: JSON.stringify({ command })
30
- });
31
- if (!response.ok) {
32
- throw new Error(`HTTP error! status: ${response.status}`);
33
- }
34
- const data = await response.json();
35
- // ... 处理成功响应 ...
36
- } catch (error) {
37
- console.error('执行命令时出错:', error);
38
- output.textContent = '错误: ' + (error.message || '未知错误');
39
- if (error.message.includes('403')) {
40
- // 处理 Forbidden 错误
41
- alert('访问被拒绝。请检查您的权限或重新登录。');
42
- // 可能需要重定向到登录页面或清除token
43
- localStorage.removeItem('token');
44
- checkLoginStatus();
45
- }
46
- } finally {
47
- showLoading(false);
48
  }
 
 
49
  }
50
  }
51
 
 
17
  showLoading(true);
18
  output.textContent = '正在执行命令...';
19
 
20
+ try {
21
+ const response = await fetch('/api/execute', {
22
+ method: 'POST',
23
+ headers: {
24
+ 'Content-Type': 'application/json',
25
+ 'Authorization': `Bearer ${localStorage.getItem('token')}`
26
+ },
27
+ body: JSON.stringify({ command })
28
+ });
29
+ if (!response.ok) {
30
+ throw new Error(`HTTP error! status: ${response.status}`);
31
+ }
32
+ const data = await response.json();
33
+ output.textContent = data.output || data.error || '命令执行成功,但没有输出。';
34
+ commandInput.value = '';
35
+ loadCommandHistory();
36
+ } catch (error) {
37
+ console.error('执行命令时出错:', error);
38
+ output.textContent = '错误: ' + (error.message || '未知错误');
39
+ if (error.message.includes('403')) {
40
+ alert('访问被拒绝。请检查您的权限或重新登录。');
41
+ localStorage.removeItem('token');
42
+ checkLoginStatus();
 
 
 
 
 
43
  }
44
+ } finally {
45
+ showLoading(false);
46
  }
47
  }
48