mirror of
https://github.com/saltbo/zpan.git
synced 2026-09-01 15:49:00 +08:00
fa943ca8b3
- Add license-state.ts helper for reading/writing license state as system_options key-value pairs instead of a dedicated singleton table - Rewrite refresh.ts, has-feature.ts, entitlement.ts, licensing-admin.ts, licensing-refresh-runner.ts to use license-state helpers - Generate migration 0014 to drop license_binding table - Update all 10 test files to use setLicenseOptions instead of db.insert(licenseBinding) - All 2809 tests pass Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
22 lines
778 B
TypeScript
22 lines
778 B
TypeScript
import { loadLicenseState } from '../licensing/license-state'
|
|
import { performRefresh } from '../licensing/refresh'
|
|
import type { Database } from '../platform/interface'
|
|
|
|
const DEDUP_WINDOW_SEC = 5 * 60
|
|
|
|
export async function runLicensingRefresh(db: Database, cloudBaseUrl: string): Promise<void> {
|
|
const state = await loadLicenseState(db)
|
|
if (!state.refreshToken) return // unbound — no-op
|
|
|
|
const nowSec = Math.floor(Date.now() / 1000)
|
|
if (state.lastRefreshAt != null && nowSec - state.lastRefreshAt < DEDUP_WINDOW_SEC) return
|
|
|
|
try {
|
|
await performRefresh(db, cloudBaseUrl)
|
|
console.log('licensing.refresh.ok')
|
|
} catch (err) {
|
|
const code = err instanceof Error ? err.message : String(err)
|
|
console.error(`licensing.refresh.error code=${code}`)
|
|
}
|
|
}
|