mirror of
https://github.com/NoFxAiOS/nofx.git
synced 2026-07-10 14:27:00 +08:00
account system、custom prompt
This commit is contained in:
27
web/src/lib/config.ts
Normal file
27
web/src/lib/config.ts
Normal file
@@ -0,0 +1,27 @@
|
||||
export interface SystemConfig {
|
||||
admin_mode: boolean;
|
||||
}
|
||||
|
||||
let configPromise: Promise<SystemConfig> | null = null;
|
||||
let cachedConfig: SystemConfig | null = null;
|
||||
|
||||
export function getSystemConfig(): Promise<SystemConfig> {
|
||||
if (cachedConfig) {
|
||||
return Promise.resolve(cachedConfig);
|
||||
}
|
||||
if (configPromise) {
|
||||
return configPromise;
|
||||
}
|
||||
configPromise = fetch('/api/config')
|
||||
.then((res) => res.json())
|
||||
.then((data: SystemConfig) => {
|
||||
cachedConfig = data;
|
||||
return data;
|
||||
})
|
||||
.finally(() => {
|
||||
// Keep cachedConfig for reuse; allow re-fetch via explicit invalidation if added later
|
||||
});
|
||||
return configPromise;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user