Commit 1189f63f authored by 郭志伟's avatar 郭志伟

build: 升级oss上传插件

parent 697f49e6
{ {
"api": { "api": {
"apiHost": "https://quantum-blocks-test1.liangkebang.net", "apiHost": "https://quantum-blocks-undefined.liangkebang.net",
"h5Host": "https://quantum-h5-test1.liangkebang.net", "h5Host": "https://quantum-h5-undefined.liangkebang.net",
"opapiHost": "https://opapi-test1.liangkebang.net", "opapiHost": "https://opapi-undefined.liangkebang.net",
"passportHost": "https://passportapi-test1.liangkebang.net", "passportHost": "https://passportapi-undefined.liangkebang.net",
"talosHost": "https://talos-test1.liangkebang.net", "talosHost": "https://talos-undefined.liangkebang.net",
"kdspHost": "https://kdsp-api-test1.liangkebang.net", "kdspHost": "https://kdsp-api-undefined.liangkebang.net",
"loginUrl": "", "loginUrl": "",
"newApolloFlag": true, "newApolloFlag": true,
"h5ShopHost": "https://tenet-test1.liangkebang.net/#", "h5ShopHost": "https://tenet-undefined.liangkebang.net/#",
"mallHost": "https://mall-test1.liangkebang.net", "mallHost": "https://mall-undefined.liangkebang.net",
"xyqbH5Host": "https://mapi-test1.liangkebang.net", "xyqbH5Host": "https://mapi-undefined.liangkebang.net",
"yxmTenantId": 560761, "yxmTenantId": 560761,
"appIdMap": { "appIdMap": {
"560761": "wxe16bf9293671506c", "560761": "wxe16bf9293671506c",
...@@ -18,8 +18,8 @@ ...@@ -18,8 +18,8 @@
} }
}, },
"redis": { "redis": {
"port": "32625", "port": "undefined",
"host": "172.17.5.22", "host": "undefined",
"password": "", "password": "",
"db": 0 "db": 0
}, },
......
{"apiHost":"https://quantum-blocks-test1.liangkebang.net","h5Host":"https://quantum-h5-test1.liangkebang.net","opapiHost":"https://opapi-test1.liangkebang.net","passportHost":"https://passportapi-test1.liangkebang.net","talosHost":"https://talos-test1.liangkebang.net","kdspHost":"https://kdsp-api-test1.liangkebang.net","loginUrl":"","newApolloFlag":true,"h5ShopHost":"https://tenet-test1.liangkebang.net/#","mallHost":"https://mall-test1.liangkebang.net","xyqbH5Host":"https://mapi-test1.liangkebang.net","yxmTenantId":560761,"appIdMap":{"560761":"wxe16bf9293671506c","560867":"wxccb8435d68e8c7d6"},"qiniuUpHost":"https://up-z0.qiniup.com","qiniuHost":"https://appsync.lkbang.net"} {"apiHost":"https://quantum-blocks-undefined.liangkebang.net","h5Host":"https://quantum-h5-undefined.liangkebang.net","opapiHost":"https://opapi-undefined.liangkebang.net","passportHost":"https://passportapi-undefined.liangkebang.net","talosHost":"https://talos-undefined.liangkebang.net","kdspHost":"https://kdsp-api-undefined.liangkebang.net","loginUrl":"","newApolloFlag":true,"h5ShopHost":"https://tenet-undefined.liangkebang.net/#","mallHost":"https://mall-undefined.liangkebang.net","xyqbH5Host":"https://mapi-undefined.liangkebang.net","yxmTenantId":560761,"appIdMap":{"560761":"wxe16bf9293671506c","560867":"wxccb8435d68e8c7d6"},"qiniuUpHost":"https://up-z0.qiniup.com","qiniuHost":"https://appsync.lkbang.net"}
\ No newline at end of file \ No newline at end of file
This diff is collapsed.
const COS = require('cos-nodejs-sdk-v5'); const OSS = require("ali-oss");
const path = require('path'); const path = require("path");
const fs = require('fs'); const fs = require('fs');
const prefix = process.env.COS_ENV === 'production' ? 'qb' : 'qb-test'; const prefix = process.env.COS_ENV === 'production' ? 'qb' : 'qb-test';
...@@ -10,9 +10,11 @@ console.log('prefix', process.env); ...@@ -10,9 +10,11 @@ console.log('prefix', process.env);
class upload2Cos { class upload2Cos {
constructor() { constructor() {
this.filesPath = []; this.filesPath = [];
this.instance = new COS({ this.instance = new OSS({
SecretId: 'AKIDVlxtVqOK9i0wc0m0e7C5saATZnl2xvUx', region: 'oss-cn-beijing',
SecretKey: 'NWQ3VlmWeFtIQHrDI6F9oCheMq41lGVV' bucket: 'qg-misc',
accessKeyId: 'LTAI5tQoJrx4uYsG7CVSa9wn',
accessKeySecret: 'JHhGqvrY6O6433Hz805efdM0TBUJO6',
}); });
} }
...@@ -20,31 +22,19 @@ class upload2Cos { ...@@ -20,31 +22,19 @@ class upload2Cos {
this._readFileList(path.resolve(__dirname, './public'), this.filesPath); this._readFileList(path.resolve(__dirname, './public'), this.filesPath);
} }
upload() { async upload() {
this.getFilesPath(); this.getFilesPath();
const filesList = this.filesPath.map(filepath => { const filesCount = this.filesPath.length;
return { try {
Bucket: 'misc-1258270469', for (let idx = 0; idx < this.filesPath.length; idx++) {
Region: 'ap-beijing', const filepath = this.filesPath[idx];
Key: `${prefix}/public${filepath.split('public')[1]}`, await this.instance.put(`${prefix}/public${filepath.split('public')[1]}`, path.normalize(filepath));
FilePath: filepath let percent = (parseFloat((idx + 1) / filesCount) * 100).toFixed(2);
console.log('进度:' + percent + '%');
}
} catch (error) {
console.log(error);
} }
});
this.instance.uploadFiles({
files: filesList,
SliceSize: 1024 * 1024,
onProgress: function (info) {
var percent = parseInt(info.percent * 10000) / 100;
var speed = parseInt(info.speed / 1024 / 1024 * 100) / 100;
console.log('进度:' + percent + '%; 速度:' + speed + 'Mb/s;');
},
onFileFinish: function (err, data, options) {
console.log(options.Key + '上传' + (err ? '失败' : '完成'));
},
}, function (err, data) {
console.log(err || data);
});
} }
_isValid (path) { _isValid (path) {
...@@ -53,17 +43,17 @@ class upload2Cos { ...@@ -53,17 +43,17 @@ class upload2Cos {
} }
_readFileList(dir, filesPath = []) { _readFileList(dir, filesPath = []) {
  const files = fs.readdirSync(dir); const files = fs.readdirSync(dir);
  files.forEach((item, index) => { files.forEach((item, index) => {
    var fullPath = path.join(dir, item); var fullPath = path.join(dir, item);
    const stat = fs.statSync(fullPath); const stat = fs.statSync(fullPath);
    if (stat.isDirectory()) {   if (stat.isDirectory()) {
      this._readFileList(path.join(dir, item), filesPath); this._readFileList(path.join(dir, item), filesPath);
    } else if(this._isValid(fullPath)) {        } else if(this._isValid(fullPath)) {
      filesPath.push(fullPath);           filesPath.push(fullPath);
    }    }
  }); });
  return filesPath; return filesPath;
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment