Adds /api/health, ntfy notify on config save, /admin/analytics charts, and deploy smoke for miniprogram config/API. Co-authored-by: Cursor <cursoragent@cursor.com>
32 lines
944 B
TypeScript
32 lines
944 B
TypeScript
import { promises as fs } from "node:fs";
|
|
import path from "node:path";
|
|
import {
|
|
DEFAULT_REMOTE_CONFIG,
|
|
mergeRemoteConfig,
|
|
type NomadroRemoteConfig,
|
|
} from "~/lib/remote-config";
|
|
|
|
const FILE = path.join(process.cwd(), "data", "remote-config.json");
|
|
|
|
export async function readRemoteConfigFile(): Promise<NomadroRemoteConfig> {
|
|
try {
|
|
const raw = await fs.readFile(FILE, "utf8");
|
|
return mergeRemoteConfig(JSON.parse(raw) as Partial<NomadroRemoteConfig>);
|
|
} catch {
|
|
return structuredClone(DEFAULT_REMOTE_CONFIG);
|
|
}
|
|
}
|
|
|
|
export async function writeRemoteConfigFile(
|
|
next: NomadroRemoteConfig,
|
|
): Promise<NomadroRemoteConfig> {
|
|
const merged = mergeRemoteConfig({
|
|
...next,
|
|
updatedAt: new Date().toISOString(),
|
|
version: Math.max(1, Number(next.version) || 1),
|
|
});
|
|
await fs.mkdir(path.dirname(FILE), { recursive: true });
|
|
await fs.writeFile(FILE, JSON.stringify(merged, null, 2), "utf8");
|
|
return merged;
|
|
}
|