Add full /data backup export/import for server migration
- New admin endpoints: GET /api/admin-backup/export streams the entire data directory as tar.gz (after flushing queued writes); POST /api/admin-backup/import validates the archive, snapshots current data, replaces the folder, and reloads all in-memory state. - Admin UI: "Full Data Backup" section with download and restore-from- file controls in the Analytics panel. - Fix admin TOTP secret path to honor SITEFORGE_DATA_DIR (moved base path resolution to server/paths.js to avoid a circular import), so 2FA for admin and study users survives backup/restore. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
+2
-11
@@ -1,17 +1,8 @@
|
||||
import path from 'node:path'
|
||||
import { fileURLToPath } from 'node:url'
|
||||
import { validateAdminPasswordSetup } from './auth.js'
|
||||
import { ROOT_DIR, DATA_DIR } from './paths.js'
|
||||
|
||||
const __filename = fileURLToPath(import.meta.url)
|
||||
const __dirname = path.dirname(__filename)
|
||||
// server/config.js is inside server/, so the project root is one level up
|
||||
export const ROOT_DIR = path.resolve(__dirname, '..')
|
||||
|
||||
const DEFAULT_DATA_DIR = path.join(ROOT_DIR, 'data')
|
||||
const configuredDataDir = typeof process.env.SITEFORGE_DATA_DIR === 'string' ? process.env.SITEFORGE_DATA_DIR.trim() : ''
|
||||
export const DATA_DIR = configuredDataDir
|
||||
? (path.isAbsolute(configuredDataDir) ? configuredDataDir : path.resolve(ROOT_DIR, configuredDataDir))
|
||||
: DEFAULT_DATA_DIR
|
||||
export { ROOT_DIR, DATA_DIR }
|
||||
|
||||
export const DATA_FILE = path.join(DATA_DIR, 'admin-content.json')
|
||||
export const DRAFT_DATA_FILE = path.join(DATA_DIR, 'admin-content-draft.json')
|
||||
|
||||
Reference in New Issue
Block a user