pangea-server 3.3.70 → 3.3.71
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 +40 -11
- package/package.json +1 -1
|
@@ -41,7 +41,7 @@ function callController(controller, validate, appVersion, authConfig) {
|
|
|
41
41
|
data = result.instances;
|
|
42
42
|
totalCount = result.totalCount;
|
|
43
43
|
}
|
|
44
|
-
await
|
|
44
|
+
await setFilesUrls(data);
|
|
45
45
|
const jsonBody = {
|
|
46
46
|
data: data || null,
|
|
47
47
|
totalCount: typeof totalCount === 'number' ? totalCount : null,
|
|
@@ -54,8 +54,10 @@ function callController(controller, validate, appVersion, authConfig) {
|
|
|
54
54
|
function hasInstancesAndTotalCount(obj) {
|
|
55
55
|
return typeof obj === 'object' && obj !== null && 'instances' in obj && 'totalCount' in obj;
|
|
56
56
|
}
|
|
57
|
-
async function
|
|
58
|
-
const
|
|
57
|
+
async function setFilesUrls(data) {
|
|
58
|
+
const singularSuffixes = ['Image', 'Video'];
|
|
59
|
+
const pluralSuffixes = ['Images', 'Videos'];
|
|
60
|
+
const entries = [];
|
|
59
61
|
const visited = new WeakSet();
|
|
60
62
|
function collect(node) {
|
|
61
63
|
if (!node)
|
|
@@ -69,16 +71,43 @@ async function setImageUrls(data) {
|
|
|
69
71
|
if (visited.has(node))
|
|
70
72
|
return;
|
|
71
73
|
visited.add(node);
|
|
72
|
-
|
|
73
|
-
|
|
74
|
+
for (const [key, value] of Object.entries(node)) {
|
|
75
|
+
if (typeof value === 'string' && value.length) {
|
|
76
|
+
if (singularSuffixes.some((s) => key === s.toLowerCase() || (key.length > s.length && key.endsWith(s)))) {
|
|
77
|
+
entries.push({ node, field: key, type: 'singular' });
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
else if (Array.isArray(value) && value.length && value.every((v) => typeof v === 'string')) {
|
|
81
|
+
if (pluralSuffixes.some((s) => key === s.toLowerCase() || (key.length > s.length && key.endsWith(s)))) {
|
|
82
|
+
entries.push({ node, field: key, type: 'plural' });
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
74
86
|
Object.values(node).forEach(collect);
|
|
75
87
|
}
|
|
76
88
|
collect(data);
|
|
77
|
-
if (!
|
|
89
|
+
if (!entries.length)
|
|
78
90
|
return;
|
|
79
|
-
const
|
|
80
|
-
const
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
91
|
+
const allFileKeys = new Set();
|
|
92
|
+
for (const { node, field, type } of entries) {
|
|
93
|
+
if (type === 'singular') {
|
|
94
|
+
allFileKeys.add(node[field]);
|
|
95
|
+
}
|
|
96
|
+
else {
|
|
97
|
+
for (const v of node[field])
|
|
98
|
+
allFileKeys.add(v);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
const uniqueKeys = Array.from(allFileKeys);
|
|
102
|
+
const urls = await Promise.all(uniqueKeys.map((key) => helpers_1.FileStorage.GenerateDownloadUrl(key)));
|
|
103
|
+
const urlMap = new Map();
|
|
104
|
+
uniqueKeys.forEach((key, i) => urlMap.set(key, urls[i]));
|
|
105
|
+
for (const { node, field, type } of entries) {
|
|
106
|
+
if (type === 'singular') {
|
|
107
|
+
node[`${field}Url`] = urlMap.get(node[field]);
|
|
108
|
+
}
|
|
109
|
+
else {
|
|
110
|
+
node[`${field}Urls`] = node[field].map((v) => urlMap.get(v));
|
|
111
|
+
}
|
|
112
|
+
}
|
|
84
113
|
}
|