修改保存逻辑:先检查C++服务连接性再决定上传流程

- 添加checkCppServiceConnection函数用于检查C++服务是否可连接
- 修改保存逻辑:如果C++服务可连接,先发送文件内容到C++服务,只有在收到200状态码后才继续保存到服务器
- 如果C++服务不可连接,则直接使用API函数保存到服务器
- 完善输出信息,帮助用户了解当前处理流程

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

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
睿 安
2025-10-03 19:54:53 +08:00
parent 8742b1d7d4
commit 95dfc4397e
6 changed files with 168 additions and 39 deletions

42
dist/localClient.js vendored
View File

@@ -33,9 +33,51 @@ var __importStar = (this && this.__importStar) || (function () {
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
exports.checkCppServiceConnection = checkCppServiceConnection;
exports.sendFileToCppService = sendFileToCppService;
const http = __importStar(require("http"));
const net = __importStar(require("net"));
const vscode = __importStar(require("vscode"));
/**
* 检查本地C++服务是否可连接
* @returns Promise<boolean> 是否可连接
*/
async function checkCppServiceConnection() {
// 从配置中获取端口号默认为26000
const config = vscode.workspace.getConfiguration('squirrel');
const localServicePort = config.get('localServicePort', 26000);
return new Promise((resolve) => {
const socket = new net.Socket();
let isResolved = false;
socket.setTimeout(3000); // 3秒超时
socket.connect(localServicePort, '127.0.0.1', () => {
// 连接成功,端口可达
socket.destroy();
resolve(true);
});
socket.on('error', (error) => {
// 连接失败
if (!isResolved) {
isResolved = true;
resolve(false);
}
});
socket.on('timeout', () => {
// 连接超时
socket.destroy();
if (!isResolved) {
isResolved = true;
resolve(false);
}
});
socket.on('close', () => {
if (!isResolved) {
isResolved = true;
resolve(false);
}
});
});
}
/**
* 构建JSON数据
* @param filePath 文件路径