fix reading event base recording for event notify

save-notification-video-clips-to-fileBin
Moe 2025-02-16 19:34:06 -08:00
parent 70d4ca76e0
commit ccbb02a05a
7 changed files with 23 additions and 11 deletions

View File

@ -273,6 +273,13 @@ module.exports = (processCwd,config) => {
console.error(`Error deleting files: ${error.message}`);
}
}
function setTimeoutPromise(theTime){
return new Promise((resolve) => {
setTimeout(() => {
resolve()
},theTime)
})
}
return {
parseJSON: parseJSON,
stringJSON: stringJSON,
@ -297,5 +304,6 @@ module.exports = (processCwd,config) => {
setDefaultIfUndefined,
deleteFilesInFolder,
moveFile,
setTimeoutPromise,
}
}

View File

@ -492,7 +492,7 @@ module.exports = (s,config,lang) => {
}){
const response = { ok: true }
try{
const fileBinFilePath = getFileBinDirectory({ ke: groupKey, mid: monitorId }) + filename;
const fileBinFilePath = s.getFileBinDirectory({ ke: groupKey, mid: monitorId }) + filename;
const copyResponse = await copyFile(filePath,fileBinFilePath)
const fileSize = (await fs.stat(fileBinFilePath)).size
// s.file('delete',filePath)
@ -510,26 +510,30 @@ module.exports = (s,config,lang) => {
response.fileBinPath = fileBinFilePath
}catch(err){
response.ok = false;
console.log(err)
response.err = err.toString();
}
return response;
}
const getEventBasedRecordingUponCompletion = function(options){
const response = {ok: true}
return new Promise((resolve,reject) => {
return new Promise(async (resolve,reject) => {
const groupKey = options.ke
const monitorId = options.mid
const activeMonitor = s.group[groupKey].activeMonitors[monitorId]
if(activeMonitor && activeMonitor.eventBasedRecording && activeMonitor.eventBasedRecording.process){
const eventBasedRecording = activeMonitor.eventBasedRecording
if(!activeMonitor || !activeMonitor.eventBasedRecording){
return resolve(response)
}
const fileTime = options.fileTime || activeMonitor.eventBasedRecordingLastFileTime;
if(activeMonitor.eventBasedRecording[fileTime] && activeMonitor.eventBasedRecording[fileTime].process){
const eventBasedRecording = activeMonitor.eventBasedRecording[fileTime]
const monitorConfig = s.group[groupKey].rawMonitorConfigurations[monitorId]
const videoLength = parseInt(monitorConfig.details.detector_send_video_length) || 10
const recordingDirectory = s.getVideoDirectory(monitorConfig)
const fileTime = eventBasedRecording.lastFileTime
const filename = `${fileTime}.mp4`
response.filename = `${filename}`
response.filePath = `${recordingDirectory}${filename}`
eventBasedRecording.process.on('exit',function(){
eventBasedRecording.process.on('exit', async function(){
setTimeout(async () => {
if(!isNaN(videoLength)){
const cutResponse = await cutVideoLength({

View File

@ -93,7 +93,7 @@ module.exports = function(s,config,lang,getSnapshot){
let videoName = null
const eventBasedRecording = await getEventBasedRecordingUponCompletion({
ke: d.ke,
mid: d.mid
mid: d.mid || d.id
})
if(eventBasedRecording.filePath){
videoPath = eventBasedRecording.filePath

View File

@ -160,7 +160,7 @@ module.exports = function(s,config,lang,getSnapshot){
let videoName = null
const eventBasedRecording = await getEventBasedRecordingUponCompletion({
ke: d.ke,
mid: d.mid
mid: d.mid || d.id
})
if(eventBasedRecording.filePath){
videoPath = eventBasedRecording.filePath

View File

@ -165,7 +165,7 @@ module.exports = function (s, config, lang, getSnapshot) {
let videoName = null
const eventBasedRecording = await getEventBasedRecordingUponCompletion({
ke: d.ke,
mid: d.mid
mid: d.mid || d.id
})
if(eventBasedRecording.filePath){
videoPath = eventBasedRecording.filePath

View File

@ -110,7 +110,7 @@ module.exports = async function(s,config,lang,getSnapshot){
let videoName = null
const eventBasedRecording = await getEventBasedRecordingUponCompletion({
ke: d.ke,
mid: d.mid
mid: d.mid || d.id
})
if(eventBasedRecording.filePath){
videoPath = eventBasedRecording.filePath

View File

@ -132,7 +132,7 @@ module.exports = function(s,config,lang,getSnapshot){
let videoName = null
const eventBasedRecording = await getEventBasedRecordingUponCompletion({
ke: d.ke,
mid: d.mid
mid: d.mid || d.id
})
if(eventBasedRecording.filePath){
videoPath = eventBasedRecording.filePath