chore(app.js): remove redundant function, use deep clone over JSON.parse(JSON.stringify())

This commit is contained in:
Rim 2025-03-30 23:57:20 -04:00
parent 2cdf46e8cb
commit 83030bf030

41
app.js
View File

@ -85,6 +85,43 @@ const sanitizeJsonOutput = (data) => {
}
};
// Replace the processJsonOutput function with this more efficient version
const processJsonOutput = (data, options = { sanitize: true, replaceKeys: true }) => {
// Use a more efficient deep clone approach instead of JSON.parse(JSON.stringify())
function deepClone(obj) {
if (obj === null || typeof obj !== 'object') {
return obj;
}
if (Array.isArray(obj)) {
return obj.map(item => deepClone(item));
}
const clone = {};
Object.keys(obj).forEach(key => {
clone[key] = deepClone(obj[key]);
});
return clone;
}
// Create a deep copy of the data to avoid reference issues
let processedData = deepClone(data);
// Apply sanitization if needed
if (options.sanitize) {
processedData = sanitizeJsonOutput(processedData);
}
// Apply key replacement if needed
if (options.replaceKeys) {
processedData = replaceJsonKeys(processedData);
}
return processedData;
};
/*
// Combined function to sanitize and replace keys
const processJsonOutput = (data, options = { sanitize: true, replaceKeys: true }) => {
// Create a deep copy of the data to avoid reference issues
@ -101,8 +138,9 @@ const processJsonOutput = (data, options = { sanitize: true, replaceKeys: true }
}
return processedData;
};
}; */
/*
// Improved token management with auto-refresh
const tokenManager = {
tokens: new Map(),
@ -146,6 +184,7 @@ const tokenManager = {
this.tokens.delete(ssoToken);
}
};
*/
// Store active sessions to avoid repeated logins
const activeSessions = new Map();