pangea-server 3.3.73 → 3.3.74
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/router/call-controller.js +20 -35
- package/package.json +1 -1
|
@@ -55,57 +55,47 @@ function hasInstancesAndTotalCount(obj) {
|
|
|
55
55
|
return typeof obj === 'object' && obj !== null && 'instances' in obj && 'totalCount' in obj;
|
|
56
56
|
}
|
|
57
57
|
async function setFilesUrls(data) {
|
|
58
|
-
console.log('[setFilesUrls] data recibida:', JSON.stringify(data, null, 2));
|
|
59
58
|
const singularSuffixes = ['Image', 'Video'];
|
|
60
59
|
const pluralSuffixes = ['Images', 'Videos'];
|
|
61
60
|
const entries = [];
|
|
62
61
|
const visited = new WeakSet();
|
|
63
62
|
function collect(node) {
|
|
64
|
-
if (!node)
|
|
65
|
-
console.log('[setFilesUrls] collect: node es falsy, salteando');
|
|
63
|
+
if (!node)
|
|
66
64
|
return;
|
|
67
|
-
|
|
65
|
+
if (typeof node !== 'object')
|
|
66
|
+
return;
|
|
67
|
+
if (visited.has(node))
|
|
68
|
+
return;
|
|
69
|
+
visited.add(node);
|
|
68
70
|
if (Array.isArray(node)) {
|
|
69
|
-
console.log('[setFilesUrls] collect: node es array con', node.length, 'elementos');
|
|
70
71
|
node.forEach(collect);
|
|
71
72
|
return;
|
|
72
73
|
}
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
74
|
+
const payload = node.dataValues ? node.dataValues : node;
|
|
75
|
+
if (payload !== node) {
|
|
76
|
+
if (visited.has(payload))
|
|
77
|
+
return;
|
|
78
|
+
visited.add(payload);
|
|
76
79
|
}
|
|
77
|
-
|
|
78
|
-
return;
|
|
79
|
-
visited.add(node);
|
|
80
|
-
console.log('[setFilesUrls] collect: analizando objeto con keys:', Object.keys(node));
|
|
81
|
-
for (const [key, value] of Object.entries(node)) {
|
|
82
|
-
const valueType = Array.isArray(value) ? 'array' : typeof value;
|
|
83
|
-
console.log(`[setFilesUrls] key="${key}" valueType=${valueType} value=`, Array.isArray(value) ? `[${value.length} items]` : typeof value === 'string' ? `"${value.substring(0, 50)}"` : value);
|
|
80
|
+
for (const [key, value] of Object.entries(payload)) {
|
|
84
81
|
if (typeof value === 'string' && value.length) {
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
if (matchSingular) {
|
|
88
|
-
entries.push({ node, field: key, type: 'singular' });
|
|
89
|
-
console.log(`[setFilesUrls] -> MATCH SINGULAR: field="${key}"`);
|
|
82
|
+
if (singularSuffixes.some((s) => key === s.toLowerCase() || (key.length > s.length && key.endsWith(s)))) {
|
|
83
|
+
entries.push({ node: payload, field: key, type: 'singular' });
|
|
90
84
|
}
|
|
91
85
|
}
|
|
92
86
|
else if (Array.isArray(value) && value.length && value.every((v) => typeof v === 'string')) {
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
if (matchPlural) {
|
|
96
|
-
entries.push({ node, field: key, type: 'plural' });
|
|
97
|
-
console.log(`[setFilesUrls] -> MATCH PLURAL: field="${key}"`);
|
|
87
|
+
if (pluralSuffixes.some((s) => key === s.toLowerCase() || (key.length > s.length && key.endsWith(s)))) {
|
|
88
|
+
entries.push({ node: payload, field: key, type: 'plural' });
|
|
98
89
|
}
|
|
99
90
|
}
|
|
91
|
+
if (typeof value === 'object' && value !== null) {
|
|
92
|
+
collect(value);
|
|
93
|
+
}
|
|
100
94
|
}
|
|
101
|
-
Object.values(node).forEach(collect);
|
|
102
95
|
}
|
|
103
96
|
collect(data);
|
|
104
|
-
|
|
105
|
-
if (!entries.length) {
|
|
106
|
-
console.log('[setFilesUrls] No hay entries, saliendo');
|
|
97
|
+
if (!entries.length)
|
|
107
98
|
return;
|
|
108
|
-
}
|
|
109
99
|
const allFileKeys = new Set();
|
|
110
100
|
for (const { node, field, type } of entries) {
|
|
111
101
|
if (type === 'singular') {
|
|
@@ -117,20 +107,15 @@ async function setFilesUrls(data) {
|
|
|
117
107
|
}
|
|
118
108
|
}
|
|
119
109
|
const uniqueKeys = Array.from(allFileKeys);
|
|
120
|
-
console.log('[setFilesUrls] uniqueKeys:', uniqueKeys);
|
|
121
110
|
const urls = await Promise.all(uniqueKeys.map((key) => helpers_1.FileStorage.GenerateDownloadUrl(key)));
|
|
122
|
-
console.log('[setFilesUrls] urls generadas:', urls);
|
|
123
111
|
const urlMap = new Map();
|
|
124
112
|
uniqueKeys.forEach((key, i) => urlMap.set(key, urls[i]));
|
|
125
113
|
for (const { node, field, type } of entries) {
|
|
126
114
|
if (type === 'singular') {
|
|
127
115
|
node[`${field}Url`] = urlMap.get(node[field]);
|
|
128
|
-
console.log(`[setFilesUrls] asignado ${field}Url =`, node[`${field}Url`]);
|
|
129
116
|
}
|
|
130
117
|
else {
|
|
131
118
|
node[`${field}Urls`] = node[field].map((v) => urlMap.get(v));
|
|
132
|
-
console.log(`[setFilesUrls] asignado ${field}Urls =`, node[`${field}Urls`]);
|
|
133
119
|
}
|
|
134
120
|
}
|
|
135
|
-
console.log('[setFilesUrls] FIN');
|
|
136
121
|
}
|