deploy1 6 yıl önce
ebeveyn
işleme
bd95981524
5 değiştirilmiş dosya ile 128 ekleme ve 15 silme
  1. 8 1
      generatezip.js
  2. 53 3
      getthezip.js
  3. 1 0
      package.json
  4. 61 8
      unpackzip.js
  5. 5 3
      uploader.js

+ 8 - 1
generatezip.js

@@ -18,7 +18,12 @@ function generatezip(endfilename, obj, callback) {
     var zip = new JSZip();
     async.mapSeries(filenames, function(ofilename, next) {
         var file = obj[ofilename];
-        if (ofilename.indexOf("namespace.manifest") === 0) {
+      
+        if (ofilename.indexOf(".js") === ofilename.length-3) {
+            console.log("JJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJ",ofilename, file.data.length);
+            zip.file(ofilename, file.data);
+        } else {
+           if (ofilename.indexOf("namespace.manifest") === 0) {
             zip.file(ofilename, JSON.stringify(file.data, true, 2))
         } else {
             if (typeof(file) === "object" && ofilename.indexOf(".json") === -1) {
@@ -27,6 +32,8 @@ function generatezip(endfilename, obj, callback) {
                 zip.file(ofilename, file)
             }
 
+        }
+
         }
         next()
     }, function(err, result) {

+ 53 - 3
getthezip.js

@@ -2,16 +2,66 @@ var isbrowser = require("./isbrowser");
 
 var promisetimeout = require("./promisetimeout");
 
-var futch = isbrowser ? require("./lib_futch") : require("node-fetch");
+//var futch = isbrowser ? require("./lib_futch") : require("node-fetch");
+var futch = isbrowser ? fetch : require("node-fetch");
 var returner = isbrowser ? function(res) {
     return res.blob()
 } : function(res) {
     return res.arrayBuffer()
 };
+ 
+
+function getthezip2(url, nreturener) {
+    // var id = nb(url).SHA1().toBase(16).substring(0, 8);
+    //  if ($("#loader-" + id).length == 0) {
+    //       $("#loader").append('<div id="loader-' + id + '">' + url + '</div>')
+    //  }
+
+    var pp = new Promise(function(resolve, reject) {
+        var request = new XMLHttpRequest();
+        request.open('GET', url, true);
+        request.responseType = 'blob';
+
+        request.onload = function() {
+            /*var reader = new FileReader();
+
+            reader.onload = function(e) {
+                resolve(e.target.result)
+            };
+            reader.onerror = function(err) {
+                reject(err)
+            };
+
+            reader.readAsDataURL(request.response);*/
+            resolve(request.response)
+        }
+
+        request.send();
+    })
+    pp.then(nreturener ? nreturener : returner)
+
+    return promisetimeout(120000, pp);
+
+
+    var pp = futch(url, {
+            method: 'get',
+            headers: {
+                'token': 'T66V8L034VY76K3GG9B83ZXZW7PKOL'
+            },
+        }, function(l) {
+            //        if (l.total > 0 && l.loaded === l.total) {
+            //            $("#loader-" + id).html("");
+            //       } else {
+            //         $("#loader-" + id).html("<pre>" + l.loaded + "/" + l.total + '</pre>')
+            //   }
+        })
+        .then(nreturener ? nreturener : returner)
+    return promisetimeout(120000, pp);
+}
 
 
 
-function getthezip(url) {
+function getthezip(url, nreturener) {
     // var id = nb(url).SHA1().toBase(16).substring(0, 8);
     //  if ($("#loader-" + id).length == 0) {
     //       $("#loader").append('<div id="loader-' + id + '">' + url + '</div>')
@@ -28,7 +78,7 @@ function getthezip(url) {
             //         $("#loader-" + id).html("<pre>" + l.loaded + "/" + l.total + '</pre>')
             //   }
         })
-        .then(returner)
+        .then(nreturener ? nreturener : returner)
     return promisetimeout(120000, pp);
 }
 

+ 1 - 0
package.json

@@ -16,6 +16,7 @@
     "async": "^2.6.1",
     "aws-sdk": "^2.315.0",
     "buffa": "git+ssh://git@git.tum.dk/tum.dk/buffa",
+    "file-type": "^10.0.0",
     "jszip": "^3.1.5",
     "node-fetch": "^2.2.0",
     "opath": "git+ssh://git@git.tum.dk/tum.dk/opath"

+ 61 - 8
unpackzip.js

@@ -1,5 +1,6 @@
 var JSZip = require("jszip");
 var async = require("async");
+var fileType = require("file-type");
 
 function unpackzip(emitter) {
     return function(f) {
@@ -12,11 +13,13 @@ function unpackzip(emitter) {
         var p = new Promise(function(resolve, reject) {
             JSZip.loadAsync(f) // 1) read the Blob
             .then(function(zip) {
+                var nass;
                 var obj = {};
                 if (zip.files["namespace.manifest"]) {
                     zip.file("namespace.manifest").async("string")
                         .then(function(data) {
-                            emitter.emit("namespace", JSON.parse(data), cont)
+                            nass= JSON.parse(data);
+                            emitter.emit("namespace", nass, cont)
                         })
                 } else {
                     emitter.emit("nonamespace", cont)
@@ -24,20 +27,70 @@ function unpackzip(emitter) {
 
                 function cont() {
                     async.mapSeries(zip.files, function(z, next) {
-                        if (z.dir) {} else {
-                            zip.file(z.name).async("string")
+                        if (z.dir) {
+                            next()
+                        } else {
+
+                            zip.file(z.name).async("uint8array")
                                 .then(function(data) {
-                                    if (z.name.indexOf(".json") > -1) {
+                                    var mimen = fileType(data);
 
-                                        emitter.emit("json", z.name, JSON.parse(data))
+                                    if (z.name.indexOf(".json") > -1 || z.name.indexOf(".link") > -1) {
+                                        zip.file(z.name).async("string")
+                                            .then(function(data) {
+                                                if (z.name.indexOf(".json") > -1) {
+                                                    emitter.emit("json", z.name, JSON.parse(data))
+                                                } else {
+                                                    if (z.name !== "namespace.manifest") {
+                                                        emitter.emit("file", z.name, (data))
+                                                    }
+                                                }
+                                                next()
+                                            })
                                     } else {
-                                        if (z.name !== "namespace.manifest") {
+                                        if (z.name.indexOf(".svg") > -1) {
+                                            zip.file(z.name).async("string")
+                                                .then(function(data) {
+                                                    if (z.name !== "namespace.manifest") {
+                                                        emitter.emit("file", z.name, (data))
+                                                    }
+                                                    next()
+                                                })
+                                        } else {
+
+                                            if (z.name.indexOf(".js")===z.name.length-3) {
+                                                zip.file(z.name).async("string")
+                                                    .then(function(data) {
+                                                       emitter.emit("jsfile", z.name, data, nass);
+                                                      
+                                                        next()
+                                                    })
+                                            } else {
+                                                zip.file(z.name).async("base64")
+                                                    .then(function(data) {
+                                                        if (z.name !== "namespace.manifest") {
+                                                            emitter.emit("file", z.name, (data), mimen)
+                                                        }
+                                                        next()
+                                                    })
+                                            }
+
+
 
-                                            emitter.emit("file", z.name, (data))
                                         }
                                     }
-                                    next()
+
+
+
+
                                 })
+
+
+
+
+
+
+
                         }
                     }, function(err, done) {
                         emitter.emit("done")

+ 5 - 3
uploader.js

@@ -1,4 +1,5 @@
 
+/*
 var AWS = require("aws-sdk")
 
 
@@ -18,12 +19,13 @@ function connectAws(bucket, region, identity) {
     return s3;
 }
 
-
+*/
 
 
 module.exports = function() {
 
 
-    var s3 = connectAws("a.tum.dk", "eu-west-1", "eu-west-1:5343270a-03fd-4856-ad07-25f1e2c78246");
-    return s3;
+  /*  var s3 = connectAws("a.tum.dk", "eu-west-1", "eu-west-1:5343270a-03fd-4856-ad07-25f1e2c78246");
+    return s3;*/
+    
 }