pangea-server 3.3.77 → 3.3.79
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 +32 -17
- package/package.json +1 -1
|
@@ -55,10 +55,12 @@ 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 targets = [];
|
|
59
58
|
const visited = new WeakSet();
|
|
59
|
+
const singleTargets = [];
|
|
60
|
+
const arrayTargets = [];
|
|
60
61
|
function isTargetKey(key) {
|
|
61
|
-
|
|
62
|
+
const k = key.toLowerCase();
|
|
63
|
+
return k.includes('image') || k.includes('video');
|
|
62
64
|
}
|
|
63
65
|
function collect(node) {
|
|
64
66
|
if (!node)
|
|
@@ -74,29 +76,42 @@ async function setFilesUrls(data) {
|
|
|
74
76
|
visited.add(node);
|
|
75
77
|
for (const [key, value] of Object.entries(node)) {
|
|
76
78
|
if (isTargetKey(key)) {
|
|
77
|
-
if (
|
|
78
|
-
|
|
79
|
+
if (Array.isArray(value) && value.every((v) => typeof v === 'string')) {
|
|
80
|
+
arrayTargets.push({ node, key });
|
|
79
81
|
}
|
|
80
|
-
else if (
|
|
81
|
-
|
|
82
|
+
else if (typeof value === 'string') {
|
|
83
|
+
singleTargets.push({ node, key });
|
|
82
84
|
}
|
|
83
85
|
}
|
|
84
86
|
collect(value);
|
|
85
87
|
}
|
|
86
88
|
}
|
|
87
89
|
collect(data);
|
|
88
|
-
|
|
90
|
+
const filesSet = new Set();
|
|
91
|
+
singleTargets.forEach(({ node, key }) => {
|
|
92
|
+
const val = node[key];
|
|
93
|
+
if (typeof val === 'string' && val.length)
|
|
94
|
+
filesSet.add(val);
|
|
95
|
+
});
|
|
96
|
+
arrayTargets.forEach(({ node, key }) => {
|
|
97
|
+
const arr = node[key];
|
|
98
|
+
arr.forEach((v) => {
|
|
99
|
+
if (typeof v === 'string' && v.length)
|
|
100
|
+
filesSet.add(v);
|
|
101
|
+
});
|
|
102
|
+
});
|
|
103
|
+
const files = Array.from(filesSet);
|
|
104
|
+
if (!files.length)
|
|
89
105
|
return;
|
|
90
|
-
const
|
|
91
|
-
const urls = await Promise.all(allFiles.map((file) => helpers_1.FileStorage.GenerateDownloadUrl(file)));
|
|
106
|
+
const urls = await Promise.all(files.map((file) => helpers_1.FileStorage.GenerateDownloadUrl(file)));
|
|
92
107
|
const map = new Map();
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
}
|
|
108
|
+
files.forEach((file, i) => map.set(file, urls[i]));
|
|
109
|
+
singleTargets.forEach(({ node, key }) => {
|
|
110
|
+
const val = node[key];
|
|
111
|
+
node[`${key}Url`] = typeof val === 'string' && val.length ? map.get(val) || null : null;
|
|
112
|
+
});
|
|
113
|
+
arrayTargets.forEach(({ node, key }) => {
|
|
114
|
+
const arr = node[key];
|
|
115
|
+
node[`${key}Urls`] = Array.isArray(arr) ? arr.map((v) => (v ? map.get(v) || null : null)) : [];
|
|
101
116
|
});
|
|
102
117
|
}
|