Commit 0221ad74 authored by Oleg Dzhimiev's avatar Oleg Dzhimiev

1. fixed for chrome for images bigger than 2MB (dumped readAsDataURL()) 2. for...

1. fixed for chrome for images bigger than 2MB (dumped readAsDataURL()) 2. for synced - restore trigger only after images are downloaded
parent a2f1896a
var tp_old = 0; var tp_old = 0;
var DLC = 0;
function take_snapshot(){ function take_snapshot(){
...@@ -32,33 +33,26 @@ function trigger(){ ...@@ -32,33 +33,26 @@ function trigger(){
$.ajax({ $.ajax({
url:href+"?trig", url:href+"?trig",
success:function(){ success:function(){
setTimeout(function(){ setTimeout(function(){
download_all(true); download_all(true);
},200); },200);
} }
}); });
} }
function download_all(rtp){ function download_all(rtp){
DLC = 0;
ports.forEach(function(c,i){ ports.forEach(function(c,i){
download_single(ip+":"+c+"/img"); download_single(ip+":"+c+"/timestamp_name/img");
}); });
if (rtp) {
setTimeout(function(){
read_tp();
},200);
}else{
$("#snapshot").attr("disabled",false);
}
} }
function download_single(addr){ function download_single(addr){
// get ze blob // get ze blob
var http = new XMLHttpRequest(); var http = new XMLHttpRequest();
http.open("GET", addr, true); http.open("GET", addr, true);
...@@ -66,41 +60,36 @@ function download_single(addr){ ...@@ -66,41 +60,36 @@ function download_single(addr){
http.onload = function(e){ http.onload = function(e){
if (this.status === 200) { if (this.status === 200) {
// To access the header, had to add
// To access the header, had to add
// printf("Access-Control-Expose-Headers: Content-Disposition\r\n"); // printf("Access-Control-Expose-Headers: Content-Disposition\r\n");
// to imgsrv // to imgsrv
var filename = this.getResponseHeader("Content-Disposition"); var filename = this.getResponseHeader("Content-Disposition");
pass_to_file_reader(filename,http.response); pass_to_file_reader(filename,http.response);
DLC++;
if (DLC==ports.length){
if ($("#synced").prop("checked")) {
read_tp();
}else{
$("#snapshot").attr("disabled",false);
}
}
} }
} }
http.send(); http.send();
/*
return 0;
var link = document.createElement('a');
link.setAttribute('download', null);
link.style.display = 'none';
link.download = addr;
link.href = addr;
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
*/
} }
// from here: // from here:
// https://diegolamonica.info/multiple-files-download-on-single-link-click/ // https://diegolamonica.info/multiple-files-download-on-single-link-click/
// http://jsfiddle.net/diegolamonica/ssk8z9pa/ // http://jsfiddle.net/diegolamonica/ssk8z9pa/
function pass_to_file_reader(filename,filedata){ // (helped a lot) https://stackoverflow.com/questions/19327749/javascript-blob-filename-without-link
function pass_to_file_reader(filename,fileblob){
var parameters = filename.split(";"); var parameters = filename.split(";");
for (var i=0;i<parameters.length;i++) parameters[i]=parameters[i].split("="); for (var i=0;i<parameters.length;i++) parameters[i]=parameters[i].split("=");
...@@ -110,33 +99,67 @@ function pass_to_file_reader(filename,filedata){ ...@@ -110,33 +99,67 @@ function pass_to_file_reader(filename,filedata){
filename = filename.trim(); filename = filename.trim();
} }
} }
var url = window.URL.createObjectURL(fileblob);
var a = $('<a>')
.attr('href', url)
.attr('download',filename)
// Firefox does not fire click if the link is outside
// the DOM
.appendTo('body');
a[0].click();
//a.click();
// delay?
setTimeout(function(){
a.remove();
},200);
//return;
// The code below will not work because .readAsDataURL() is limited in Chrome to 2MB, but no limit in FF.
/*
var reader = new FileReader(); var reader = new FileReader();
reader.filename = filename; reader.filename = filename;
reader.onloadend = function(e){ reader.onloadend = function(e){
//console.log("Load ended!");
var file = [this.filename,e.target.result]; var file = [this.filename,e.target.result];
var theAnchor = $('<a />') var theAnchor = $('<a>')
.attr('href', file[1]) .attr('href', file[1])
.attr('download',file[0]) .attr('download',file[0])
// Firefox does not fires click if the link is outside // Firefox does not fire click if the link is outside
// the DOM // the DOM
.appendTo('body'); .appendTo('body');
theAnchor[0].click(); theAnchor[0].click();
//theAnchor.click(); //theAnchor.click();
theAnchor.remove();
//delay
setTimeout(function(){
theAnchor.remove();
},200);
}; };
reader.onload = function(e){
//console.log("onload");
};
reader.readAsDataURL(filedata); reader.readAsDataURL(filedata);
*/
} }
function read_tp(){ function read_tp(){
var param = "TRIG_PERIOD"; var param = "TRIG_PERIOD";
$.ajax({ $.ajax({
url: ip+"/parsedit.php?immediate&"+param, url: ip+"/parsedit.php?immediate&"+param,
...@@ -148,22 +171,22 @@ function read_tp(){ ...@@ -148,22 +171,22 @@ function read_tp(){
} }
function restore_trig_period(){ function restore_trig_period(){
$.ajax({ $.ajax({
url: ip+"/parsedit.php?immediate&TRIG_PERIOD="+(tp_old)+"*-2&sensor_port="+trig_master, url: ip+"/parsedit.php?immediate&TRIG_PERIOD="+(tp_old)+"*-2&sensor_port="+trig_master,
success: function(){ success: function(){
console.log("Done"); console.log("Done");
$("#snapshot").attr("disabled",false); $("#snapshot").attr("disabled",false);
} }
}); });
} }
function toggle_help(){ function toggle_help(){
$("#help").toggle(); $("#help").toggle();
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment