mirror of
https://github.com/farion1231/cc-switch.git
synced 2026-08-04 11:43:57 +08:00
feat(usage): add automatic models.dev pricing sync (#5734)
* feat(usage): persist model pricing in local config * feat(usage): sync selected models.dev pricing on startup * fix(usage): address models.dev sync review feedback * fix(usage): harden local pricing synchronization
This commit is contained in:
@@ -19,6 +19,10 @@ import {
|
||||
installGlobalErrorHandlers,
|
||||
reportFrontendError,
|
||||
} from "./lib/frontendLogger";
|
||||
import {
|
||||
MODELS_DEV_SYNC_CONFIG_QUERY_KEY,
|
||||
syncModelsDevPricingOnStartup,
|
||||
} from "./lib/modelsDevAutoSync";
|
||||
|
||||
installGlobalErrorHandlers();
|
||||
|
||||
@@ -124,6 +128,25 @@ async function bootstrap() {
|
||||
</FrontendErrorBoundary>
|
||||
</React.StrictMode>,
|
||||
);
|
||||
|
||||
void syncModelsDevPricingOnStartup()
|
||||
.then((result) => {
|
||||
if (!result.skipped) {
|
||||
return Promise.all([
|
||||
queryClient.invalidateQueries({ queryKey: ["usage"] }),
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: MODELS_DEV_SYNC_CONFIG_QUERY_KEY,
|
||||
}),
|
||||
]);
|
||||
}
|
||||
})
|
||||
.catch((error) => {
|
||||
// 离线或 models.dev 暂时不可用不应阻塞应用启动。
|
||||
reportFrontendError("models_dev_startup_sync", error);
|
||||
void queryClient.invalidateQueries({
|
||||
queryKey: MODELS_DEV_SYNC_CONFIG_QUERY_KEY,
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
void bootstrap();
|
||||
|
||||
Reference in New Issue
Block a user