Fix state mutation of doc.screenshots in server.js
All checks were successful
continuous-integration/drone Build is passing

This commit is contained in:
Léo Carpentier 2022-02-16 13:56:41 +02:00
parent a951f16494
commit 066474190d

View File

@ -11,7 +11,7 @@ const mongoUri = process.env.MONGO_URI || 'mongodb://127.0.0.1:27017/default?rep
const minioURI = new URL(process.env.MINIO_URI || 'http://kspace-mugshot:2mSI6HdbJ8@127.0.0.1:9000/kspace-mugshot'); const minioURI = new URL(process.env.MINIO_URI || 'http://kspace-mugshot:2mSI6HdbJ8@127.0.0.1:9000/kspace-mugshot');
const minioBucket = minioURI.pathname.substring(1); const minioBucket = minioURI.pathname.substring(1);
console.info("Using bucket:", minioBucket); console.info("Using bucket:", minioBucket);
const historyNumber = parseInt(process.env.HISTORY_AMOUNT) || 10; const historyNumber = parseInt(process.env.HISTORY_AMOUNT) || 1000;
// Stream set-up variables // Stream set-up variables
let changeStream; let changeStream;
@ -46,14 +46,15 @@ async function run() {
}); });
async function wrapEvent(doc) { async function wrapEvent(doc) {
let newDoc;
if (doc && doc.screenshot_count) { if (doc && doc.screenshot_count) {
doc.screenshots = []; newDoc = {...doc, screenshots: []}
for (let i = 1; i <= doc.screenshot_count ; i++) { for (let i = 1; i <= doc.screenshot_count ; i++) {
let presignedUrl = await minioClient.presignedUrl('GET', minioBucket, `${doc.camera}/${doc._id}/${i}.jpg`, 60 * 60); let presignedUrl = await minioClient.presignedUrl('GET', minioBucket, `${doc.camera}/${doc._id}/${i}.jpg`, 60 * 60);
doc.screenshots.push({ url: presignedUrl }); newDoc.screenshots.push({ url: presignedUrl });
} }
}; };
let blob = JSON.stringify(doc); let blob = JSON.stringify(newDoc);
return `event: log-entry\ndata: ${blob}\n\n` return `event: log-entry\ndata: ${blob}\n\n`
} }