mirror of
https://gitea.toothfairyai.com/ToothFairyAI/tf_code.git
synced 2026-04-03 15:43:45 +00:00
fix bunfile bug
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user