(provider, ctx)
| 226 | provider: { |
| 227 | id: "digitalocean", |
| 228 | async models(provider, ctx) { |
| 229 | const baseModels = provider.models |
| 230 | if (ctx.auth?.type !== "api") return baseModels |
| 231 | |
| 232 | const metadata = ctx.auth.metadata ?? {} |
| 233 | const oauthAccess = metadata["oauth_access"] |
| 234 | const oauthExpires = parseInt(metadata["oauth_expires"] || "0", 10) |
| 235 | const fetchedAt = parseInt(metadata["routers_fetched_at"] || "0", 10) |
| 236 | const cached = parseRoutersJSON(metadata["routers"]) |
| 237 | |
| 238 | let routers = cached |
| 239 | const stale = Date.now() - fetchedAt > ROUTER_REFRESH_INTERVAL_MS |
| 240 | const bearerValid = oauthAccess && oauthExpires > Date.now() |
| 241 | |
| 242 | if (bearerValid && stale) { |
| 243 | const result = await listRouters(oauthAccess) |
| 244 | if (result.ok) { |
| 245 | routers = result.routers |
| 246 | const updated: Record<string, string> = { |
| 247 | ...metadata, |
| 248 | routers: JSON.stringify(routers.map((r) => ({ name: r.name, uuid: r.uuid, description: r.description }))), |
| 249 | routers_fetched_at: String(Date.now()), |
| 250 | } |
| 251 | await input.client.auth |
| 252 | .set({ |
| 253 | path: { id: "digitalocean" }, |
| 254 | body: { type: "api", key: ctx.auth.key, metadata: updated }, |
| 255 | }) |
| 256 | .catch(() => {}) |
| 257 | } else if (result.status === 401 || result.status === 403) { |
| 258 | } else if (result.status !== 0) { |
| 259 | } |
| 260 | } |
| 261 | |
| 262 | const merged: Record<string, Model> = { ...baseModels } |
| 263 | for (const router of routers) { |
| 264 | const id = `router:${router.name}` |
| 265 | if (merged[id]) continue |
| 266 | merged[id] = routerModel(router, "digitalocean") |
| 267 | } |
| 268 | return merged |
| 269 | }, |
| 270 | }, |
| 271 | auth: { |
| 272 | provider: "digitalocean", |
no test coverage detected