locale second stage
This commit is contained in:
21
lib/feeds.ts
21
lib/feeds.ts
@@ -181,6 +181,10 @@ export async function fetchMatchesAndTeams(): Promise<{ matches: Match[]; teams:
|
||||
id, name: side.name, code: side.tla ?? "", group,
|
||||
crest: `/crests/${id}.svg`,
|
||||
localisedName: localisedTeamName(side.tla ?? "", side.name ?? ""),
|
||||
localisedNames: {
|
||||
de: localisedTeamName(side.tla ?? "", side.name ?? "", "de"),
|
||||
en: localisedTeamName(side.tla ?? "", side.name ?? "", "en"),
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -606,12 +610,13 @@ interface FifaScores {
|
||||
}
|
||||
|
||||
// Holt Live-Scores von der FIFA-API. Gibt Map MatchNumber → Scores + FIFA-ID→App-Code-Map zurück.
|
||||
export async function fetchFifaScores(): Promise<{
|
||||
export async function fetchFifaScores(locale: string = "de"): Promise<{
|
||||
scores: Map<number, FifaScores>;
|
||||
fifaIdToAppCode: Map<string, string>;
|
||||
}> {
|
||||
return cached("fifa:scores", 45_000, async () => {
|
||||
const url = `${FIFA_BASE}/calendar/matches?language=de&count=500&idSeason=${FIFA_SEASON}`;
|
||||
return cached(`fifa:scores:${locale}`, 45_000, async () => {
|
||||
const lang = locale === "en" ? "en" : "de";
|
||||
const url = `${FIFA_BASE}/calendar/matches?language=${lang}&count=500&idSeason=${FIFA_SEASON}`;
|
||||
const res = await fetch(url, {
|
||||
cache: "no-store",
|
||||
headers: { "User-Agent": "wm2026-board/1.0" },
|
||||
@@ -715,9 +720,10 @@ function normMinuteStr(min: string | null | undefined): string {
|
||||
return (min ?? "").replace(/'/g, "").replace(/\s+/g, "").trim();
|
||||
}
|
||||
|
||||
async function fetchFifaGoals(idStage: string, idMatch: string): Promise<FifaGoalRaw[]> {
|
||||
return cached(`fifa:detail:${idMatch}`, 60_000, async () => {
|
||||
const url = `${FIFA_BASE}/live/football/17/${FIFA_SEASON}/${idStage}/${idMatch}?language=de`;
|
||||
async function fetchFifaGoals(idStage: string, idMatch: string, locale: string = "de"): Promise<FifaGoalRaw[]> {
|
||||
return cached(`fifa:detail:${locale}:${idMatch}`, 60_000, async () => {
|
||||
const lang = locale === "en" ? "en" : "de";
|
||||
const url = `${FIFA_BASE}/live/football/17/${FIFA_SEASON}/${idStage}/${idMatch}?language=${lang}`;
|
||||
const res = await fetch(url, {
|
||||
cache: "no-store",
|
||||
headers: { "User-Agent": "wm2026-board/1.0" },
|
||||
@@ -762,6 +768,7 @@ async function fetchFifaGoals(idStage: string, idMatch: string): Promise<FifaGoa
|
||||
export async function attachFifaGoals(
|
||||
matches: Match[],
|
||||
fifaData: { scores: Map<number, FifaScores>; fifaIdToAppCode: Map<string, string> },
|
||||
locale: string = "de",
|
||||
): Promise<Match[]> {
|
||||
const targets = matches.filter(m =>
|
||||
(m.status === "FINISHED" || m.status === "LIVE" || m.status === "IN_PLAY") &&
|
||||
@@ -771,7 +778,7 @@ export async function attachFifaGoals(
|
||||
await Promise.all(targets.map(async (m) => {
|
||||
const fs = fifaData.scores.get(m.matchNumber);
|
||||
if (!fs?.idMatch || !fs?.idStage) return;
|
||||
const goals = await fetchFifaGoals(fs.idStage, fs.idMatch);
|
||||
const goals = await fetchFifaGoals(fs.idStage, fs.idMatch, locale);
|
||||
if (goals.length) goalsByMatchId.set(m.id, goals);
|
||||
}));
|
||||
if (goalsByMatchId.size === 0) return matches;
|
||||
|
||||
Reference in New Issue
Block a user