|
|
|
@ -11,7 +11,7 @@ const mongoUri = process.env.MONGO_URI || 'mongodb://127.0.0.1:27017/default?rep
@@ -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 minioBucket = minioURI.pathname.substring(1); |
|
|
|
|
console.info("Using bucket:", minioBucket); |
|
|
|
|
const historyNumber = parseInt(process.env.HISTORY_AMOUNT) || 1000; |
|
|
|
|
const historyNumber = parseInt(process.env.HISTORY_AMOUNT) || 10; |
|
|
|
|
|
|
|
|
|
// Stream set-up variables
|
|
|
|
|
let changeStream; |
|
|
|
@ -46,18 +46,32 @@ async function run() {
@@ -46,18 +46,32 @@ async function run() {
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
async function wrapEvent(doc) { |
|
|
|
|
let screenShotArray = []; |
|
|
|
|
let arr = []; |
|
|
|
|
let blob; |
|
|
|
|
if (doc && doc.screenshot_count) { |
|
|
|
|
for (let i = 1; i <= doc.screenshot_count ; i++) { |
|
|
|
|
let presignedUrl = await minioClient.presignedUrl('GET', minioBucket, `${doc.camera}/${doc._id}/${i}.jpg`, 60 * 60); |
|
|
|
|
screenShotArray.push({ url: presignedUrl }); |
|
|
|
|
arr.push({ |
|
|
|
|
url: await minioClient.presignedUrl('GET', minioBucket, |
|
|
|
|
`${doc.camera}/${doc._id}/${i}.jpg`, 60 * 60) |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
} else if (doc && doc.screenshots) { |
|
|
|
|
for (let j = 0; j < doc.screenshots.length; j++) { |
|
|
|
|
let path = doc.screenshots[j]; |
|
|
|
|
arr.push({ |
|
|
|
|
url: await minioClient.presignedUrl('GET', minioBucket, |
|
|
|
|
`thumb/${path}`, 60 * 60), |
|
|
|
|
orig: await minioClient.presignedUrl('GET', minioBucket, |
|
|
|
|
`${path}`, 60 * 60) |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
blob = JSON.stringify({...doc, screenshots: [...screenShotArray]}); |
|
|
|
|
} else { |
|
|
|
|
blob = JSON.stringify({...doc}) |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (arr.length > 0) { |
|
|
|
|
blob = JSON.stringify({...doc, screenshots: [...arr]}); |
|
|
|
|
} else { |
|
|
|
|
blob = JSON.stringify({...doc}); |
|
|
|
|
} |
|
|
|
|
return `event: log-entry\ndata: ${blob}\n\n` |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|