diff --git a/scripts/seed/downloadFile.ts b/scripts/seed/downloadFile.ts index f9840f9..7cdac92 100644 --- a/scripts/seed/downloadFile.ts +++ b/scripts/seed/downloadFile.ts @@ -1,8 +1,16 @@ import { fetch } from "@remix-run/node"; +import { readFile } from "fs/promises"; const URL = "https://www5.ine.gub.uy/documents/Estad%C3%ADsticasecon%C3%B3micas/SERIES%20Y%20OTROS/Cotizaci%C3%B3n%20de%20monedas/Cotizaci%C3%B3n%20monedas.xlsx"; export async function downloadFile() { - return (await fetch(URL)).arrayBuffer(); + const response = await fetch(URL); + + if (response.status === 200) { + return response.arrayBuffer(); + } + + console.log("File download failed. Reading fallback.xlsx"); + return await readFile(__dirname + "/fallback.xlsx"); } diff --git a/scripts/seed/fallback.xlsx b/scripts/seed/fallback.xlsx new file mode 100644 index 0000000..f1d0b7d Binary files /dev/null and b/scripts/seed/fallback.xlsx differ