diff --git a/libs/database/migrate/2023-07-10.js b/libs/database/migrate/2023-07-10.js index 3f94f0bd..00621b51 100644 --- a/libs/database/migrate/2023-07-10.js +++ b/libs/database/migrate/2023-07-10.js @@ -17,4 +17,7 @@ module.exports = async function(s,config){ {name: 'time', type: 'timestamp', defaultTo: currentTimestamp()}, {name: 'incidentTime', type: 'timestamp', defaultTo: currentTimestamp()}, ]); + await addColumn('Files',[ + {name: 'type', length: 20, type: 'string'}, + ]); } diff --git a/libs/database/preQueries.js b/libs/database/preQueries.js index 2210da61..4eb5fec6 100644 --- a/libs/database/preQueries.js +++ b/libs/database/preQueries.js @@ -51,6 +51,7 @@ module.exports = function(s,config){ {name: 'status', type: 'integer', length: 1, defaultTo: 0}, {name: 'archive', type: 'tinyint', length: 1, defaultTo: 0}, {name: 'time', type: 'timestamp', defaultTo: currentTimestamp()}, + {name: 'type', length: 20, type: 'string'}, ]); await createTable('Videos',[ isMySQL ? {name: 'utf8', type: 'charset'} : null, diff --git a/libs/report.js b/libs/report.js index 13f2ec0c..bc2931df 100644 --- a/libs/report.js +++ b/libs/report.js @@ -1,3 +1,4 @@ +const fs = require('fs').promises module.exports = function(s,config,lang){ const { getPartsFromPath, @@ -41,6 +42,33 @@ module.exports = function(s,config,lang){ return newReportId } } + async function moveZipToFileBin({ + ke, + mid, + zipName, + newReportId, + currentTime, + outputZipPath, + moveZipToPath, + }){ + await copyFile(outputZipPath, moveZipToPath) + await fs.rm(outputZipPath) + const fileStats = await fs.stat(moveZipToPath) + const fileBinInsertQuery = { + ke, + mid, + name: zipName, + size: fileStats.size, + details: JSON.stringify({ + reportId: newReportId + }), + archive: 1, + status: 1, + time: currentTime, + type: 'report' + } + await s.insertFileBinEntry(fileBinInsertQuery) + } async function saveReport(options){ const { ke, @@ -58,14 +86,23 @@ module.exports = function(s,config,lang){ // save files to zip const zipName = `Report-${currentTime.getTime()}` const tempDirectory = `${getStreamDirectory({ke, mid})}${zipName}` + const moveZipToDirectory = `${s.getFileBinDirectory({ke, mid})}${zipName}` if(snapPaths)await copyFilesToReportFolder('images', tempDirectory,snapPaths); if(videoPaths)await copyFilesToReportFolder('videos', tempDirectory,videoPaths); if(fileBinPaths)await copyFilesToReportFolder('fileBin', tempDirectory,fileBinPaths); - // finish zip move!!!!!! const outputZipPath = `${tempDirectory}.zip` - const moveZipToPath = `${tempDirectory}.zip` + const moveZipToPath = `${moveZipToDirectory}.zip` await zipFolder(tempDirectory,outputZipPath) - await copyFile(outputZipPath, moveZipToPath) + await fs.rm(tempDirectory, { recursive: true }) + await moveZipToFileBin({ + ke, + mid, + zipName, + newReportId, + currentTime, + outputZipPath, + moveZipToPath, + }) // put added information about video // - length of videos // - format of videos