Преглед изворни кода

Merge branch 'fix/gulpfile_download' into 'develop'

Merge of fix/gulpfile_download to develop 修改gulpfile,修正gitlab下载jvm出错

See merge request o2oa/o2oa!265
胡起 пре 5 година
родитељ
комит
8e68a2bdc8
1 измењених фајлова са 57 додато и 2 уклоњено
  1. 57 2
      gulpfile.js

+ 57 - 2
gulpfile.js

@@ -99,7 +99,7 @@ function ProgressBar(description, bar_length){
     };
 }
 
-function downloadFile(path, filename, headcb, progresscb, cb){
+function downloadFile_progress(path, filename, headcb, progresscb, cb){
     var dest = `o2server/${filename}`;
 
     // fs.exists(dest, function(exists) {
@@ -144,7 +144,7 @@ function downloadFile(path, filename, headcb, progresscb, cb){
                     });
                     request.get(options).pipe(str).pipe(stream);
                 } else {
-                    gutil.log(gutil.colors.red("download error"), ":", gutil.colors.red(filename), "statusCode:"+response.statusCode);
+                    gutil.log(gutil.colors.red("download error"), ":", gutil.colors.red(filename), "statusCode:"+res.statusCode);
                 }
             })
             req.on('error', (e) => {
@@ -154,6 +154,61 @@ function downloadFile(path, filename, headcb, progresscb, cb){
     //    }
     //});
 }
+function downloadFile(path, filename, headcb, progresscb, cb){
+    var dest = `o2server/${filename}`;
+
+    // fs.exists(dest, function(exists) {
+    //     if (exists){
+    //         headcb(1);
+    //         progresscb({transferred:1});
+    //         cb();
+    //     }else{
+    let stream = fs.createWriteStream(dest);
+    var options = { url:protocol+"://"+downloadHost+path };
+    var fileHost = downloadHost;
+    var filePath =  path;
+    stream.on('finish', () => {
+        //gutil.log("download", ":", gutil.colors.green(filename), " completed!");
+        cb();
+    });
+    stream.on('error', (err) => {
+        gutil.log(gutil.colors.red("download error"), ":", gutil.colors.red(filename), err);
+    });
+
+    // var req = http.request({
+    //     host:fileHost,
+    //     path:filePath,
+    //     method:'HEAD'
+    // },function (res){
+    //     if (res.statusCode == 200) {
+    //         res.setEncoding(null);
+    //         var time = 0;
+    //         var l = res.headers['content-length'];
+    //         var str = progress({
+    //             length: l,
+    //             time: 100 /* ms */
+    //         });
+    //         headcb(l);
+    //
+    //         str.on('progress', function(progress) {
+    //             if (pb){
+    //                 progresscb(progress);
+    //                 pb.render({ completed: currentLength, total: totalLength, time: time+=100 });
+    //             }
+    //
+    //         });
+             request.get(options).pipe(stream);
+    //     } else {
+    //         gutil.log(gutil.colors.red("download error"), ":", gutil.colors.red(filename), "statusCode:"+res.statusCode);
+    //     }
+    // })
+    // req.on('error', (e) => {
+    //     gutil.log(gutil.colors.red("download error"), ":", gutil.colors.red(filename), e);
+    // });
+    // req.end();
+    //    }
+    //});
+}
 
 var commonsLength = 0;
 var jvmLenght = 0;