Skip to content

Commit 1471719

Browse files
committed
Merge pull request #69 from victordiaz/master
download binary from repo is OK
2 parents e21345d + 0595e44 commit 1471719

2 files changed

Lines changed: 43 additions & 41 deletions

File tree

nw-miniblip/javascript/main.js

Lines changed: 38 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
// TODO
22
// OK - GET REMOTE JSON
3-
// DOWNLOAD FILE ON ITEM CLICK
3+
// OK - DOWNLOAD FILE ON ITEM CLICK
44
// CHECK BOARD STATUS
55
// UPLOAD FIRMWARE
66
//
77
var fs = require("fs");
88
var https = require('https');
99
var md5 = require('md5');
10+
var httpreq = require('httpreq');
1011

1112

1213
function detect_board() {
@@ -92,6 +93,8 @@ console.log(file_url);
9293
$("#firmware-list #list").append($item)
9394

9495
$item.click(function() {
96+
$(".item").removeClass("selected");
97+
$(this).addClass("selected");
9598
var $div = $("#firmware-upload-section #action");
9699

97100
$div.fadeOut("500", function() {
@@ -103,9 +106,10 @@ console.log(file_url);
103106
});
104107

105108
$div.find("#upload").click(function() {
109+
106110
if (isRemote) {
107111
download_firmware(obj, function() {
108-
//upload_firmware(file_url, "/dev/sdb");
112+
upload_firmware(file_url, "/dev/sdb");
109113
});
110114
} else {
111115
upload_firmware(file_url, "/dev/sdb");
@@ -129,41 +133,34 @@ function get_list_firmwares_local() {
129133
}
130134

131135

132-
//TODO check md5
133136
function download_firmware(obj, callback) {
134137
if (!fs.existsSync("./tmp")){
135138
fs.mkdirSync("./tmp");
136139
}
137140

138-
var url = get_remote_firmware_url(obj.name);
139-
var path = process.cwd() + "/tmp/" + obj.name+".bin";
140-
console.log("saving from: "+ url);
141-
console.log("saving to " + path );
142-
143-
var file = fs.createWriteStream(path);
144-
145-
var request = https.get(url, function(response) {
146-
console.log(response);
147-
response.pipe(file);
148-
149-
file.on('finish', function(d) {
150-
//check md5
151-
var md5result;
152-
fs.readFile(path, function(err, buf) {
141+
var from = get_remote_firmware_url(obj.name);
142+
var to = process.cwd() + "/tmp/" + obj.name+".bin";
143+
//console.log("saving from: "+ from);
144+
//console.log("saving to " + to );
145+
146+
httpreq.download(from, to
147+
, function (err, progress){
148+
if (err) return console.log(err);
149+
//console.log("downloading from " + progress);
150+
}, function (err, res){
151+
if (err) return console.log(err);
152+
//console.log(res);
153+
var md5result;
154+
fs.readFile(to, function(err, buf) {
153155
if (md5(buf) == obj.md5) {
154-
console.log("ok");
156+
//console.log("md5 ok");
155157
md5result = true;
156158
} else {
157-
console.log("nop");
159+
//console.log("md5 nop");
158160
md5result = false;
159161
}
160162
callback(md5result);
161-
}); //readfile
162-
});//fileonfinish
163-
164-
}).on('error', function(e) {
165-
fs.unlink(dest);
166-
console.log(e);
163+
}); //readfile
167164
});
168165
}
169166

@@ -218,22 +215,22 @@ function show_section() {
218215

219216
}
220217

221-
//interval of given delat, will execute callback with [true] or [false] as param
218+
//interval of given delay, will execute callback with [true] or [false] as param
222219
function check_serial_connected(delay, callback) {
223220
setInterval(function(){
224-
var cmd = "ls /dev/ttyACM*";
225-
try {
226-
var res = require('child_process').execSync(cmd, {
227-
stdio: "pipe",
228-
stderr: "pipe"
229-
}).toString();
230-
231-
if (!res || res.length === 0 || res === undefined) res = false;
232-
else res = true;
233-
}
234-
catch (err){
235-
res = false;
236-
}
237-
callback(res);
221+
var cmd = "ls /dev/ttyACM*";
222+
try {
223+
var res = require('child_process').execSync(cmd, {
224+
stdio: "pipe",
225+
stderr: "pipe"
226+
}).toString();
227+
228+
if (!res || res.length === 0 || res === undefined) res = false;
229+
else res = true;
230+
}
231+
catch (err){
232+
res = false;
233+
}
234+
callback(res);
238235
},delay);
239236
}

nw-miniblip/styles/main.less

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,11 @@ body {
163163
&:hover {
164164
background: rgba(0, 0, 0, 0.08);
165165
}
166+
167+
&.selected {
168+
background: rgba(0, 0, 0, 0.08);
169+
}
170+
166171
}
167172
}
168173

0 commit comments

Comments
 (0)