pangea-server 3.3.74 → 3.3.76
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,10 +55,16 @@ 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 singularSuffixes = ['Image', 'Video'];
|
|
59
|
-
const pluralSuffixes = ['Images', 'Videos'];
|
|
60
58
|
const entries = [];
|
|
61
59
|
const visited = new WeakSet();
|
|
60
|
+
function matchesSingular(key) {
|
|
61
|
+
const k = key.toLowerCase();
|
|
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');
|
|
67
|
+
}
|
|
62
68
|
function collect(node) {
|
|
63
69
|
if (!node)
|
|
64
70
|
return;
|
|
@@ -78,13 +84,13 @@ async function setFilesUrls(data) {
|
|
|
78
84
|
visited.add(payload);
|
|
79
85
|
}
|
|
80
86
|
for (const [key, value] of Object.entries(payload)) {
|
|
81
|
-
if (typeof value === 'string' && value.length) {
|
|
82
|
-
if (
|
|
87
|
+
if (typeof value === 'string' && value.length > 0) {
|
|
88
|
+
if (matchesSingular(key)) {
|
|
83
89
|
entries.push({ node: payload, field: key, type: 'singular' });
|
|
84
90
|
}
|
|
85
91
|
}
|
|
86
|
-
else if (Array.isArray(value) && value.
|
|
87
|
-
if (
|
|
92
|
+
else if (Array.isArray(value) && value.every((v) => typeof v === 'string')) {
|
|
93
|
+
if (matchesPlural(key)) {
|
|
88
94
|
entries.push({ node: payload, field: key, type: 'plural' });
|
|
89
95
|
}
|
|
90
96
|
}
|
|
@@ -112,10 +118,10 @@ async function setFilesUrls(data) {
|
|
|
112
118
|
uniqueKeys.forEach((key, i) => urlMap.set(key, urls[i]));
|
|
113
119
|
for (const { node, field, type } of entries) {
|
|
114
120
|
if (type === 'singular') {
|
|
115
|
-
node[`${field}Url`] = urlMap.get(node[field]);
|
|
121
|
+
node[`${field}Url`] = urlMap.get(node[field]) || null;
|
|
116
122
|
}
|
|
117
123
|
else {
|
|
118
|
-
node[`${field}Urls`] = node[field].map((v) => urlMap.get(v));
|
|
124
|
+
node[`${field}Urls`] = node[field].map((v) => urlMap.get(v) || null);
|
|
119
125
|
}
|
|
120
126
|
}
|
|
121
127
|
}
|