pangea-server 3.3.76 → 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.
- package/dist/router/call-controller.js +24 -49
- package/package.json +1 -1
|
@@ -55,73 +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
|
-
const
|
|
58
|
+
const targets = [];
|
|
59
59
|
const visited = new WeakSet();
|
|
60
|
-
function
|
|
61
|
-
|
|
62
|
-
return k === 'image' || k === 'video' || k.endsWith('image') || k.endsWith('video');
|
|
63
|
-
}
|
|
64
|
-
function matchesPlural(key) {
|
|
65
|
-
const k = key.toLowerCase();
|
|
66
|
-
return k === 'images' || k === 'videos' || k.endsWith('images') || k.endsWith('videos');
|
|
60
|
+
function isTargetKey(key) {
|
|
61
|
+
return key.toLowerCase().includes('image') || key.toLowerCase().includes('video');
|
|
67
62
|
}
|
|
68
63
|
function collect(node) {
|
|
69
64
|
if (!node)
|
|
70
65
|
return;
|
|
66
|
+
if (Array.isArray(node)) {
|
|
67
|
+
node.forEach(collect);
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
71
70
|
if (typeof node !== 'object')
|
|
72
71
|
return;
|
|
73
72
|
if (visited.has(node))
|
|
74
73
|
return;
|
|
75
74
|
visited.add(node);
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
const payload = node.dataValues ? node.dataValues : node;
|
|
81
|
-
if (payload !== node) {
|
|
82
|
-
if (visited.has(payload))
|
|
83
|
-
return;
|
|
84
|
-
visited.add(payload);
|
|
85
|
-
}
|
|
86
|
-
for (const [key, value] of Object.entries(payload)) {
|
|
87
|
-
if (typeof value === 'string' && value.length > 0) {
|
|
88
|
-
if (matchesSingular(key)) {
|
|
89
|
-
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' });
|
|
90
79
|
}
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
if (matchesPlural(key)) {
|
|
94
|
-
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' });
|
|
95
82
|
}
|
|
96
83
|
}
|
|
97
|
-
|
|
98
|
-
collect(value);
|
|
99
|
-
}
|
|
84
|
+
collect(value);
|
|
100
85
|
}
|
|
101
86
|
}
|
|
102
87
|
collect(data);
|
|
103
|
-
if (!
|
|
88
|
+
if (!targets.length)
|
|
104
89
|
return;
|
|
105
|
-
const
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
allFileKeys.add(v);
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
const uniqueKeys = Array.from(allFileKeys);
|
|
116
|
-
const urls = await Promise.all(uniqueKeys.map((key) => helpers_1.FileStorage.GenerateDownloadUrl(key)));
|
|
117
|
-
const urlMap = new Map();
|
|
118
|
-
uniqueKeys.forEach((key, i) => urlMap.set(key, urls[i]));
|
|
119
|
-
for (const { node, field, type } of entries) {
|
|
120
|
-
if (type === 'singular') {
|
|
121
|
-
node[`${field}Url`] = urlMap.get(node[field]) || null;
|
|
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;
|
|
122
97
|
}
|
|
123
98
|
else {
|
|
124
|
-
node[`${
|
|
99
|
+
t.node[`${t.key}Urls`] = t.node[t.key].map((file) => map.get(file) || null);
|
|
125
100
|
}
|
|
126
|
-
}
|
|
101
|
+
});
|
|
127
102
|
}
|