ok
Browse files- 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 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
});
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 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 |
|