mirror of
https://github.com/unraid/api.git
synced 2026-01-04 23:50:37 -06:00
fix: convert updateId function to iterative instead of recursive
This commit is contained in:
@@ -4,11 +4,25 @@ import { getServerIdentifier } from "@app/core/utils/server-identifier";
|
||||
const serverId = getServerIdentifier();
|
||||
|
||||
const updateId = (obj: any) => {
|
||||
if (obj && typeof obj === 'object') {
|
||||
if ('id' in obj && typeof obj.id === 'string') {
|
||||
obj.id = `${serverId}-${obj.id}`;
|
||||
const stack = [obj];
|
||||
let iterations = 0;
|
||||
// Prevent infinite loops
|
||||
while (stack.length > 0 && iterations < 100) {
|
||||
const current = stack.pop();
|
||||
|
||||
if (current && typeof current === 'object') {
|
||||
if ('id' in current && typeof current.id === 'string') {
|
||||
current.id = `${serverId}-${current.id}`;
|
||||
}
|
||||
|
||||
for (const value of Object.values(current)) {
|
||||
if (value && typeof value === 'object') {
|
||||
stack.push(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
Object.values(obj).forEach((value) => updateId(value));
|
||||
|
||||
iterations++;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user