fix: Add API response transformer for legacy CSGOW.TF format

- Create transformers.ts to convert legacy API format to new schema
- Transform score array [a, b] to score_team_a/score_team_b fields
- Convert Unix timestamps to ISO strings
- Map legacy field names (parsed, vac, game_ban) to new names
- Update matches API to use transformer with proper types
- Handle empty map names gracefully in homepage
- Limit featured matches to exactly 6 items

Fixes homepage data display issue where API format mismatch prevented
matches from rendering. API returns legacy CSGO:WTF format while frontend
expects new CS2.WTF schema.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
2025-11-04 23:14:28 +01:00
parent 8b73a68a6b
commit ea61061530
4 changed files with 68 additions and 13 deletions

View File

@@ -0,0 +1,51 @@
/**
* API Response Transformers
* Converts legacy CSGO:WTF API responses to the new CS2.WTF format
*/
import type { MatchListItem, MatchesListResponse } from '$lib/types';
/**
* Legacy API match format (from api.csgow.tf)
*/
export interface LegacyMatchListItem {
match_id: string;
map: string;
date: number; // Unix timestamp
score: [number, number]; // [team_a, team_b]
duration: number;
match_result: number;
max_rounds: number;
parsed: boolean;
vac: boolean;
game_ban: boolean;
}
/**
* Transform legacy match list item to new format
*/
export function transformMatchListItem(legacy: LegacyMatchListItem): MatchListItem {
return {
match_id: Number(legacy.match_id),
map: legacy.map || 'unknown', // Handle empty map names
date: new Date(legacy.date * 1000).toISOString(), // Convert Unix timestamp to ISO string
score_team_a: legacy.score[0],
score_team_b: legacy.score[1],
duration: legacy.duration,
demo_parsed: legacy.parsed,
player_count: 10 // Default to 10 players (5v5)
};
}
/**
* Transform legacy matches list response to new format
*/
export function transformMatchesListResponse(
legacyMatches: LegacyMatchListItem[]
): MatchesListResponse {
return {
matches: legacyMatches.map(transformMatchListItem),
has_more: false, // Legacy API doesn't provide pagination info
next_page_time: undefined
};
}