mirror of
https://github.com/asabino2/dockerbackup.git
synced 2026-09-24 06:36:59 +00:00
atualiza versão para 0.0.7; adiciona exclusão em cascata de locais de armazenamento e nova rota para verificar impacto
This commit is contained in:
@@ -470,6 +470,19 @@ async function main() {
|
||||
}
|
||||
});
|
||||
|
||||
app.get('/api/storage-locations/:id/impact', authMiddleware, async (request, response) => {
|
||||
try {
|
||||
const impact = await store.storageLocationImpact(request.params.id);
|
||||
response.json({
|
||||
profileCount: impact.profiles.length,
|
||||
profileNames: impact.profiles.map((p) => p.name),
|
||||
backupCount: impact.backupCount,
|
||||
});
|
||||
} catch (error) {
|
||||
response.status(500).json({ error: error.message });
|
||||
}
|
||||
});
|
||||
|
||||
app.delete('/api/storage-locations/:id', authMiddleware, async (request, response) => {
|
||||
try {
|
||||
await store.deleteStorageLocation(request.params.id);
|
||||
|
||||
@@ -58,6 +58,7 @@ class JsonStore {
|
||||
backupScope: profileInput.backupScope || 'volumes',
|
||||
volumeSelections: profileInput.volumeSelections || {},
|
||||
backupDir: profileInput.backupDir,
|
||||
storageLocationId: profileInput.storageLocationId || null,
|
||||
updatedAt: now,
|
||||
createdAt: profileInput.createdAt || now,
|
||||
};
|
||||
@@ -166,8 +167,21 @@ class JsonStore {
|
||||
return location;
|
||||
}
|
||||
|
||||
async storageLocationImpact(locationId) {
|
||||
const data = await this.read();
|
||||
const profiles = data.profiles.filter((p) => p.storageLocationId === locationId);
|
||||
const profileIds = new Set(profiles.map((p) => p.id));
|
||||
const backupCount = data.backups.filter((b) => profileIds.has(b.profileId)).length;
|
||||
return { profiles, backupCount };
|
||||
}
|
||||
|
||||
async deleteStorageLocation(locationId) {
|
||||
await this.write((data) => {
|
||||
const profileIds = new Set(
|
||||
data.profiles.filter((p) => p.storageLocationId === locationId).map((p) => p.id)
|
||||
);
|
||||
data.backups = data.backups.filter((b) => !profileIds.has(b.profileId));
|
||||
data.profiles = data.profiles.filter((p) => !profileIds.has(p.id));
|
||||
data.storageLocations = data.storageLocations.filter((item) => item.id !== locationId);
|
||||
return data;
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user