Adds autoImportEnabled/autoImportHour to rclone config. A separate hourly cron finds the latest .zip in backups/ and restores it to the database (drop schema, psql restore, apply migrations). Frontend shows toggle + time picker + Import Now button in the Receiver PC section. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
63 lines
1.6 KiB
TypeScript
63 lines
1.6 KiB
TypeScript
import fs from "fs";
|
|
import path from "path";
|
|
|
|
const CONFIG_FILE = path.resolve(process.cwd(), "rclone-config.json");
|
|
|
|
export const RCLONE_USER = "MyDentalApp";
|
|
export const RCLONE_PASS = "SuperSecret!@2026";
|
|
|
|
export interface RcloneConfig {
|
|
// Source role: serve backups folder via WebDAV
|
|
serverEnabled: boolean;
|
|
serverPort: number;
|
|
|
|
// Receiver role: pull backups from source PC
|
|
receiverEnabled: boolean;
|
|
receiverSyncHour: number;
|
|
sourceIp: string;
|
|
sourcePort: number;
|
|
lastSyncAt: string | null;
|
|
lastSyncStatus: string | null;
|
|
lastSyncError: string | null;
|
|
|
|
// Auto-import: restore latest backup after rclone pull
|
|
autoImportEnabled: boolean;
|
|
autoImportHour: number;
|
|
lastImportAt: string | null;
|
|
lastImportStatus: string | null;
|
|
lastImportError: string | null;
|
|
}
|
|
|
|
const DEFAULT_CONFIG: RcloneConfig = {
|
|
serverEnabled: false,
|
|
serverPort: 8080,
|
|
receiverEnabled: false,
|
|
receiverSyncHour: 21,
|
|
sourceIp: "",
|
|
sourcePort: 8080,
|
|
lastSyncAt: null,
|
|
lastSyncStatus: null,
|
|
lastSyncError: null,
|
|
autoImportEnabled: false,
|
|
autoImportHour: 22,
|
|
lastImportAt: null,
|
|
lastImportStatus: null,
|
|
lastImportError: null,
|
|
};
|
|
|
|
export function readRcloneConfig(): RcloneConfig {
|
|
if (fs.existsSync(CONFIG_FILE)) {
|
|
try {
|
|
return { ...DEFAULT_CONFIG, ...JSON.parse(fs.readFileSync(CONFIG_FILE, "utf8")) };
|
|
} catch {}
|
|
}
|
|
return { ...DEFAULT_CONFIG };
|
|
}
|
|
|
|
export function writeRcloneConfig(patch: Partial<RcloneConfig>): RcloneConfig {
|
|
const current = readRcloneConfig();
|
|
const updated = { ...current, ...patch };
|
|
fs.writeFileSync(CONFIG_FILE, JSON.stringify(updated, null, 2), "utf8");
|
|
return updated;
|
|
}
|