pangea-server 3.3.72 → 3.3.73
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.
|
@@ -55,39 +55,57 @@ 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));
|
|
58
59
|
const singularSuffixes = ['Image', 'Video'];
|
|
59
60
|
const pluralSuffixes = ['Images', 'Videos'];
|
|
60
61
|
const entries = [];
|
|
61
62
|
const visited = new WeakSet();
|
|
62
63
|
function collect(node) {
|
|
63
|
-
if (!node)
|
|
64
|
+
if (!node) {
|
|
65
|
+
console.log('[setFilesUrls] collect: node es falsy, salteando');
|
|
64
66
|
return;
|
|
67
|
+
}
|
|
65
68
|
if (Array.isArray(node)) {
|
|
69
|
+
console.log('[setFilesUrls] collect: node es array con', node.length, 'elementos');
|
|
66
70
|
node.forEach(collect);
|
|
67
71
|
return;
|
|
68
72
|
}
|
|
69
|
-
if (typeof node !== 'object')
|
|
73
|
+
if (typeof node !== 'object') {
|
|
74
|
+
console.log('[setFilesUrls] collect: node no es object, es', typeof node);
|
|
70
75
|
return;
|
|
76
|
+
}
|
|
71
77
|
if (visited.has(node))
|
|
72
78
|
return;
|
|
73
79
|
visited.add(node);
|
|
80
|
+
console.log('[setFilesUrls] collect: analizando objeto con keys:', Object.keys(node));
|
|
74
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);
|
|
75
84
|
if (typeof value === 'string' && value.length) {
|
|
76
|
-
|
|
85
|
+
const matchSingular = singularSuffixes.find((s) => key === s.toLowerCase() || (key.length > s.length && key.endsWith(s)));
|
|
86
|
+
console.log(`[setFilesUrls] -> string check: matchSingular=${matchSingular || 'none'}`);
|
|
87
|
+
if (matchSingular) {
|
|
77
88
|
entries.push({ node, field: key, type: 'singular' });
|
|
89
|
+
console.log(`[setFilesUrls] -> MATCH SINGULAR: field="${key}"`);
|
|
78
90
|
}
|
|
79
91
|
}
|
|
80
92
|
else if (Array.isArray(value) && value.length && value.every((v) => typeof v === 'string')) {
|
|
81
|
-
|
|
93
|
+
const matchPlural = pluralSuffixes.find((s) => key === s.toLowerCase() || (key.length > s.length && key.endsWith(s)));
|
|
94
|
+
console.log(`[setFilesUrls] -> string[] check: matchPlural=${matchPlural || 'none'}`);
|
|
95
|
+
if (matchPlural) {
|
|
82
96
|
entries.push({ node, field: key, type: 'plural' });
|
|
97
|
+
console.log(`[setFilesUrls] -> MATCH PLURAL: field="${key}"`);
|
|
83
98
|
}
|
|
84
99
|
}
|
|
85
100
|
}
|
|
86
101
|
Object.values(node).forEach(collect);
|
|
87
102
|
}
|
|
88
103
|
collect(data);
|
|
89
|
-
|
|
104
|
+
console.log('[setFilesUrls] entries encontrados:', entries.map((e) => ({ field: e.field, type: e.type })));
|
|
105
|
+
if (!entries.length) {
|
|
106
|
+
console.log('[setFilesUrls] No hay entries, saliendo');
|
|
90
107
|
return;
|
|
108
|
+
}
|
|
91
109
|
const allFileKeys = new Set();
|
|
92
110
|
for (const { node, field, type } of entries) {
|
|
93
111
|
if (type === 'singular') {
|
|
@@ -99,15 +117,20 @@ async function setFilesUrls(data) {
|
|
|
99
117
|
}
|
|
100
118
|
}
|
|
101
119
|
const uniqueKeys = Array.from(allFileKeys);
|
|
120
|
+
console.log('[setFilesUrls] uniqueKeys:', uniqueKeys);
|
|
102
121
|
const urls = await Promise.all(uniqueKeys.map((key) => helpers_1.FileStorage.GenerateDownloadUrl(key)));
|
|
122
|
+
console.log('[setFilesUrls] urls generadas:', urls);
|
|
103
123
|
const urlMap = new Map();
|
|
104
124
|
uniqueKeys.forEach((key, i) => urlMap.set(key, urls[i]));
|
|
105
125
|
for (const { node, field, type } of entries) {
|
|
106
126
|
if (type === 'singular') {
|
|
107
127
|
node[`${field}Url`] = urlMap.get(node[field]);
|
|
128
|
+
console.log(`[setFilesUrls] asignado ${field}Url =`, node[`${field}Url`]);
|
|
108
129
|
}
|
|
109
130
|
else {
|
|
110
131
|
node[`${field}Urls`] = node[field].map((v) => urlMap.get(v));
|
|
132
|
+
console.log(`[setFilesUrls] asignado ${field}Urls =`, node[`${field}Urls`]);
|
|
111
133
|
}
|
|
112
134
|
}
|
|
135
|
+
console.log('[setFilesUrls] FIN');
|
|
113
136
|
}
|