"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const yargs_1 = __importDefault(require("yargs")); const helpers_1 = require("yargs/helpers"); const steamSession_1 = require("./app/steamSession"); const fetchMatchFromSharecode_1 = require("./app/fetchMatchFromSharecode"); const downloadDemoFile_1 = require("./app/downloadDemoFile"); const http_1 = __importDefault(require("http")); const fs_1 = __importDefault(require("fs")); const path_1 = __importDefault(require("path")); const argv = (0, yargs_1.default)((0, helpers_1.hideBin)(process.argv)).options({ username: { type: 'string', demandOption: true }, password: { type: 'string', demandOption: true }, mfa: { type: 'string', demandOption: false }, authCode: { type: 'string', demandOption: false }, port: { type: 'number', default: 4000, demandOption: false }, demoPath: { type: 'string', default: 'demos', demandOption: false, description: 'Zielverzeichnis fรผr heruntergeladene Demos', }, }).parseSync(); const PORT = argv.port; const resolvedDemoPath = path_1.default.resolve(argv.demoPath); if (!fs_1.default.existsSync(resolvedDemoPath)) { fs_1.default.mkdirSync(resolvedDemoPath, { recursive: true }); console.log(`๐Ÿ“‚ Verzeichnis erstellt: ${resolvedDemoPath}`); } async function start() { const session = await (0, steamSession_1.createSteamSession)(argv.username, argv.password, argv.mfa); console.log(`๐Ÿš€ Server lรคuft auf http://localhost:${PORT}`); http_1.default .createServer(async (req, res) => { if (req.method === 'POST' && req.url === '/download') { let body = ''; req.on('data', (chunk) => (body += chunk)); req.on('end', async () => { try { const { shareCode, steamId } = JSON.parse(body); console.log(`๐Ÿ“ฆ ShareCode empfangen: ${shareCode}`); const match = await (0, fetchMatchFromSharecode_1.fetchMatchFromShareCode)(shareCode, session); const demoFilePath = await (0, downloadDemoFile_1.downloadDemoFile)(match, steamId, resolvedDemoPath, (percent) => { process.stdout.write(`๐Ÿ“ถ Fortschritt: ${percent}%\r`); if (percent === 100) { console.log('โœ… Download abgeschlossen'); } }); // JSON-Dateipfad erstellen const jsonFilePath = demoFilePath.replace(/\.dem$/, '.json'); const jsonFileName = path_1.default.basename(jsonFilePath); // Match-Daten als JSON schreiben await fs_1.default.promises.writeFile(jsonFilePath, JSON.stringify(match, null, 2), 'utf-8'); console.log(`๐Ÿ“ Match-Daten gespeichert unter: ${jsonFileName}`); // Antwort an den Client res.writeHead(200, { 'Content-Type': 'application/json' }); res.end(JSON.stringify({ success: true, path: demoFilePath })); } catch (err) { console.error('โŒ Fehler:', err); res.writeHead(500, { 'Content-Type': 'application/json' }); res.end(JSON.stringify({ success: false, error: err instanceof Error ? err.message : err })); } }); } else { res.writeHead(404); res.end(); } }) .listen(PORT); } start();