clear "over max" timelapse frames

merge-requests/61/head
Moe 2019-04-26 11:10:53 -07:00
parent 8cbd2281cd
commit a1f33195ee
10 changed files with 109 additions and 15 deletions

View File

@ -48,7 +48,7 @@ loadLib('ffmpeg')(s,config,lang,function(ffmpeg){
//websocket connection handlers : login and streams..
loadLib('socketio')(s,config,lang,io)
//user and group functions
loadLib('user')(s,config)
loadLib('user')(s,config,lang)
//monitor/camera handlers
loadLib('monitor')(s,config,lang)
//event functions : motion, object matrix handler

View File

@ -17,6 +17,8 @@
"Password": "Password",
"Password Again": "Password Again",
"Remember Me": "Remember Me",
"Process Already Running": "Process Already Running",
"Process Not Running": "Process Not Running",
"RAM": "RAM",
"CPU": "CPU",
"on": "on",
@ -234,6 +236,7 @@
"Database": "Database",
"Database Not Found": "Database Not Found",
"User Not Found": "User Not Found",
"Not Found": "Not Found",
"Save Links to Database": "Save Links to Database",
"Uploaders": "Uploaders",
"Upload File": "Upload File",
@ -864,7 +867,10 @@
"Confidence":"Confidence",
"Trainer Engine":"Trainer Engine",
"Train":"Train",
"TrainConfirm":"Are you sure you want to begin training? This can take more than 12 hours with over 500 images. This will consume a large amount of resources, like RAM or CPU.",
"openImagesDownloadConfirm":"Are you sure you want to begin download images and bounding boxes (preset Matrices) from OpenImages?",
"openImagesDownloadConfirmStop":"Are you sure you want to stop training?",
"TrainConfirm":"Are you sure you want to begin training? This can take more than 12 hours with over 500 images. This will consume a large amount of resources, like RAM and/or CPU.",
"TrainConfirmStop":"Are you sure you want to stop training?",
"Batch":"Batch",
"Subdivision":"Subdivision",
"Map":"Map",

View File

@ -925,6 +925,7 @@ module.exports = function(s,config,lang){
var timeNow = new Date()
s.sqlQuery('INSERT INTO `Timelapse Frames` (ke,mid,details,filename,size,time) VALUES (?,?,?,?,?,?)',[e.ke,e.id,s.s(details),filename,fileStats.size,timeNow])
s.setDiskUsedForGroup(e,fileStats.size / 1000000)
s.purgeDiskForGroup(e)
})
s.group[e.ke].mon[e.id].recordTimelapseWriter = fileStream
}

View File

@ -923,6 +923,7 @@ module.exports = function(s,config,lang,io){
var tempSessionKey = s.gid(30)
cn.superSessionKey = tempSessionKey
s.superUsersApi[tempSessionKey] = data
s.superUsersApi[tempSessionKey].cnid = cn.id
if(!data.$user.tokens)data.$user.tokens = {}
data.$user.tokens[tempSessionKey] = {}
cn.ip=cn.request.connection.remoteAddress

View File

@ -79,27 +79,27 @@ module.exports = function(s,config,lang,io){
s.sqlQuery('SELECT * FROM Videos WHERE ke=? AND status!=?',[user.ke,0],function(err,videos){
s.sqlQuery('SELECT * FROM `Timelapse Frames` WHERE ke=?',[user.ke],function(err,timelapseFrames){
s.sqlQuery('SELECT * FROM `Files` WHERE ke=?',[user.ke],function(err,files){
var usedSpace = 0
if(videos && videos[0]){
videos.forEach(function(video){
video.details = s.parseJSON(video.details)
if(!video.details.dir){
s.group[user.ke].usedSpace += video.size
usedSpace += video.size
}
})
s.group[user.ke].usedSpace = s.group[user.ke].usedSpace / 1000000
}
if(timelapseFrames && timelapseFrames[0]){
timelapseFrames.forEach(function(frame){
user.size += frame.size
usedSpace += frame.size
})
}
if(files && files[0]){
files.forEach(function(file){
user.size += file.size
usedSpace += file.size
})
}
s.group[user.ke].usedSpace = usedSpace / 1000000
loadAddStorageDiskUseForUser(user,videos,function(){
s.systemLog(user.mail+' : '+lang.startUpText1+' : '+videos.length,user.size)
callback()
})
})
@ -110,7 +110,7 @@ module.exports = function(s,config,lang,io){
var userDetails = JSON.parse(user.details)
user.cloudDiskUse = {}
user.size = 0
s.group[user.ke].sizeLimit = userDetails.size
user.limit = userDetails.size
s.cloudDisksLoaded.forEach(function(storageType){
user.cloudDiskUse[storageType] = {
usedSpace : 0,

View File

@ -76,9 +76,61 @@ module.exports = function(s,config){
if(callback)callback()
}
}
var deleteSetOfTimelapseFrames = function(err,frames,storageIndex,callback){
var framesToDelete = []
var queryValues = [e.ke]
var completedCheck = 0
if(frames){
frames.forEach(function(frame){
var selectedDate = frame.filename.split('T')[0]
var fileLocationMid = `${frame.ke}/${frame.mid}_timelapse/${selectedDate}/` + frame.filename
framesToDelete.push('(mid=? AND `time`=?)')
queryValues.push(frame.mid)
queryValues.push(frame.time)
fs.unlink(fileLocationMid,function(err){
++completedCheck
if(err){
fs.stat(fileLocationMid,function(err){
if(!err){
s.file('delete',fileLocationMid)
}
})
}
if(framesToDelete.length === completedCheck){
framesToDelete = framesToDelete.join(' OR ')
s.sqlQuery('DELETE FROM `Timelapse Frames` WHERE ke =? AND ('+framesToDelete+')',queryValues,function(){
reRunCheck()
})
}
})
if(storageIndex){
s.setDiskUsedForGroupAddStorage(e,{
size: -(frame.size/1000000),
storageIndex: storageIndex
})
}else{
s.setDiskUsedForGroup(e,-(frame.size/1000000))
}
// s.tx({
// f: 'timelapse_frame_delete',
// ff: 'over_max',
// filename: s.formattedTime(video.time)+'.'+video.ext,
// mid: video.mid,
// ke: video.ke,
// time: video.time,
// end: s.formattedTime(new Date,'YYYY-MM-DD HH:mm:ss')
// },'GRP_'+e.ke)
})
}else{
console.log(err)
}
if(framesToDelete.length === 0){
if(callback)callback()
}
}
var deleteMainVideos = function(callback){
reRunCheck = function(){
return deleteMainVideos(callback)
callback()
}
//run purge command
if(s.group[e.ke].usedSpace > (s.group[e.ke].sizeLimit * config.cron.deleteOverMaxOffset)){
@ -121,11 +173,33 @@ module.exports = function(s,config){
}
readStorageArray()
}
deleteMainVideos(function(){
deleteAddStorageVideos(function(){
finish()
var deleteTimelapseFrames = function(callback){
reRunCheck = function(){
callback()
}
//run purge command
if(s.group[e.ke].usedSpace > (s.group[e.ke].sizeLimit * config.cron.deleteOverMaxOffset)){
s.sqlQuery('SELECT * FROM `Timelapse Frames` WHERE ke=? AND details NOT LIKE \'%"archived":"1"%\' ORDER BY `time` ASC LIMIT 3',[e.ke],function(err,frames){
deleteSetOfTimelapseFrames(err,frames,null,callback)
})
}else{
callback()
}
}
var doAllChecks = function(){
deleteMainVideos(function(){
deleteTimelapseFrames(function(){
if(s.group[e.ke].usedSpace > (s.group[e.ke].sizeLimit * config.cron.deleteOverMaxOffset)){
doAllChecks()
}else{
deleteAddStorageVideos(function(){
finish()
})
}
})
})
})
}
doAllChecks()
}
checkQueue()
}
@ -193,7 +267,7 @@ module.exports = function(s,config){
if(!s.group[e.ke].addStorageUse){s.group[e.ke].addStorageUse = {}}
if(!e.limit||e.limit===''){e.limit=10000}else{e.limit=parseFloat(e.limit)}
//save global space limit for group key (mb)
s.group[e.ke].sizeLimit = s.group[e.ke].sizeLimit || e.limit
s.group[e.ke].sizeLimit = s.group[e.ke].sizeLimit || e.limit || 10000
//save global used space as megabyte value
s.group[e.ke].usedSpace = s.group[e.ke].usedSpace || ((e.size || 0) / 1000000)
//emit the changes to connected users

View File

@ -16,6 +16,15 @@ module.exports = function(s,config,lang){
return s.dir.videos+e.ke+'/'+e.id+'/';
}
}
s.getTimelapseFrameDirectory = function(e){
if(e.mid&&!e.id){e.id=e.mid};
s.checkDetails(e)
if(e.details&&e.details.dir&&e.details.dir!==''){
return s.checkCorrectPathEnding(e.details.dir)+e.ke+'/'+e.id+'/'
}else{
return s.dir.videos+e.ke+'/'+e.id+'/';
}
}
/**
* Creates available API based URLs for streaming
* @constructor

View File

@ -113,7 +113,7 @@ img{max-width:100%}
}
@media (min-width: 768px){
.modal.full,.modal.medium{padding-left:0!important;}
.modal.full .modal-dialog{width:calc(100% - 10px)!important;margin: 30px auto;}
.modal.full .modal-dialog{width:calc(100% - 10px)!important;margin: 30px auto;max-width: none;}
.modal.medium .modal-dialog{width:calc(70% - 10px)!important;margin: 30px auto;}
.full.modal .modal-body,.medium.modal .modal-body{height:calc(100% - 200px);overflow:auto}
}

View File

@ -4,3 +4,4 @@
.dark.modal .modal-body{background:#333;}
.dark.modal .close{color:#fff;}
.dark.modal{color:#fff;}
#confirm_window {z-index: 11111}

View File

@ -16,9 +16,11 @@
<link rel="stylesheet" href="<%-window.libURL%>libs/css/pnotify.custom.min.css">
<link rel="stylesheet" href="<%-window.libURL%>libs/css/now-ui-kit.css?v=1.1.0" />
<link rel="stylesheet" href="<%-window.libURL%>libs/css/dash2.basic.css">
<link rel="stylesheet" href="<%-window.libURL%>libs/css/dash2.modal.css">
<link rel="stylesheet" href="<%-window.libURL%>libs/css/dash2.forms.css">
<link rel="stylesheet" href="<%-window.libURL%>libs/css/super-page.css" />
<script src="<%-window.libURL%>libs/js/jquery.min.js"></script>
<script src="<%-window.libURL%>libs/js/jquery-ui.min.js"></script>
<script src="<%-window.libURL%>libs/js/basic.js"></script>
<script src="<%-window.libURL%>libs/js/jquery.serialize.js"></script>
<script src="<%-window.libURL%>libs/js/pnotify.custom.min.js"></script>