fix bunfile bug

This commit is contained in:
Dax Raad
2025-06-10 18:23:19 -04:00
parent 49110f7412
commit ca3c22dc12
6 changed files with 18 additions and 16 deletions

View File

@@ -4,18 +4,21 @@ import path from "path"
export namespace ModelsDev {
const log = Log.create({ service: "models.dev" })
const file = Bun.file(path.join(Global.Path.cache, "models.json"))
const filepath = path.join(Global.Path.cache, "models.json")
export async function get() {
if (await file.exists()) {
const file = Bun.file(filepath)
const result = await file.json().catch(() => {})
if (result) {
refresh()
return file.json()
return result
}
await refresh()
return get()
}
async function refresh() {
const file = Bun.file(filepath)
log.info("refreshing")
const result = await fetch("https://models.dev/api.json")
if (!result.ok)