mirror of
https://github.com/digitalocean/nginxconfig.io.git
synced 2025-08-11 06:21:49 +08:00
Add global tools section & export data generator
This commit is contained in:
42
src/nginxconfig/util/export_data.js
Normal file
42
src/nginxconfig/util/export_data.js
Normal file
@@ -0,0 +1,42 @@
|
||||
const categoriesExport = (categories) => {
|
||||
const categoriesData = {};
|
||||
|
||||
// Work through each category
|
||||
for (const category in categories) {
|
||||
const categoryData = {};
|
||||
|
||||
// Go over each property in the category
|
||||
for (const property in categories[category]) {
|
||||
|
||||
// If the user input differs from the default, they changed it, so we save it
|
||||
const propertyData = categories[category][property];
|
||||
if (propertyData.value !== propertyData.default) {
|
||||
categoryData[property] = propertyData.value;
|
||||
}
|
||||
}
|
||||
|
||||
// If there were any property changes, save the category
|
||||
if (Object.keys(categoryData).length) {
|
||||
categoriesData[category] = categoryData;
|
||||
}
|
||||
}
|
||||
|
||||
return categoriesData;
|
||||
};
|
||||
|
||||
export default (domains, global) => {
|
||||
const exportData = {};
|
||||
|
||||
// Handle domains
|
||||
// Always save changes, even if none, so we can replicate the correct number of domains
|
||||
exportData.domains = domains.map(domain => categoriesExport(domain[0]));
|
||||
|
||||
// Handle global
|
||||
// If there were any category changes, save global changes
|
||||
const globalData = categoriesExport(global);
|
||||
if (Object.keys(globalData).length) {
|
||||
exportData.global = globalData;
|
||||
}
|
||||
|
||||
return exportData;
|
||||
};
|
Reference in New Issue
Block a user