- Admin panel (/admin) with JWT auth: configure Replicate API token, JigsawStack API key, model version, enable/disable AI translation, change admin password. Settings persisted in data/settings.json. - Replicate AI translation: POST /api/translate/replicate uses JigsawStack text-translate model via Replicate API. Main page switches to client-side AI translation when enabled. - Document translation tab: supports PDF, DOCX, XLSX, XLS, CSV. Excel/Word formatting fully preserved (SheetJS + JSZip XML manipulation). PDF uses pdf-parse extraction + pdf-lib reconstruction. Column selector UI for tabular data (per-sheet, All/None toggles). - Updated README with full implementation documentation. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
49 lines
1.4 KiB
TypeScript
49 lines
1.4 KiB
TypeScript
import fs from "fs";
|
|
import path from "path";
|
|
|
|
export type Settings = {
|
|
replicateApiToken: string;
|
|
jigsawApiKey: string;
|
|
modelVersion: string;
|
|
replicateEnabled: boolean;
|
|
adminPasswordHash: string;
|
|
};
|
|
|
|
const DEFAULT_SETTINGS: Settings = {
|
|
replicateApiToken: process.env["REPLICATE_API_TOKEN"] ?? "",
|
|
jigsawApiKey: process.env["JIGSAWSTACK_API_KEY"] ?? "",
|
|
modelVersion: "jigsawstack/text-translate:454df4c49941c05dea05175bd37686d0872c73c1f9366d1c2505db32ade52a89",
|
|
replicateEnabled: false,
|
|
adminPasswordHash: process.env["ADMIN_PASSWORD"] ?? "admin"
|
|
};
|
|
|
|
const SETTINGS_PATH = path.join(process.cwd(), "data", "settings.json");
|
|
|
|
function ensureDataDir() {
|
|
const dir = path.dirname(SETTINGS_PATH);
|
|
if (!fs.existsSync(dir)) {
|
|
fs.mkdirSync(dir, { recursive: true });
|
|
}
|
|
}
|
|
|
|
export function readSettings(): Settings {
|
|
try {
|
|
ensureDataDir();
|
|
if (!fs.existsSync(SETTINGS_PATH)) {
|
|
return { ...DEFAULT_SETTINGS };
|
|
}
|
|
const raw = fs.readFileSync(SETTINGS_PATH, "utf-8");
|
|
return { ...DEFAULT_SETTINGS, ...JSON.parse(raw) };
|
|
} catch {
|
|
return { ...DEFAULT_SETTINGS };
|
|
}
|
|
}
|
|
|
|
export function writeSettings(updates: Partial<Settings>): Settings {
|
|
ensureDataDir();
|
|
const current = readSettings();
|
|
const next = { ...current, ...updates };
|
|
fs.writeFileSync(SETTINGS_PATH, JSON.stringify(next, null, 2), "utf-8");
|
|
return next;
|
|
}
|