feat: add admin panel, Replicate AI translation, and document translation
- 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>
2026-03-10 07:43:54 +01:00
|
|
|
import fs from "fs";
|
|
|
|
|
import path from "path";
|
|
|
|
|
|
2026-03-10 08:50:40 +01:00
|
|
|
export type ReplicateMode = "cloud" | "local";
|
|
|
|
|
|
feat: add admin panel, Replicate AI translation, and document translation
- 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>
2026-03-10 07:43:54 +01:00
|
|
|
export type Settings = {
|
|
|
|
|
replicateApiToken: string;
|
|
|
|
|
jigsawApiKey: string;
|
|
|
|
|
modelVersion: string;
|
|
|
|
|
replicateEnabled: boolean;
|
2026-03-10 08:50:40 +01:00
|
|
|
replicateMode: ReplicateMode;
|
|
|
|
|
localEndpoint: string;
|
feat: add admin panel, Replicate AI translation, and document translation
- 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>
2026-03-10 07:43:54 +01:00
|
|
|
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,
|
2026-03-10 08:50:40 +01:00
|
|
|
replicateMode: (process.env["REPLICATE_MODE"] as ReplicateMode) ?? "cloud",
|
|
|
|
|
localEndpoint: process.env["LOCAL_MODEL_ENDPOINT"] ?? "http://localhost:5030/predictions",
|
feat: add admin panel, Replicate AI translation, and document translation
- 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>
2026-03-10 07:43:54 +01:00
|
|
|
adminPasswordHash: process.env["ADMIN_PASSWORD"] ?? "admin"
|
|
|
|
|
};
|
|
|
|
|
|
2026-03-10 08:23:29 +01:00
|
|
|
/**
|
|
|
|
|
* Resolve a writable path for settings.json.
|
|
|
|
|
* Priority:
|
|
|
|
|
* 1. SETTINGS_PATH env var (explicit override)
|
|
|
|
|
* 2. <cwd>/data/settings.json (default, works when data/ is writable)
|
|
|
|
|
* 3. /tmp/lingvai-settings.json (fallback for read-only containers)
|
|
|
|
|
*/
|
|
|
|
|
function resolveSettingsPath(): string {
|
|
|
|
|
if (process.env["SETTINGS_PATH"]) {
|
|
|
|
|
return process.env["SETTINGS_PATH"];
|
|
|
|
|
}
|
|
|
|
|
const primary = path.join(process.cwd(), "data", "settings.json");
|
|
|
|
|
try {
|
|
|
|
|
const dir = path.dirname(primary);
|
feat: add admin panel, Replicate AI translation, and document translation
- 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>
2026-03-10 07:43:54 +01:00
|
|
|
fs.mkdirSync(dir, { recursive: true });
|
2026-03-10 08:23:29 +01:00
|
|
|
// Test write access by opening with 'a' (append/create without truncating)
|
|
|
|
|
const fd = fs.openSync(primary, "a");
|
|
|
|
|
fs.closeSync(fd);
|
|
|
|
|
return primary;
|
|
|
|
|
} catch {
|
|
|
|
|
return path.join("/tmp", "lingvai-settings.json");
|
feat: add admin panel, Replicate AI translation, and document translation
- 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>
2026-03-10 07:43:54 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-10 08:23:29 +01:00
|
|
|
// Resolve once at module load so every call uses the same path
|
|
|
|
|
const SETTINGS_PATH = resolveSettingsPath();
|
|
|
|
|
|
|
|
|
|
if (SETTINGS_PATH.startsWith("/tmp")) {
|
|
|
|
|
console.warn(
|
|
|
|
|
`[lingvai] data/settings.json is not writable. ` +
|
|
|
|
|
`Settings will be stored at ${SETTINGS_PATH}. ` +
|
|
|
|
|
`Mount a writable volume at /app/data or set SETTINGS_PATH to persist across restarts.`
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
feat: add admin panel, Replicate AI translation, and document translation
- 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>
2026-03-10 07:43:54 +01:00
|
|
|
export function readSettings(): Settings {
|
|
|
|
|
try {
|
|
|
|
|
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 {
|
|
|
|
|
const current = readSettings();
|
|
|
|
|
const next = { ...current, ...updates };
|
2026-03-10 08:23:29 +01:00
|
|
|
const dir = path.dirname(SETTINGS_PATH);
|
|
|
|
|
fs.mkdirSync(dir, { recursive: true });
|
feat: add admin panel, Replicate AI translation, and document translation
- 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>
2026-03-10 07:43:54 +01:00
|
|
|
fs.writeFileSync(SETTINGS_PATH, JSON.stringify(next, null, 2), "utf-8");
|
|
|
|
|
return next;
|
|
|
|
|
}
|