实现直播详情页
This commit is contained in:
56
lib/api.ts
56
lib/api.ts
@@ -4,6 +4,7 @@ import {
|
||||
ApiResponse,
|
||||
Country,
|
||||
League,
|
||||
LiveScoreMatch,
|
||||
Match,
|
||||
MatchDetailData,
|
||||
OddsData,
|
||||
@@ -138,23 +139,56 @@ export const fetchMatchDetail = async (
|
||||
}
|
||||
};
|
||||
|
||||
export const fetchLiveScore = async (
|
||||
sportId: number,
|
||||
leagueId?: number,
|
||||
timezone?: string
|
||||
): Promise<LiveScoreMatch[]> => {
|
||||
try {
|
||||
const params: { sport_id: number; league_id?: number; timezone?: string } =
|
||||
{
|
||||
sport_id: sportId,
|
||||
};
|
||||
|
||||
if (leagueId) {
|
||||
params.league_id = leagueId;
|
||||
}
|
||||
|
||||
if (timezone) {
|
||||
params.timezone = timezone;
|
||||
}
|
||||
|
||||
const response = await apiClient.get<ApiResponse<LiveScoreMatch[]>>(
|
||||
API_ENDPOINTS.LIVESCORE,
|
||||
{ params }
|
||||
);
|
||||
|
||||
if (response.data.code === 0) {
|
||||
return response.data.data;
|
||||
}
|
||||
|
||||
throw new Error(response.data.message);
|
||||
} catch (error) {
|
||||
console.error("Fetch livescore error:", error);
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
|
||||
export const fetchUpcomingMatches = async (
|
||||
sportId: number,
|
||||
leagueKey: string,
|
||||
limit: number = 50
|
||||
): Promise<UpcomingMatch[]> => {
|
||||
try {
|
||||
const response =
|
||||
await apiClient.get<ApiResponse<ApiListResponse<UpcomingMatch>>>(
|
||||
API_ENDPOINTS.UPCOMING_MATCHES,
|
||||
{
|
||||
params: {
|
||||
sport_id: sportId,
|
||||
leagueKey,
|
||||
limit,
|
||||
},
|
||||
}
|
||||
);
|
||||
const response = await apiClient.get<
|
||||
ApiResponse<ApiListResponse<UpcomingMatch>>
|
||||
>(API_ENDPOINTS.UPCOMING_MATCHES, {
|
||||
params: {
|
||||
sport_id: sportId,
|
||||
leagueKey,
|
||||
limit,
|
||||
},
|
||||
});
|
||||
|
||||
if (response.data.code === 0) {
|
||||
return response.data.data.list;
|
||||
|
||||
Reference in New Issue
Block a user