From 26111b84d27d62df5494c9c05ec818a01f2e7bdf Mon Sep 17 00:00:00 2001 From: Ylian Saint-Hilaire Date: Mon, 20 Apr 2020 20:12:35 -0700 Subject: [PATCH] Fixed file corruption when AgentPong is used. --- agents/meshcore.js | 6 ++++-- views/default.handlebars | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/agents/meshcore.js b/agents/meshcore.js index ea29f42d..51ce6986 100644 --- a/agents/meshcore.js +++ b/agents/meshcore.js @@ -1100,8 +1100,10 @@ function createMeshCore(agent) { // If this is upload data, save it to file if (this.httprequest.uploadFile) { - try { fs.writeSync(this.httprequest.uploadFile, data); } catch (e) { this.write(new Buffer(JSON.stringify({ action: 'uploaderror' }))); return; } // Write to the file, if there is a problem, error out. - this.write(new Buffer(JSON.stringify({ action: 'uploadack', reqid: this.httprequest.uploadFileid }))); // Ask for more data + if (typeof data == 'object') { + try { fs.writeSync(this.httprequest.uploadFile, data); } catch (e) { this.write(new Buffer(JSON.stringify({ action: 'uploaderror' }))); return; } // Write to the file, if there is a problem, error out. + this.write(new Buffer(JSON.stringify({ action: 'uploadack', reqid: this.httprequest.uploadFileid }))); // Ask for more data + } return; } /* diff --git a/views/default.handlebars b/views/default.handlebars index 10aa4d86..3dd80845 100644 --- a/views/default.handlebars +++ b/views/default.handlebars @@ -6915,7 +6915,7 @@ var p13filetreelocation = []; function p13gotFiles(data) { - if ((data.length > 0) && (data.charCodeAt(0) != 123)) { p13gotDownloadBinaryData(data); return; } + if ((data.length > 0) && (data.charCodeAt(0) != 123)) { p13gotDownloadBinaryData(data); return; } // This is ok because 4 first bytes is a control value. //console.log('p13gotFiles', data); data = JSON.parse(decode_utf8(data)); if (data.action == 'download') { p13gotDownloadCommand(data); return; }