pangea-server 3.3.65 → 3.3.66
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.
|
@@ -46,6 +46,7 @@ function callController(controller, validate, appVersion, authConfig) {
|
|
|
46
46
|
data = result.instances;
|
|
47
47
|
totalCount = result.totalCount;
|
|
48
48
|
}
|
|
49
|
+
await setImageUrls(data);
|
|
49
50
|
const jsonBody = {
|
|
50
51
|
data: data || null,
|
|
51
52
|
totalCount: typeof totalCount === 'number' ? totalCount : null,
|
|
@@ -59,3 +60,27 @@ function callController(controller, validate, appVersion, authConfig) {
|
|
|
59
60
|
function hasInstancesAndTotalCount(obj) {
|
|
60
61
|
return typeof obj === 'object' && obj !== null && 'instances' in obj && 'totalCount' in obj;
|
|
61
62
|
}
|
|
63
|
+
async function setImageUrls(data) {
|
|
64
|
+
const targets = [];
|
|
65
|
+
function collect(node) {
|
|
66
|
+
if (!node)
|
|
67
|
+
return;
|
|
68
|
+
if (Array.isArray(node)) {
|
|
69
|
+
node.forEach(collect);
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
if (typeof node !== 'object')
|
|
73
|
+
return;
|
|
74
|
+
if (typeof node.image === 'string' && node.image.length)
|
|
75
|
+
targets.push(node);
|
|
76
|
+
Object.values(node).forEach(collect);
|
|
77
|
+
}
|
|
78
|
+
collect(data);
|
|
79
|
+
if (!targets.length)
|
|
80
|
+
return;
|
|
81
|
+
const uniqueImages = Array.from(new Set(targets.map((target) => target.image)));
|
|
82
|
+
const urls = await Promise.all(uniqueImages.map((image) => helpers_1.FileStorage.GenerateDownloadUrl(image)));
|
|
83
|
+
const map = new Map();
|
|
84
|
+
uniqueImages.forEach((image, i) => map.set(image, urls[i]));
|
|
85
|
+
targets.forEach((target) => (target.imageUrl = map.get(target.image)));
|
|
86
|
+
}
|