2025-09-18 16:04:07 +08:00
|
|
|
|
"use strict";
|
|
|
|
|
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
|
|
|
|
if (k2 === undefined) k2 = k;
|
|
|
|
|
|
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
|
|
|
|
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
|
|
|
|
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
|
|
|
|
}
|
|
|
|
|
|
Object.defineProperty(o, k2, desc);
|
|
|
|
|
|
}) : (function(o, m, k, k2) {
|
|
|
|
|
|
if (k2 === undefined) k2 = k;
|
|
|
|
|
|
o[k2] = m[k];
|
|
|
|
|
|
}));
|
|
|
|
|
|
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
|
|
|
|
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
|
|
|
|
}) : function(o, v) {
|
|
|
|
|
|
o["default"] = v;
|
|
|
|
|
|
});
|
|
|
|
|
|
var __importStar = (this && this.__importStar) || (function () {
|
|
|
|
|
|
var ownKeys = function(o) {
|
|
|
|
|
|
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
|
|
|
|
var ar = [];
|
|
|
|
|
|
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
|
|
|
|
return ar;
|
|
|
|
|
|
};
|
|
|
|
|
|
return ownKeys(o);
|
|
|
|
|
|
};
|
|
|
|
|
|
return function (mod) {
|
|
|
|
|
|
if (mod && mod.__esModule) return mod;
|
|
|
|
|
|
var result = {};
|
|
|
|
|
|
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
|
|
|
|
__setModuleDefault(result, mod);
|
|
|
|
|
|
return result;
|
|
|
|
|
|
};
|
|
|
|
|
|
})();
|
|
|
|
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
|
|
|
exports.sendFileToCppService = sendFileToCppService;
|
|
|
|
|
|
const http = __importStar(require("http"));
|
2025-09-18 16:10:04 +08:00
|
|
|
|
const vscode = __importStar(require("vscode"));
|
2025-09-18 16:04:07 +08:00
|
|
|
|
/**
|
|
|
|
|
|
* 构建JSON数据
|
|
|
|
|
|
* @param filePath 文件路径
|
|
|
|
|
|
* @param content 文件内容
|
|
|
|
|
|
* @returns JSON字符串
|
|
|
|
|
|
*/
|
|
|
|
|
|
function buildJsonData(filePath, content) {
|
|
|
|
|
|
const data = {};
|
|
|
|
|
|
data[filePath] = content;
|
|
|
|
|
|
return JSON.stringify(data);
|
|
|
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 发送文件内容到本地C++服务
|
|
|
|
|
|
* @param filePath 文件路径
|
|
|
|
|
|
* @param content 文件内容
|
|
|
|
|
|
* @returns Promise<boolean> 是否发送成功
|
|
|
|
|
|
*/
|
|
|
|
|
|
async function sendFileToCppService(filePath, content) {
|
2025-09-18 16:10:04 +08:00
|
|
|
|
// 从配置中获取端口号,默认为26000
|
|
|
|
|
|
const config = vscode.workspace.getConfiguration('squirrel');
|
|
|
|
|
|
const localServicePort = config.get('localServicePort', 26000);
|
2025-09-18 16:04:07 +08:00
|
|
|
|
return new Promise((resolve) => {
|
|
|
|
|
|
const jsonData = buildJsonData(filePath, content);
|
|
|
|
|
|
const postData = jsonData;
|
|
|
|
|
|
const options = {
|
|
|
|
|
|
hostname: '127.0.0.1',
|
2025-09-18 16:10:04 +08:00
|
|
|
|
port: localServicePort,
|
2025-09-18 16:04:07 +08:00
|
|
|
|
path: '/send_data',
|
|
|
|
|
|
method: 'POST',
|
|
|
|
|
|
headers: {
|
|
|
|
|
|
'Content-Type': 'application/json',
|
|
|
|
|
|
'Content-Length': Buffer.byteLength(postData)
|
|
|
|
|
|
}
|
|
|
|
|
|
};
|
|
|
|
|
|
const req = http.request(options, (res) => {
|
|
|
|
|
|
let data = '';
|
|
|
|
|
|
res.on('data', (chunk) => {
|
|
|
|
|
|
data += chunk;
|
|
|
|
|
|
});
|
|
|
|
|
|
res.on('end', () => {
|
|
|
|
|
|
console.log(`[Squirrel] 已发送文件到C++服务: ${filePath}, 状态码: ${res.statusCode}`);
|
|
|
|
|
|
if (res.statusCode === 200) {
|
|
|
|
|
|
resolve(true);
|
|
|
|
|
|
}
|
|
|
|
|
|
else {
|
|
|
|
|
|
console.error(`[Squirrel] 发送失败,状态码: ${res.statusCode}, 响应: ${data}`);
|
|
|
|
|
|
resolve(false);
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
});
|
|
|
|
|
|
req.on('error', (error) => {
|
|
|
|
|
|
console.error(`[Squirrel] 发送文件到C++服务失败: ${error.message}`);
|
|
|
|
|
|
resolve(false);
|
|
|
|
|
|
});
|
|
|
|
|
|
req.write(postData);
|
|
|
|
|
|
req.end();
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
//# sourceMappingURL=localClient.js.map
|