add working settings for steam
This commit is contained in:
101
scripts/steam-cli.mjs
Normal file
101
scripts/steam-cli.mjs
Normal file
@@ -0,0 +1,101 @@
|
||||
#!/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 <apiKey> <steamId>");
|
||||
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();
|
||||
75
scripts/test-api.mjs
Normal file
75
scripts/test-api.mjs
Normal file
@@ -0,0 +1,75 @@
|
||||
/**
|
||||
* Test-Script für Backend-APIs
|
||||
* Ruft die Endpoints direkt auf ohne Browser/GUI
|
||||
*/
|
||||
|
||||
import { handleConfigLoad, handleSteamRefresh } from "../server/steam-api.mjs";
|
||||
|
||||
// Mock Request/Response Objekte
|
||||
class MockRequest {
|
||||
constructor(method, url, body = null) {
|
||||
this.method = method;
|
||||
this.url = url;
|
||||
this._body = body;
|
||||
this._listeners = {};
|
||||
}
|
||||
|
||||
on(event, callback) {
|
||||
this._listeners[event] = callback;
|
||||
|
||||
if (event === "data" && this._body) {
|
||||
setTimeout(() => callback(this._body), 0);
|
||||
}
|
||||
if (event === "end") {
|
||||
setTimeout(() => callback(), 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class MockResponse {
|
||||
constructor() {
|
||||
this.statusCode = 200;
|
||||
this.headers = {};
|
||||
this._chunks = [];
|
||||
}
|
||||
|
||||
setHeader(name, value) {
|
||||
this.headers[name] = value;
|
||||
}
|
||||
|
||||
end(data) {
|
||||
if (data) this._chunks.push(data);
|
||||
const output = this._chunks.join("");
|
||||
console.log("\n=== RESPONSE ===");
|
||||
console.log("Status:", this.statusCode);
|
||||
console.log("Headers:", this.headers);
|
||||
console.log("Body:", output);
|
||||
|
||||
// Parse JSON wenn Content-Type gesetzt ist
|
||||
if (this.headers["Content-Type"] === "application/json") {
|
||||
try {
|
||||
const parsed = JSON.parse(output);
|
||||
console.log("\nParsed JSON:");
|
||||
console.log(JSON.stringify(parsed, null, 2));
|
||||
} catch (e) {
|
||||
console.error("JSON Parse Error:", e.message);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Test 1: Config Load
|
||||
console.log("\n### TEST 1: Config Load ###");
|
||||
const configReq = new MockRequest("GET", "/api/config/load");
|
||||
const configRes = new MockResponse();
|
||||
await handleConfigLoad(configReq, configRes);
|
||||
|
||||
// Test 2: Steam Refresh (braucht config.local.json)
|
||||
console.log("\n\n### TEST 2: Steam Refresh ###");
|
||||
const steamBody = JSON.stringify({
|
||||
apiKey: "78CDB987B47DDBB9C385522E5F6D0A52",
|
||||
steamId: "76561197960313963",
|
||||
});
|
||||
const steamReq = new MockRequest("POST", "/api/steam/refresh", steamBody);
|
||||
const steamRes = new MockResponse();
|
||||
await handleSteamRefresh(steamReq, steamRes);
|
||||
54
scripts/test-backend.mjs
Normal file
54
scripts/test-backend.mjs
Normal file
@@ -0,0 +1,54 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
/**
|
||||
* Standalone Backend-Test
|
||||
* Testet die API-Funktionen direkt ohne Vite-Server
|
||||
*/
|
||||
|
||||
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);
|
||||
const rootDir = join(__dirname, "..");
|
||||
|
||||
console.log("=".repeat(60));
|
||||
console.log("Backend API Test");
|
||||
console.log("=".repeat(60));
|
||||
|
||||
// Test 1: Config File lesen
|
||||
console.log("\n[TEST 1] Config File direkt lesen");
|
||||
console.log("-".repeat(60));
|
||||
|
||||
const configPath = join(rootDir, "config.local.json");
|
||||
console.log("Config Pfad:", configPath);
|
||||
|
||||
try {
|
||||
const configRaw = await readFile(configPath, "utf-8");
|
||||
console.log("\n✓ Datei gelesen, Größe:", configRaw.length, "bytes");
|
||||
console.log("\nInhalt:");
|
||||
console.log(configRaw);
|
||||
|
||||
const config = JSON.parse(configRaw);
|
||||
console.log("\n✓ JSON parsing erfolgreich");
|
||||
console.log("\nGeparste Config:");
|
||||
console.log(JSON.stringify(config, null, 2));
|
||||
|
||||
if (config.steam?.apiKey && config.steam?.steamId) {
|
||||
console.log("\n✓ Steam-Daten vorhanden:");
|
||||
console.log(" - API Key:", config.steam.apiKey.substring(0, 8) + "...");
|
||||
console.log(" - Steam ID:", config.steam.steamId);
|
||||
} else {
|
||||
console.log("\n⚠️ Steam-Daten nicht vollständig");
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("\n❌ Fehler beim Lesen der Config:");
|
||||
console.error(" Error:", error.message);
|
||||
console.error(" Stack:", error.stack);
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
console.log("\n" + "=".repeat(60));
|
||||
console.log("✓ Alle Tests bestanden!");
|
||||
console.log("=".repeat(60));
|
||||
28
scripts/test-config-load.mjs
Normal file
28
scripts/test-config-load.mjs
Normal file
@@ -0,0 +1,28 @@
|
||||
/**
|
||||
* Einfacher Test: Lädt config.local.json
|
||||
*/
|
||||
|
||||
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);
|
||||
const configPath = join(__dirname, "..", "config.local.json");
|
||||
|
||||
console.log("Config Pfad:", configPath);
|
||||
|
||||
try {
|
||||
const configData = await readFile(configPath, "utf-8");
|
||||
console.log("\nRaw File Content:");
|
||||
console.log(configData);
|
||||
|
||||
const config = JSON.parse(configData);
|
||||
console.log("\nParsed Config:");
|
||||
console.log(JSON.stringify(config, null, 2));
|
||||
|
||||
console.log("\n✓ Config erfolgreich geladen!");
|
||||
} catch (error) {
|
||||
console.error("\n❌ Fehler:", error.message);
|
||||
console.error(error);
|
||||
}
|
||||
Reference in New Issue
Block a user