2026-07-08 07:05:48 +08:00
|
|
|
import path from "node:path";
|
|
|
|
|
import fs from "node:fs";
|
|
|
|
|
import { ModrinthClient } from "@/lib/modrinth";
|
|
|
|
|
import { CurseForgeClient } from "@/lib/curseforge";
|
|
|
|
|
import type { Secrets } from "@/types";
|
|
|
|
|
import { SecretsSchema } from "@/types";
|
|
|
|
|
|
|
|
|
|
function loadSecrets(): Secrets {
|
|
|
|
|
const secretsPath = path.join(process.cwd(), "secrets.json");
|
|
|
|
|
|
|
|
|
|
let raw: unknown;
|
|
|
|
|
try {
|
|
|
|
|
raw = JSON.parse(fs.readFileSync(secretsPath, "utf-8"));
|
|
|
|
|
} catch {
|
|
|
|
|
throw new Error(
|
|
|
|
|
`Failed to read secrets.json (${secretsPath}). Please ensure the file exists and is valid JSON.`,
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const result = SecretsSchema.safeParse(raw);
|
|
|
|
|
if (!result.success) {
|
|
|
|
|
throw new Error(
|
|
|
|
|
`secrets.json validation failed: ${result.error.message}`,
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
return result.data;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const secrets = loadSecrets();
|
|
|
|
|
|
|
|
|
|
export const modrinthClient = new ModrinthClient(
|
|
|
|
|
secrets.modrinth,
|
2026-07-10 08:59:26 +08:00
|
|
|
"ModReleaser (local)",
|
2026-07-08 07:05:48 +08:00
|
|
|
);
|
|
|
|
|
|
|
|
|
|
export const curseforgeClient = new CurseForgeClient(secrets.curseforge);
|