修改保存逻辑:在上传文件前先通过C++编译服务验证脚本

- 修改model.ts的saveFileContent方法,在上传文件前先通过C++服务验证脚本
- 如果C++服务可连接,则先发送脚本进行编译验证,只有在返回200状态码(编译通过)后才上传到服务器
- 如果C++服务返回非200状态码(编译失败),则不允许上传并提示错误
- 如果C++服务不可连接,则直接上传到服务器
- 简化extension.ts中的保存事件监听器,仅执行UI更新和缓存更新
- 保持原有错误处理机制,确保在C++服务故障时也能正常上传文件

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
睿 安
2025-10-03 20:34:01 +08:00
parent 95dfc4397e
commit 859af05c7f
6 changed files with 113 additions and 113 deletions

62
dist/model.js vendored
View File

@@ -36,6 +36,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
exports.FileModel = void 0;
const vscode = __importStar(require("vscode"));
const apiClient_1 = require("./apiClient");
const localClient_1 = require("./localClient");
class FileModel {
constructor() {
this.fileList = new Map();
@@ -185,19 +186,60 @@ class FileModel {
}
// 保存文件内容
async saveFileContent(filePath, content) {
try {
const success = await this.apiClient.uploadFileContent(filePath, content);
if (success) {
const entry = this.fileList.get(filePath);
if (entry) {
entry.content = content;
entry.lastLoaded = new Date();
// 先检查C++服务是否可连接
const isCppServiceConnected = await (0, localClient_1.checkCppServiceConnection)();
if (isCppServiceConnected) {
// C++服务可连接,先发送进行编译验证
try {
const sendSuccess = await (0, localClient_1.sendFileToCppService)(filePath, content);
if (sendSuccess) {
// C++编译服务返回200说明脚本编译通过允许上传
const success = await this.apiClient.uploadFileContent(filePath, content);
if (success) {
const entry = this.fileList.get(filePath);
if (entry) {
entry.content = content;
entry.lastLoaded = new Date();
}
return true;
}
}
else {
// C++编译服务返回非200说明脚本存在问题不允许上传
vscode.window.showErrorMessage(`脚本编译失败,无法保存文件 ${filePath}。请检查代码错误后再试。`);
return false;
}
}
catch (error) {
// 向C++服务发送文件过程中出现错误
vscode.window.showErrorMessage(`发送文件到编译服务时出错: ${error},但仍尝试直接保存文件`);
const success = await this.apiClient.uploadFileContent(filePath, content);
if (success) {
const entry = this.fileList.get(filePath);
if (entry) {
entry.content = content;
entry.lastLoaded = new Date();
}
return true;
}
return true;
}
}
catch (error) {
vscode.window.showErrorMessage(`保存文件失败: ${error}`);
else {
// C++服务不可连接,直接执行上传
try {
const success = await this.apiClient.uploadFileContent(filePath, content);
if (success) {
const entry = this.fileList.get(filePath);
if (entry) {
entry.content = content;
entry.lastLoaded = new Date();
}
return true;
}
}
catch (error) {
vscode.window.showErrorMessage(`保存文件失败: ${error}`);
}
}
return false;
}