فهرست منبع

MicroPython support

Andrew Chalkley 8 سال پیش
والد
کامیت
7013db3eba
3فایلهای تغییر یافته به همراه28 افزوده شده و 17 حذف شده
  1. 25 14
      back-end/prepare_binaries.js
  2. 1 1
      front-end/js/app.js
  3. 2 2
      package.json

+ 25 - 14
back-end/prepare_binaries.js

@@ -4,6 +4,7 @@ const request = require("request");
 const decompress = require("decompress");
 const fs = require("fs");
 const EventEmitter = require("events").EventEmitter;
+const url = require('url');
 
 function isBinaryFileRequired(flashSpecification, fileName) {
     return flashSpecification.map(binary => binary.path).indexOf(fileName) !== -1;
@@ -22,12 +23,14 @@ function prepareBinaries(manifest) {
     const flashContents = manifest.flash;
     let body;
     let contentLength;
+    const pathName = url.parse(manifest.download).pathname;
+    const fileName = pathName.split("/").pop();
     request(manifest.download)
         .on("response", response => {
             contentLength = Number(response.headers["content-length"]);
         })
         .on("data", data => {
-            if(body) {
+            if (body) {
                 body = Buffer.concat([body, data]);
             } else {
                 body = data;
@@ -42,19 +45,27 @@ function prepareBinaries(manifest) {
             eventEmitter.emit("progress", progress);
         })
         .on("complete", () => {
-            decompress(body, {
-                 filter: file => isBinaryFileRequired(flashContents, file.path)
-            })
-            .then(files => {
-                files.forEach(
-                    file => addBufferToBinary(flashContents, file.path, file.data)
-                );
-                eventEmitter.emit("complete", flashContents);
-            })
-            .catch(err => eventEmitter.emit("error", err));
-      })
-      .on("error", err => eventEmitter.emit("error", err));
-    
+            let preparedPromise;
+            if (manifest.download.toLowerCase().endsWith(".zip")) {
+                preparedPromise = decompress(body, {
+                    filter: file => isBinaryFileRequired(flashContents, file.path)
+                })
+                    .then(files => {
+                        files.forEach(
+                            file => addBufferToBinary(flashContents, file.path, file.data)
+                        );
+                    });
+            } else {
+                preparedPromise = new Promise((resolve, reject)=>{
+                    addBufferToBinary(flashContents, fileName, body);
+                    resolve();
+                });
+            }
+            preparedPromise.then(() => eventEmitter.emit("complete", flashContents))
+                .catch(err => eventEmitter.emit("error", err));
+        })
+        .on("error", err => eventEmitter.emit("error", err));
+
     return eventEmitter;
 }
 

+ 1 - 1
front-end/js/app.js

@@ -9,7 +9,7 @@
  * @type {{manifestList: string, pollTime: number}}
  */
 const CONSTANTS = {
-    manifestList: "http://flasher.thingssdk.com/v1/manifest-list.json",
+    manifestList: "http://flasher.thingssdk.com/v1.1/manifest-list.json",
     pollTime: 1000
 };
 

+ 2 - 2
package.json

@@ -1,6 +1,6 @@
 {
   "name": "flasher.js",
-  "version": "1.0.0",
+  "version": "1.1.0",
   "description": "A GUI tool for flashing the JavaScript runtimes and other firmware on to ESP8266 based microcontrollers and development boards",
   "main": "index.js",
   "scripts": {
@@ -61,7 +61,7 @@
     "electron-squirrel-startup": "^1.0.0",
     "request": "^2.72.0",
     "rimraf": "^2.5.3",
-    "serialport": "4.0.0"
+    "serialport": "^4.0.6"
   },
   "devDependencies": {
     "chai": "^3.5.0",