32 lines
944 B
TypeScript
32 lines
944 B
TypeScript
export async function fetchSteamProfile(
|
|
steamId: string
|
|
): Promise<{ name: string; avatar: string } | null> {
|
|
const key = process.env.STEAM_API_KEY;
|
|
if (!key) return null;
|
|
|
|
const url = `https://api.steampowered.com/ISteamUser/GetPlayerSummaries/v2/?key=${key}&steamids=${steamId}`;
|
|
|
|
try {
|
|
const res = await fetch(url);
|
|
const contentType = res.headers.get('content-type') || '';
|
|
|
|
if (!res.ok || !contentType.includes('application/json')) {
|
|
const text = await res.text();
|
|
console.warn(`[SteamAPI] ⚠️ Ungültige Antwort für ${steamId} (${res.status}):`, text.slice(0, 200));
|
|
return null;
|
|
}
|
|
|
|
const data = await res.json();
|
|
const player = data.response?.players?.[0];
|
|
if (!player) return null;
|
|
|
|
return {
|
|
name: player.personaname,
|
|
avatar: player.avatarfull,
|
|
};
|
|
} catch (err) {
|
|
console.warn(`[SteamAPI] ❌ Fehler für ${steamId}:`, err);
|
|
return null;
|
|
}
|
|
}
|