pangea-server 3.3.75 → 3.3.77

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,70 +55,48 @@ 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] Iniciando setFilesUrls...');
59
- const singularSuffixes = ['Image', 'Video'];
60
- const pluralSuffixes = ['Images', 'Videos'];
61
- const entries = [];
58
+ const targets = [];
62
59
  const visited = new WeakSet();
60
+ function isTargetKey(key) {
61
+ return key.toLowerCase().includes('image') || key.toLowerCase().includes('video');
62
+ }
63
63
  function collect(node) {
64
64
  if (!node)
65
65
  return;
66
+ if (Array.isArray(node)) {
67
+ node.forEach(collect);
68
+ return;
69
+ }
66
70
  if (typeof node !== 'object')
67
71
  return;
68
72
  if (visited.has(node))
69
73
  return;
70
74
  visited.add(node);
71
- if (Array.isArray(node)) {
72
- node.forEach(collect);
73
- return;
74
- }
75
- const payload = node.dataValues ? node.dataValues : node;
76
- if (payload !== node) {
77
- if (visited.has(payload))
78
- return;
79
- visited.add(payload);
80
- }
81
- for (const [key, value] of Object.entries(payload)) {
82
- if (typeof value === 'string' && value.length) {
83
- if (singularSuffixes.some((s) => key === s.toLowerCase() || (key.length > s.length && key.endsWith(s)))) {
84
- entries.push({ node: payload, field: key, type: 'singular' });
75
+ for (const [key, value] of Object.entries(node)) {
76
+ if (isTargetKey(key)) {
77
+ if (typeof value === 'string' && value.length) {
78
+ targets.push({ node, key, type: 'single' });
85
79
  }
86
- }
87
- else if (Array.isArray(value) && value.every((v) => typeof v === 'string')) {
88
- if (pluralSuffixes.some((s) => key === s.toLowerCase() || (key.length > s.length && key.endsWith(s)))) {
89
- entries.push({ node: payload, field: key, type: 'plural' });
80
+ else if (Array.isArray(value) && value.length && value.every((v) => typeof v === 'string')) {
81
+ targets.push({ node, key, type: 'array' });
90
82
  }
91
83
  }
92
- if (typeof value === 'object' && value !== null) {
93
- collect(value);
94
- }
84
+ collect(value);
95
85
  }
96
86
  }
97
87
  collect(data);
98
- console.log(`[setFilesUrls] Entries encontrados: ${entries.length}`, entries.map((e) => e.field));
99
- if (!entries.length)
88
+ if (!targets.length)
100
89
  return;
101
- const allFileKeys = new Set();
102
- for (const { node, field, type } of entries) {
103
- if (type === 'singular') {
104
- allFileKeys.add(node[field]);
105
- }
106
- else {
107
- for (const v of node[field])
108
- allFileKeys.add(v);
109
- }
110
- }
111
- const uniqueKeys = Array.from(allFileKeys);
112
- const urls = await Promise.all(uniqueKeys.map((key) => helpers_1.FileStorage.GenerateDownloadUrl(key)));
113
- const urlMap = new Map();
114
- uniqueKeys.forEach((key, i) => urlMap.set(key, urls[i]));
115
- for (const { node, field, type } of entries) {
116
- if (type === 'singular') {
117
- node[`${field}Url`] = urlMap.get(node[field]);
90
+ const allFiles = Array.from(new Set(targets.flatMap((t) => (t.type === 'single' ? [t.node[t.key]] : t.node[t.key]))));
91
+ const urls = await Promise.all(allFiles.map((file) => helpers_1.FileStorage.GenerateDownloadUrl(file)));
92
+ const map = new Map();
93
+ allFiles.forEach((file, i) => map.set(file, urls[i]));
94
+ targets.forEach((t) => {
95
+ if (t.type === 'single') {
96
+ t.node[`${t.key}Url`] = map.get(t.node[t.key]) || null;
118
97
  }
119
98
  else {
120
- node[`${field}Urls`] = node[field].map((v) => urlMap.get(v));
99
+ t.node[`${t.key}Urls`] = t.node[t.key].map((file) => map.get(file) || null);
121
100
  }
122
- }
123
- console.log(`[setFilesUrls] URLs asignadas exitosamente`);
101
+ });
124
102
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "pangea-server",
3
3
  "description": "",
4
- "version": "3.3.75",
4
+ "version": "3.3.77",
5
5
  "files": [
6
6
  "dist"
7
7
  ],