pangea-server 3.3.81 → 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 +46 -60
- package/package.json +1 -1
|
@@ -56,19 +56,32 @@ 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;
|
|
64
69
|
}
|
|
65
|
-
function
|
|
70
|
+
function normalizePluralValue(value) {
|
|
66
71
|
if (Array.isArray(value))
|
|
67
|
-
return value;
|
|
68
|
-
if (typeof value === 'string' && value.length)
|
|
69
|
-
return 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);
|
|
70
78
|
return [];
|
|
71
79
|
}
|
|
80
|
+
function normalizeSingleValue(value) {
|
|
81
|
+
if (typeof value === 'string')
|
|
82
|
+
return value.length > 0 ? value : null;
|
|
83
|
+
return null;
|
|
84
|
+
}
|
|
72
85
|
function collect(node) {
|
|
73
86
|
if (!node)
|
|
74
87
|
return;
|
|
@@ -81,62 +94,35 @@ async function setFilesUrls(data) {
|
|
|
81
94
|
if (visited.has(node))
|
|
82
95
|
return;
|
|
83
96
|
visited.add(node);
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
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
|
-
}
|
|
104
|
-
}
|
|
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 });
|
|
105
104
|
}
|
|
106
105
|
collect(value);
|
|
107
|
-
}
|
|
106
|
+
});
|
|
108
107
|
}
|
|
109
108
|
collect(data);
|
|
110
|
-
|
|
111
|
-
singleTargets.forEach(({ node, key }) => {
|
|
112
|
-
const val = node[key];
|
|
113
|
-
if (typeof val === 'string' && val.length)
|
|
114
|
-
filesSet.add(val);
|
|
115
|
-
});
|
|
116
|
-
arrayTargets.forEach(({ node, key }) => {
|
|
117
|
-
const arr = node[key];
|
|
118
|
-
if (!Array.isArray(arr))
|
|
119
|
-
return;
|
|
120
|
-
arr.forEach((v) => {
|
|
121
|
-
if (typeof v === 'string' && v.length)
|
|
122
|
-
filesSet.add(v);
|
|
123
|
-
});
|
|
124
|
-
});
|
|
125
|
-
const files = Array.from(filesSet);
|
|
126
|
-
if (!files.length) {
|
|
127
|
-
arrayTargets.forEach(({ node, key }) => (node[`${key}Urls`] = []));
|
|
128
|
-
singleTargets.forEach(({ node, key }) => (node[`${key}Url`] = null));
|
|
109
|
+
if (!targets.length)
|
|
129
110
|
return;
|
|
130
|
-
|
|
131
|
-
|
|
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]) || [])));
|
|
132
114
|
const map = new Map();
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
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;
|
|
141
127
|
});
|
|
142
128
|
}
|