pangea-server 3.3.77 → 3.3.78
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.
|
@@ -58,7 +58,8 @@ async function setFilesUrls(data) {
|
|
|
58
58
|
const targets = [];
|
|
59
59
|
const visited = new WeakSet();
|
|
60
60
|
function isTargetKey(key) {
|
|
61
|
-
|
|
61
|
+
const k = key.toLowerCase();
|
|
62
|
+
return k.includes('image') || k.includes('video');
|
|
62
63
|
}
|
|
63
64
|
function collect(node) {
|
|
64
65
|
if (!node)
|
|
@@ -74,12 +75,12 @@ async function setFilesUrls(data) {
|
|
|
74
75
|
visited.add(node);
|
|
75
76
|
for (const [key, value] of Object.entries(node)) {
|
|
76
77
|
if (isTargetKey(key)) {
|
|
77
|
-
if (
|
|
78
|
-
targets.push({ node, key, type: 'single' });
|
|
79
|
-
}
|
|
80
|
-
else if (Array.isArray(value) && value.length && value.every((v) => typeof v === 'string')) {
|
|
78
|
+
if (Array.isArray(value) && value.every((v) => typeof v === 'string')) {
|
|
81
79
|
targets.push({ node, key, type: 'array' });
|
|
82
80
|
}
|
|
81
|
+
else if (typeof value === 'string') {
|
|
82
|
+
targets.push({ node, key, type: 'single' });
|
|
83
|
+
}
|
|
83
84
|
}
|
|
84
85
|
collect(value);
|
|
85
86
|
}
|
|
@@ -87,16 +88,16 @@ async function setFilesUrls(data) {
|
|
|
87
88
|
collect(data);
|
|
88
89
|
if (!targets.length)
|
|
89
90
|
return;
|
|
90
|
-
const allFiles = Array.from(new Set(targets.flatMap((t) => (t.type === '
|
|
91
|
+
const allFiles = Array.from(new Set(targets.flatMap((t) => (t.type === 'array' ? t.node[t.key] : t.node[t.key] ? [t.node[t.key]] : []))));
|
|
91
92
|
const urls = await Promise.all(allFiles.map((file) => helpers_1.FileStorage.GenerateDownloadUrl(file)));
|
|
92
93
|
const map = new Map();
|
|
93
94
|
allFiles.forEach((file, i) => map.set(file, urls[i]));
|
|
94
95
|
targets.forEach((t) => {
|
|
95
|
-
if (t.type === '
|
|
96
|
-
t.node[`${t.key}
|
|
96
|
+
if (t.type === 'array') {
|
|
97
|
+
t.node[`${t.key}Urls`] = t.node[t.key].map((file) => map.get(file) || null);
|
|
97
98
|
}
|
|
98
99
|
else {
|
|
99
|
-
t.node[`${t.key}
|
|
100
|
+
t.node[`${t.key}Url`] = t.node[t.key] ? map.get(t.node[t.key]) || null : null;
|
|
100
101
|
}
|
|
101
102
|
});
|
|
102
103
|
}
|