mirror of
https://github.com/asabino2/dockerbackup.git
synced 2026-09-24 06:36:59 +00:00
atualiza versão para 0.0.8; corrige botões dos modais e implementa exclusão de arquivos de backup ao remover perfis
This commit is contained in:
+26
-5
@@ -262,13 +262,34 @@ async function main() {
|
||||
|
||||
app.delete('/api/profiles/:profileId', authMiddleware, async (request, response) => {
|
||||
try {
|
||||
const profile = await store.getProfile(request.params.profileId);
|
||||
await store.deleteProfile(request.params.profileId);
|
||||
const profileId = request.params.profileId;
|
||||
const profile = await store.getProfile(profileId);
|
||||
const backups = await store.listBackups(profileId);
|
||||
|
||||
await store.deleteProfile(profileId);
|
||||
|
||||
// Deleta arquivos de backup gravados em disco usando os caminhos registrados
|
||||
const slugifyLocal = (value) => value.replace(/[^a-zA-Z0-9_-]+/g, '-').replace(/^-+|-+$/g, '').toLowerCase() || 'item';
|
||||
const deletedProfileDirs = new Set();
|
||||
for (const backup of backups) {
|
||||
const backupRoot = backup.backupDir;
|
||||
if (!backupRoot) continue;
|
||||
for (const container of backup.containers || []) {
|
||||
if (container.archiveRelativePath) {
|
||||
await fs.rm(path.join(backupRoot, container.archiveRelativePath), { force: true });
|
||||
}
|
||||
}
|
||||
if (profile?.name) {
|
||||
deletedProfileDirs.add(path.join(backupRoot, slugifyLocal(profile.name)));
|
||||
}
|
||||
}
|
||||
|
||||
// Limpa a pasta do profile (cobre .snar e outros arquivos não registrados no store)
|
||||
if (profile?.backupDir) {
|
||||
const slugify = (value) => value.replace(/[^a-zA-Z0-9_-]+/g, '-').replace(/^-+|-+$/g, '').toLowerCase() || 'item';
|
||||
const profileBackupDir = path.join(profile.backupDir, slugify(profile.name));
|
||||
await fs.rm(profileBackupDir, { recursive: true, force: true });
|
||||
deletedProfileDirs.add(path.join(profile.backupDir, slugifyLocal(profile.name)));
|
||||
}
|
||||
for (const dir of deletedProfileDirs) {
|
||||
await fs.rm(dir, { recursive: true, force: true });
|
||||
}
|
||||
|
||||
response.status(204).end();
|
||||
|
||||
Reference in New Issue
Block a user