Skip to content

Commit

Permalink
Updated findChangedConfigItems function
Browse files Browse the repository at this point in the history
  • Loading branch information
Tzahi12345 committed Nov 29, 2023
1 parent 8a588cf commit 3151200
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions backend/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -167,17 +167,18 @@ exports.globalArgsRequiresSafeDownload = () => {
return failedArgs && failedArgs.length > 0;
}

exports.findChangedConfigItems = (old_config, new_config, key = '', changedConfigItems = [], depth = 0) => {
exports.findChangedConfigItems = (old_config, new_config, path = '', changedConfigItems = [], depth = 0) => {
if (typeof old_config === 'object' && typeof new_config === 'object' && depth < 3) {
for (const key in old_config) {
if (Object.prototype.hasOwnProperty.call(new_config, key)) {
exports.findChangedConfigItems(old_config[key], new_config[key], key, changedConfigItems, depth + 1);
exports.findChangedConfigItems(old_config[key], new_config[key], `${path}${path ? '.' : ''}${key}`, changedConfigItems, depth + 1);
}
}
} else {
if (JSON.stringify(old_config) !== JSON.stringify(new_config)) {
const key = getConfigItemKeyByPath(path);
changedConfigItems.push({
key: key,
key: key ? key : path.split('.')[path.split('.').length - 1], // return key in CONFIG_ITEMS or the object key
old_value: JSON.parse(JSON.stringify(old_config)),
new_value: JSON.parse(JSON.stringify(new_config))
});
Expand All @@ -186,6 +187,12 @@ exports.findChangedConfigItems = (old_config, new_config, key = '', changedConfi
return changedConfigItems;
}

function getConfigItemKeyByPath(path) {
const found_item = Object.values(exports.CONFIG_ITEMS).find(item => item.path === path);
if (found_item) return found_item['key'];
else return null;
}

const DEFAULT_CONFIG = {
"YoutubeDLMaterial": {
"Host": {
Expand Down

0 comments on commit 3151200

Please sign in to comment.