| 1 | import type { Map } from "@/types/map.type"; |
| 2 | |
| 3 | export const fetchMap = async (circuitKey: number): Promise<Map | null> => { |
| 4 | try { |
| 5 | const year = new Date().getFullYear(); |
| 6 | |
| 7 | const mapRequest = await fetch(`https://api.multiviewer.app/api/v1/circuits/${circuitKey}/${year}`, { |
| 8 | next: { revalidate: 60 * 60 * 2 }, |
| 9 | }); |
| 10 | |
| 11 | if (!mapRequest.ok) { |
| 12 | console.error("Failed to fetch map", mapRequest); |
| 13 | return null; |
| 14 | } |
| 15 | |
| 16 | return mapRequest.json(); |
| 17 | } catch (error) { |
| 18 | console.error("Failed to fetch map", error); |
| 19 | return null; |
| 20 | } |
| 21 | }; |