1
0
Fork 0

Fix apploader node.js app issues - invalid length when uploading (base64 encode issues) and path (when run from directory other than the root)

master
Gordon Williams 2020-06-09 09:23:55 +01:00
parent 4a5abd1cfd
commit 99dcd7868c
2 changed files with 10 additions and 4 deletions

View File

@ -78,8 +78,12 @@ function cmdListDevices() {
});
noble.startScanning([], true);
setTimeout(function() {
console.log("Stopping scan");
noble.stopScanning();
}, 2000);
setTimeout(function() {
process.exit(0);
}, 500);
}, 4000);
}
function cmdInstallApp(appId, deviceAddress) {
@ -88,7 +92,8 @@ function cmdInstallApp(appId, deviceAddress) {
if (app.custom) ERROR(`App ${JSON.stringify(appId)} requires HTML customisation`);
return AppInfo.getFiles(app, {
fileGetter:function(url) {
return Promise.resolve(require("fs").readFileSync(url).toString());
console.log(__dirname+"/"+url);
return Promise.resolve(require("fs").readFileSync(__dirname+"/../"+url).toString());
}, settings : SETTINGS}).then(files => {
//console.log(files);
var command = files.map(f=>f.cmd).join("\n")+"\n";
@ -101,6 +106,7 @@ function bangleSend(command, deviceAddress) {
var args = [].slice.call(arguments);
console.log("UART: "+args.join(" "));
}
//console.log("Sending",JSON.stringify(command));
var RESET = true;
var DEVICEADDRESS = "";

View File

@ -1,8 +1,8 @@
if (typeof btoa==="undefined") {
// Don't define btoa as a function here because Apple's
// iOS browser defines the function even though it's in
// an IF statement that is never executed!
btoa = function(d) { return Buffer.from(d).toString('base64'); }
// an IF statement that is never executed
btoa = function(d) { return Buffer.from(d,'binary').toString('base64'); }
}
// Converts a string into most efficient way to send to Espruino (either json, base64, or compressed base64)