Fixed file corruption when AgentPong is used.
Ylian Saint-Hilaire committed
Apr 20, 2020 at 20:12 UTC
26111b84d27d62df5494c9c05ec818a01f2e7bdf
2 files changed
+5
-3
agents/meshcore.js
+4
-2
@@ -1100,8 +1100,10 @@ function createMeshCore(agent) {
1100
1101
// If this is upload data, save it to file
1102
if (this.httprequest.uploadFile) {
1103
- 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.
1104
- this.write(new Buffer(JSON.stringify({ action: 'uploadack', reqid: this.httprequest.uploadFileid }))); // Ask for more data
1103
+ if (typeof data == 'object') {
1104
+ 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.
1105
+ this.write(new Buffer(JSON.stringify({ action: 'uploadack', reqid: this.httprequest.uploadFileid }))); // Ask for more data
1106
+ }
1107
return;
1108
}
1109
/*
views/default.handlebars
+1
-1
@@ -6915,7 +6915,7 @@
6915
var p13filetreelocation = [];
6916
6917
function p13gotFiles(data) {
6918
- if ((data.length > 0) && (data.charCodeAt(0) != 123)) { p13gotDownloadBinaryData(data); return; }
6918
+ if ((data.length > 0) && (data.charCodeAt(0) != 123)) { p13gotDownloadBinaryData(data); return; } // This is ok because 4 first bytes is a control value.
6919
//console.log('p13gotFiles', data);
6920
data = JSON.parse(decode_utf8(data));
6921
if (data.action == 'download') { p13gotDownloadCommand(data); return; }