pangea-server 3.3.79 → 3.3.81
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.
|
@@ -62,6 +62,13 @@ async function setFilesUrls(data) {
|
|
|
62
62
|
const k = key.toLowerCase();
|
|
63
63
|
return k.includes('image') || k.includes('video');
|
|
64
64
|
}
|
|
65
|
+
function normalizeArray(value) {
|
|
66
|
+
if (Array.isArray(value))
|
|
67
|
+
return value;
|
|
68
|
+
if (typeof value === 'string' && value.length)
|
|
69
|
+
return value.split(',').map((v) => v.trim()).filter(Boolean);
|
|
70
|
+
return [];
|
|
71
|
+
}
|
|
65
72
|
function collect(node) {
|
|
66
73
|
if (!node)
|
|
67
74
|
return;
|
|
@@ -76,11 +83,24 @@ async function setFilesUrls(data) {
|
|
|
76
83
|
visited.add(node);
|
|
77
84
|
for (const [key, value] of Object.entries(node)) {
|
|
78
85
|
if (isTargetKey(key)) {
|
|
79
|
-
if (Array.isArray(value)
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
86
|
+
if (Array.isArray(value) || typeof value === 'string') {
|
|
87
|
+
const arr = normalizeArray(value);
|
|
88
|
+
if (arr.length > 1) {
|
|
89
|
+
node[key] = arr;
|
|
90
|
+
arrayTargets.push({ node, key });
|
|
91
|
+
}
|
|
92
|
+
else if (arr.length === 1) {
|
|
93
|
+
node[key] = arr[0];
|
|
94
|
+
singleTargets.push({ node, key });
|
|
95
|
+
}
|
|
96
|
+
else if (Array.isArray(value)) {
|
|
97
|
+
node[key] = [];
|
|
98
|
+
arrayTargets.push({ node, key });
|
|
99
|
+
}
|
|
100
|
+
else {
|
|
101
|
+
node[key] = null;
|
|
102
|
+
singleTargets.push({ node, key });
|
|
103
|
+
}
|
|
84
104
|
}
|
|
85
105
|
}
|
|
86
106
|
collect(value);
|
|
@@ -95,14 +115,19 @@ async function setFilesUrls(data) {
|
|
|
95
115
|
});
|
|
96
116
|
arrayTargets.forEach(({ node, key }) => {
|
|
97
117
|
const arr = node[key];
|
|
118
|
+
if (!Array.isArray(arr))
|
|
119
|
+
return;
|
|
98
120
|
arr.forEach((v) => {
|
|
99
121
|
if (typeof v === 'string' && v.length)
|
|
100
122
|
filesSet.add(v);
|
|
101
123
|
});
|
|
102
124
|
});
|
|
103
125
|
const files = Array.from(filesSet);
|
|
104
|
-
if (!files.length)
|
|
126
|
+
if (!files.length) {
|
|
127
|
+
arrayTargets.forEach(({ node, key }) => (node[`${key}Urls`] = []));
|
|
128
|
+
singleTargets.forEach(({ node, key }) => (node[`${key}Url`] = null));
|
|
105
129
|
return;
|
|
130
|
+
}
|
|
106
131
|
const urls = await Promise.all(files.map((file) => helpers_1.FileStorage.GenerateDownloadUrl(file)));
|
|
107
132
|
const map = new Map();
|
|
108
133
|
files.forEach((file, i) => map.set(file, urls[i]));
|
|
@@ -112,6 +137,6 @@ async function setFilesUrls(data) {
|
|
|
112
137
|
});
|
|
113
138
|
arrayTargets.forEach(({ node, key }) => {
|
|
114
139
|
const arr = node[key];
|
|
115
|
-
node[`${key}Urls`] = Array.isArray(arr) ? arr.map((v) => (v ? map.get(v)
|
|
140
|
+
node[`${key}Urls`] = Array.isArray(arr) ? arr.map((v) => (v && map.has(v) ? map.get(v) : null)) : [];
|
|
116
141
|
});
|
|
117
142
|
}
|