feat: enhance settings and backup functionality

- Updated status descriptions in `SettingsIndexPageClient` to reflect current functionality.
- Added a new backup management section in settings for better user access.
- Modified `BackupService` to include backup type in filenames, improving clarity and organization.
- Enhanced backup file parsing to support both new and old filename formats, ensuring backward compatibility.
This commit is contained in:
Julien Froidefond
2025-09-20 16:21:50 +02:00
parent 9a33d1ee48
commit da0565472d
2 changed files with 30 additions and 9 deletions

View File

@@ -111,7 +111,7 @@ export class BackupService {
async createBackup(type: 'manual' | 'automatic' = 'manual'): Promise<BackupInfo> {
const backupId = `backup_${Date.now()}`;
const timestamp = new Date().toISOString().replace(/[:.]/g, '-');
const filename = `towercontrol_${timestamp}.db`;
const filename = `towercontrol_${type}_${timestamp}.db`;
const backupPath = path.join(this.getCurrentBackupPath(), filename);
console.log(`🔄 Starting ${type} backup: ${filename}`);
@@ -332,14 +332,28 @@ export class BackupService {
const filePath = path.join(currentBackupPath, file);
const stats = await fs.stat(filePath);
// Extraire la date du nom de fichier
const dateMatch = file.match(/towercontrol_(\d{4}-\d{2}-\d{2}T\d{2}-\d{2}-\d{2}-\d{3}Z)/);
// Extraire le type et la date du nom de fichier
// Nouveau format: towercontrol_manual_2025-09-18T14-12-05-737Z.db
// Ancien format: towercontrol_2025-09-18T14-12-05-737Z.db (considéré comme automatic)
let type: 'manual' | 'automatic' = 'automatic';
let dateMatch = file.match(/towercontrol_(manual|automatic)_(\d{4}-\d{2}-\d{2}T\d{2}-\d{2}-\d{2}-\d{3}Z)/);
if (!dateMatch) {
// Format ancien sans type - considérer comme automatic
dateMatch = file.match(/towercontrol_(\d{4}-\d{2}-\d{2}T\d{2}-\d{2}-\d{2}-\d{3}Z)/);
if (dateMatch) {
dateMatch = [dateMatch[0], 'automatic', dateMatch[1]]; // Restructurer pour compatibilité
}
} else {
type = dateMatch[1] as 'manual' | 'automatic';
}
let createdAt = stats.birthtime;
if (dateMatch) {
if (dateMatch && dateMatch[2]) {
// Convertir le format de fichier vers ISO string valide
// Format: 2025-09-18T14-12-05-737Z -> 2025-09-18T14:12:05.737Z
const isoString = dateMatch[1]
const isoString = dateMatch[2]
.replace(/T(\d{2})-(\d{2})-(\d{2})-(\d{3})Z/, 'T$1:$2:$3.$4Z');
createdAt = new Date(isoString);
}
@@ -349,7 +363,7 @@ export class BackupService {
filename: file,
size: stats.size,
createdAt,
type: 'automatic', // On ne peut pas déterminer le type depuis le nom
type,
status: 'success',
});
}