#!/usr/bin/env node /** * Steam CLI - Direktes Testen der Steam API * Usage: node scripts/steam-cli.mjs [apiKey] [steamId] */ import { fetchSteamGames } from "../server/steam-backend.mjs"; import { readFile } from "node:fs/promises"; import { fileURLToPath } from "node:url"; import { dirname, join } from "node:path"; const __filename = fileURLToPath(import.meta.url); const __dirname = dirname(__filename); async function loadConfig() { try { const configPath = join(__dirname, "..", "config.local.json"); const configData = await readFile(configPath, "utf-8"); return JSON.parse(configData); } catch { return null; } } async function main() { console.log("=".repeat(70)); console.log("Steam API CLI Test"); console.log("=".repeat(70)); // API Key und Steam ID holen (CLI-Args oder config.local.json) let apiKey = process.argv[2]; let steamId = process.argv[3]; if (!apiKey || !steamId) { console.log("\nKeine CLI-Args, versuche config.local.json zu laden..."); const config = await loadConfig(); if (config?.steam) { apiKey = config.steam.apiKey; steamId = config.steam.steamId; console.log("✓ Credentials aus config.local.json geladen"); } } if (!apiKey || !steamId) { console.error("\n❌ Fehler: API Key und Steam ID erforderlich!"); console.error("\nUsage:"); console.error(" node scripts/steam-cli.mjs "); console.error( " oder config.local.json mit steam.apiKey und steam.steamId", ); process.exit(1); } console.log("\nParameter:"); console.log(" API Key:", apiKey.substring(0, 8) + "..."); console.log(" Steam ID:", steamId); console.log("\nRufe Steam API auf...\n"); try { const result = await fetchSteamGames(apiKey, steamId); console.log("=".repeat(70)); console.log("✓ Erfolgreich!"); console.log("=".repeat(70)); console.log(`\nAnzahl Spiele: ${result.count}`); if (result.count > 0) { console.log("\nErste 5 Spiele:"); console.log("-".repeat(70)); result.games.slice(0, 5).forEach((game, idx) => { console.log(`\n${idx + 1}. ${game.title}`); console.log(` ID: ${game.id}`); console.log(` Spielzeit: ${game.playtimeHours}h`); console.log(` Zuletzt gespielt: ${game.lastPlayed || "nie"}`); console.log(` URL: ${game.url}`); }); console.log("\n" + "-".repeat(70)); console.log("\nKomplettes JSON (erste 3 Spiele):"); console.log(JSON.stringify(result.games.slice(0, 3), null, 2)); } console.log("\n" + "=".repeat(70)); console.log("✓ Test erfolgreich abgeschlossen"); console.log("=".repeat(70) + "\n"); } catch (error) { console.error("\n" + "=".repeat(70)); console.error("❌ Fehler:"); console.error("=".repeat(70)); console.error("\nMessage:", error.message); if (error.stack) { console.error("\nStack:"); console.error(error.stack); } console.error("\n" + "=".repeat(70) + "\n"); process.exit(1); } } main();