pangea-server 3.3.80 → 3.3.82
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 +49 -43
- package/package.json +1 -1
|
@@ -56,11 +56,31 @@ function hasInstancesAndTotalCount(obj) {
|
|
|
56
56
|
}
|
|
57
57
|
async function setFilesUrls(data) {
|
|
58
58
|
const visited = new WeakSet();
|
|
59
|
-
const
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
59
|
+
const targets = [];
|
|
60
|
+
function getFieldMode(key) {
|
|
61
|
+
const lowerKey = key.toLowerCase();
|
|
62
|
+
if (lowerKey.endsWith('url') || lowerKey.endsWith('urls'))
|
|
63
|
+
return null;
|
|
64
|
+
if (lowerKey.includes('images') || lowerKey.includes('videos'))
|
|
65
|
+
return 'plural';
|
|
66
|
+
if (lowerKey.includes('image') || lowerKey.includes('video'))
|
|
67
|
+
return 'single';
|
|
68
|
+
return null;
|
|
69
|
+
}
|
|
70
|
+
function normalizePluralValue(value) {
|
|
71
|
+
if (Array.isArray(value))
|
|
72
|
+
return value.filter((item) => typeof item === 'string' && item.length > 0);
|
|
73
|
+
if (typeof value === 'string' && value.length > 0)
|
|
74
|
+
return value
|
|
75
|
+
.split(',')
|
|
76
|
+
.map((item) => item.trim())
|
|
77
|
+
.filter(Boolean);
|
|
78
|
+
return [];
|
|
79
|
+
}
|
|
80
|
+
function normalizeSingleValue(value) {
|
|
81
|
+
if (typeof value === 'string')
|
|
82
|
+
return value.length > 0 ? value : null;
|
|
83
|
+
return null;
|
|
64
84
|
}
|
|
65
85
|
function collect(node) {
|
|
66
86
|
if (!node)
|
|
@@ -74,49 +94,35 @@ async function setFilesUrls(data) {
|
|
|
74
94
|
if (visited.has(node))
|
|
75
95
|
return;
|
|
76
96
|
visited.add(node);
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
}
|
|
97
|
+
Object.entries(node).forEach(([key, value]) => {
|
|
98
|
+
const mode = getFieldMode(key);
|
|
99
|
+
if (mode === 'plural') {
|
|
100
|
+
targets.push({ node, key, mode });
|
|
101
|
+
}
|
|
102
|
+
else if (mode === 'single' && typeof value === 'string') {
|
|
103
|
+
targets.push({ node, key, mode });
|
|
85
104
|
}
|
|
86
105
|
collect(value);
|
|
87
|
-
}
|
|
106
|
+
});
|
|
88
107
|
}
|
|
89
108
|
collect(data);
|
|
90
|
-
|
|
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
|
-
if (!Array.isArray(arr))
|
|
99
|
-
return;
|
|
100
|
-
arr.forEach((v) => {
|
|
101
|
-
if (typeof v === 'string' && v.length)
|
|
102
|
-
filesSet.add(v);
|
|
103
|
-
});
|
|
104
|
-
});
|
|
105
|
-
const files = Array.from(filesSet);
|
|
106
|
-
if (!files.length) {
|
|
107
|
-
arrayTargets.forEach(({ node, key }) => (node[`${key}Urls`] = []));
|
|
108
|
-
singleTargets.forEach(({ node, key }) => (node[`${key}Url`] = null));
|
|
109
|
+
if (!targets.length)
|
|
109
110
|
return;
|
|
110
|
-
|
|
111
|
-
|
|
111
|
+
const allFiles = Array.from(new Set(targets.flatMap((target) => target.mode === 'plural'
|
|
112
|
+
? normalizePluralValue(target.node[target.key])
|
|
113
|
+
: normalizeSingleValue(target.node[target.key]) || [])));
|
|
112
114
|
const map = new Map();
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
115
|
+
if (allFiles.length) {
|
|
116
|
+
const urls = await Promise.all(allFiles.map((file) => helpers_1.FileStorage.GenerateDownloadUrl(file)));
|
|
117
|
+
allFiles.forEach((file, i) => map.set(file, urls[i]));
|
|
118
|
+
}
|
|
119
|
+
targets.forEach((target) => {
|
|
120
|
+
if (target.mode === 'plural') {
|
|
121
|
+
const files = normalizePluralValue(target.node[target.key]);
|
|
122
|
+
target.node[`${target.key}Urls`] = files.map((file) => map.get(file) || null);
|
|
123
|
+
return;
|
|
124
|
+
}
|
|
125
|
+
const file = normalizeSingleValue(target.node[target.key]);
|
|
126
|
+
target.node[`${target.key}Url`] = file ? map.get(file) || null : null;
|
|
121
127
|
});
|
|
122
128
|
}
|