api.ts 1.7 KB
Newer Older
式部 已提交
1 2 3 4 5 6 7
export interface Schedule {
    UtcDateTime: string;
    Date: string;
    Time: string;
    TimeZoneDisplayName: string;
}

fix  
式部 已提交
8
export const getSchedules = async () => {
fix  
式部 已提交
9 10
    const response = await fetch('/api/fina/competitions/3337/schedule');
    return response.json();
式部 已提交
11 12 13 14 15 16 17 18
};

export interface Competition {
    Id: string;
    DisciplineName: string;
}

export const getCompetitions = async (): Promise<Competition[]> => {
fix  
式部 已提交
19
    const response = await fetch('https://swimming.abdecd.xyz/api/fina/competitions/3337/events');
式部 已提交
20 21 22 23
    const data = await response.json() as { Sports: [{ DisciplineList: Competition[] }] };
    return data.Sports?.[0]?.DisciplineList;
};

fix  
式部 已提交
24
getCompetitions().then(console.log);
fix  
式部 已提交
25
export const getResults = async (hash: string) => {
fix  
式部 已提交
26
    const response = await fetch(`https://swimming.abdecd.xyz/api/fina/events/${hash}`);
式部 已提交
27 28 29 30 31 32 33 34
    return await response.json();
};

export const getCountryFlag = (country: string): string => {
    return `https://www.worldaquatics.com/resources/v2.11.4/i/elements/flags/${country.toLowerCase()}.png`;
};

export const getAthletePhoto = async (...id: string[]) => {
fix  
式部 已提交
35
    const query = id.map(i => `"FINA_ATHLETE:${i}"`).join(' or ');
式部 已提交
36 37 38 39 40 41
    const response = await fetch(`/api/content/fina/photo/en/?pageSize=100&tagNames=athlete-image&referenceExpression=${query}`);
    const data = await response.json();
    return data.content;
};

export const getMedalTable = async () => {
fix  
式部 已提交
42 43 44 45
    const response = await fetch('/api/fina/competitions/3337/medals');
    const data = await response.json() as {
        Medals: { SportMedals: { Country: string; Gold: number; Silver: number; Bronze: number; Total: number }[] }
    };
式部 已提交
46 47
    return data.Medals.SportMedals?.[0];
};
fix  
式部 已提交
48