2025-05-28 00:40:46 +02:00

70 lines
3.1 KiB
JavaScript

"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 path = await (0, downloadDemoFile_1.downloadDemoFile)(match, steamId, resolvedDemoPath, (percent) => {
process.stdout.write(`📶 Fortschritt: ${percent}%\r`);
if (percent === 100) {
console.log('✅ Download abgeschlossen');
}
});
res.writeHead(200, { 'Content-Type': 'application/json' });
res.end(JSON.stringify({ success: true, path }));
}
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();