"use strict";
Object.defineProperty(exports, "__esModule", {
    value: true
});
const _nodepath = /*#__PURE__*/ _interop_require_default(require("node:path"));
const _nodefs = /*#__PURE__*/ _interop_require_default(require("node:fs"));
const _nodeconsole = /*#__PURE__*/ _interop_require_default(require("node:console"));
const _multer = /*#__PURE__*/ _interop_require_default(require("multer"));
const _express = /*#__PURE__*/ _interop_require_default(require("express"));
const _nodehttp = /*#__PURE__*/ _interop_require_default(require("node:http"));
function _interop_require_default(obj) {
    return obj && obj.__esModule ? obj : {
        default: obj
    };
}
const port = process.argv[2] ? Number.parseInt(process.argv[2]) : 2234;
const uploadsDir = _nodepath.default.join(__dirname, "uploads", `server-${port.toString()}`);
if (!_nodefs.default.existsSync(uploadsDir)) {
    _nodeconsole.default.log(`[PORT ${port}] Creating uploads folder ${uploadsDir}`);
    _nodefs.default.mkdirSync(uploadsDir, {
        recursive: true
    });
}
cleanupUploads();
const upload = (0, _multer.default)({
    dest: uploadsDir
});
const app = (0, _express.default)();
const server = _nodehttp.default.createServer(app);
app.get("/api/version", async (req, res)=>{
    res.send({
        api: "2.0.0",
        server: "2.1.2",
        nozzle_diameter: 0.4,
        text: "PrusaLink",
        hostname: "prusa-mini",
        capabilities: {
            "upload-by-put": true
        }
    });
});
function cleanupUploads() {
    try {
        _nodeconsole.default.log(`[PORT ${port}] Cleaning up uploads folder...`);
        const files = _nodefs.default.readdirSync(uploadsDir);
        for (const file of files){
            const filePath = _nodepath.default.join(uploadsDir, file);
            _nodefs.default.unlinkSync(filePath);
            _nodeconsole.default.log(`[PORT ${port}] Deleted: ${filePath}`);
        }
        _nodeconsole.default.log(`[PORT ${port}] Uploads folder cleanup complete`);
    } catch (error) {
        _nodeconsole.default.error(`[PORT ${port}] Error cleaning up uploads folder:`, error);
    }
}

//# sourceMappingURL=mock-prusalink.server.js.map