"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"));
/**
 * 构建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) {
    return new Promise((resolve) => {
        const jsonData = buildJsonData(filePath, content);
        const postData = jsonData;
        const options = {
            hostname: '127.0.0.1',
            port: 26000,
            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