Authored by 李靖

Merge branch 'feature/upload' of http://git.yoho.cn/OPENTECH/yoho-node-ci into feature/upload

@@ -6,11 +6,13 @@ const rd = require('rd'); @@ -6,11 +6,13 @@ const rd = require('rd');
6 const shelljs = require('shelljs'); 6 const shelljs = require('shelljs');
7 const decompress = require('decompress'); 7 const decompress = require('decompress');
8 const decompressUnzip = require('decompress-unzip'); 8 const decompressUnzip = require('decompress-unzip');
  9 +const ws = require('../../../lib/ws');
9 const qn = require('../../../lib/qiniu'); 10 const qn = require('../../../lib/qiniu');
10 const Router = require('koa-router'); 11 const Router = require('koa-router');
11 const router = new Router(); 12 const router = new Router();
12 13
13 const QINIU_PREFIX = 'yoho'; 14 const QINIU_PREFIX = 'yoho';
  15 +const BROADCAST_PATH = '/upload';
14 16
15 const file = { 17 const file = {
16 /** 18 /**
@@ -19,7 +21,6 @@ const file = { @@ -19,7 +21,6 @@ const file = {
19 page: async(ctx) => { 21 page: async(ctx) => {
20 let result = await qn.listAsync('/yoho'); 22 let result = await qn.listAsync('/yoho');
21 23
22 - console.log('ALL-FILE-LIST:', result);  
23 await ctx.render('/action/file_page', {fileList: result}); 24 await ctx.render('/action/file_page', {fileList: result});
24 }, 25 },
25 26
@@ -46,18 +47,20 @@ const file = { @@ -46,18 +47,20 @@ const file = {
46 await readable.pipe(writable); 47 await readable.pipe(writable);
47 48
48 readable.on('end', () => { 49 readable.on('end', () => {
49 - console.log('Zip file uploaded to Server!'); 50 + ws.broadcast(BROADCAST_PATH, {
  51 + state: 'Zip file uploaded to Server!'
  52 + });
50 }); 53 });
51 54
52 - console.log('Zip file savepath:', fileSavePath);  
53 -  
54 // 解压 55 // 解压
55 await decompress(fileSavePath, fileDistPath, { 56 await decompress(fileSavePath, fileDistPath, {
56 plugins: [ 57 plugins: [
57 decompressUnzip() 58 decompressUnzip()
58 ] 59 ]
59 }).then(() => { 60 }).then(() => {
60 - console.log('Zip file decompressed'); 61 + ws.broadcast(BROADCAST_PATH, {
  62 + state: 'Zip file decompressed!'
  63 + });
61 }); 64 });
62 65
63 // 上传到七牛处理 66 // 上传到七牛处理
@@ -76,7 +79,9 @@ const file = { @@ -76,7 +79,9 @@ const file = {
76 key: path.join(QINIU_PREFIX, fileList[i]) 79 key: path.join(QINIU_PREFIX, fileList[i])
77 }); 80 });
78 81
79 - console.log(`${fileList[i]} Uploaded to Qiniu!`); 82 + ws.broadcast(BROADCAST_PATH, {
  83 + state: `SUCCESS! ${fileList[i]} Uploaded to Qiniu!`
  84 + });
80 } 85 }
81 } 86 }
82 } 87 }