import { listBackups, getBackupServiceStatus, createHourlyBackup } from '../../services/backupService.js'; /** * Registers internal backup service status and execution endpoints. * @param {import('express').Application} app - Express app * @param {string} [basePath=''] - Optional URL prefix for all routes in this module */ export function register(app, basePath = '') { /** * @openapi * /backup: * get: * tags: [Backup] * summary: List backups and service status * description: Retrieves the current status of the internal backup service and lists available hourly, daily, and monthly backups. * responses: * 200: * description: Backup service status and listing * content: * application/json: * schema: * $ref: '#/components/schemas/BackupOverviewResponse' * 500: * description: Internal error * content: * application/json: * schema: * $ref: '#/components/schemas/Error' */ // #region GET /backup // MARK: handles GET /backup to list backups and service status app.get(`${basePath}/backup`, async (_req, res) => { try { const status = getBackupServiceStatus(); const backups = listBackups(); res.status(200).json({ status, backups }); } catch (error) { res.status(500).json({ error: error.message }); } }); // #endregion /** * @openapi * /backup/run: * post: * tags: [Backup] * summary: Trigger manual backup * description: Immediately triggers an on-demand backup snapshot of VFS, storage, and SQLite database. * responses: * 200: * description: Backup triggered successfully * content: * application/json: * schema: * $ref: '#/components/schemas/BackupRunResult' * 500: * description: Backup execution failure * content: * application/json: * schema: * $ref: '#/components/schemas/Error' */ // #region POST /backup/run // MARK: handles POST /backup/run to trigger manual backup app.post(`${basePath}/backup/run`, async (_req, res) => { try { const result = await createHourlyBackup({ manual: true }); res.status(200).json(result); } catch (error) { res.status(500).json({ error: error.message }); } }); // #endregion }