silverwolf-x/project / packages /font /src /google /fetch-font-file.ts
silverwolf-x's picture
download
raw
629 Bytes
import fs from 'node:fs'
import { retry } from './retry'
import { fetchResource } from './fetch-resource'
/**
* Fetches a font file and returns its contents as a Buffer.
* If NEXT_FONT_GOOGLE_MOCKED_RESPONSES is set, we handle mock data logic.
*/
export async function fetchFontFile(url: string, isDev: boolean) {
if (process.env.NEXT_FONT_GOOGLE_MOCKED_RESPONSES) {
if (url.startsWith('/')) {
return fs.readFileSync(url)
}
return Buffer.from(url)
}
return await retry(async () => {
return fetchResource(
url,
isDev,
`Failed to fetch font file from \`${url}\`.`
)
}, 3)
}

Xet Storage Details

Size:
629 Bytes
·
Xet hash:
e698a575756d73be645ae3866dce10b1f1ddea2bf1a5604abfb6ae4a1761aec7

Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.