Commit 2174cae3 authored by 徐光星's avatar 徐光星

Merge branch 'feat/updateOssUploader' into 'master'

Feat/update oss uploader

See merge request !91
parents cdc6f218 42232d48
{ {
"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
...@@ -3139,6 +3139,128 @@ ...@@ -3139,6 +3139,128 @@
"resolved": "http://npmprivate.quantgroups.com/ajv-keywords/-/ajv-keywords-3.5.2.tgz", "resolved": "http://npmprivate.quantgroups.com/ajv-keywords/-/ajv-keywords-3.5.2.tgz",
"integrity": "sha512-5p6WTN0DdTGVQk6VjcEju19IgaHudalcfabD7yhDGeA6bcQnmL+CpveLJq/3hvfwd1aof6L386Ougkx6RfyMIQ==" "integrity": "sha512-5p6WTN0DdTGVQk6VjcEju19IgaHudalcfabD7yhDGeA6bcQnmL+CpveLJq/3hvfwd1aof6L386Ougkx6RfyMIQ=="
}, },
"ali-oss": {
"version": "6.17.1",
"resolved": "http://npmprivate.quantgroups.com/ali-oss/-/ali-oss-6.17.1.tgz",
"integrity": "sha512-v2oT3UhSJTH/LrsscVvi7iEGrnundydNaFzpYAKatqOl4JNcBV4UiwtlJU+ZHLys040JH2k+CutznA0GoE+P2w==",
"dev": true,
"requires": {
"address": "^1.0.0",
"agentkeepalive": "^3.4.1",
"bowser": "^1.6.0",
"copy-to": "^2.0.1",
"dateformat": "^2.0.0",
"debug": "^2.2.0",
"destroy": "^1.0.4",
"end-or-error": "^1.0.1",
"get-ready": "^1.0.0",
"humanize-ms": "^1.2.0",
"is-type-of": "^1.0.0",
"js-base64": "^2.5.2",
"jstoxml": "^2.0.0",
"merge-descriptors": "^1.0.1",
"mime": "^2.4.5",
"mz-modules": "^2.1.0",
"platform": "^1.3.1",
"pump": "^3.0.0",
"sdk-base": "^2.0.1",
"stream-http": "2.8.2",
"stream-wormhole": "^1.0.4",
"urllib": "^2.33.1",
"utility": "^1.8.0",
"xml2js": "^0.4.16"
},
"dependencies": {
"agentkeepalive": {
"version": "3.5.2",
"resolved": "http://npmprivate.quantgroups.com/agentkeepalive/-/agentkeepalive-3.5.2.tgz",
"integrity": "sha512-e0L/HNe6qkQ7H19kTlRRqUibEAwDK5AFk6y3PtMsuut2VAH6+Q4xZml1tNDJD7kSAyqmbG/K08K5WEJYtUrSlQ==",
"dev": true,
"requires": {
"humanize-ms": "^1.2.1"
}
},
"debug": {
"version": "2.6.9",
"resolved": "http://npmprivate.quantgroups.com/debug/-/debug-2.6.9.tgz",
"integrity": "sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==",
"dev": true,
"requires": {
"ms": "2.0.0"
}
},
"get-ready": {
"version": "1.0.0",
"resolved": "http://npmprivate.quantgroups.com/get-ready/-/get-ready-1.0.0.tgz",
"integrity": "sha1-+RgX8emt7P6hOlYq38jeiDqzR4I=",
"dev": true
},
"isarray": {
"version": "1.0.0",
"resolved": "http://npmprivate.quantgroups.com/isarray/-/isarray-1.0.0.tgz",
"integrity": "sha1-u5NdSFgsuhaMBoNJV6VKPgcSTxE=",
"dev": true
},
"ms": {
"version": "2.0.0",
"resolved": "http://npmprivate.quantgroups.com/ms/-/ms-2.0.0.tgz",
"integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g=",
"dev": true
},
"readable-stream": {
"version": "2.3.7",
"resolved": "http://npmprivate.quantgroups.com/readable-stream/-/readable-stream-2.3.7.tgz",
"integrity": "sha512-Ebho8K4jIbHAxnuxi7o42OrZgF/ZTNcsZj6nRKyUmkhLFq8CHItp/fy6hQZuZmP/n3yZ9VBUbp4zz/mX8hmYPw==",
"dev": true,
"requires": {
"core-util-is": "~1.0.0",
"inherits": "~2.0.3",
"isarray": "~1.0.0",
"process-nextick-args": "~2.0.0",
"safe-buffer": "~5.1.1",
"string_decoder": "~1.1.1",
"util-deprecate": "~1.0.1"
}
},
"safe-buffer": {
"version": "5.1.2",
"resolved": "http://npmprivate.quantgroups.com/safe-buffer/-/safe-buffer-5.1.2.tgz",
"integrity": "sha512-Gd2UZBJDkXlY7GbJxfsE8/nvKkUEU1G38c1siN6QP6a9PT9MmHB8GnpscSmMJSoF8LOIrt8ud/wPtojys4G6+g==",
"dev": true
},
"sdk-base": {
"version": "2.0.1",
"resolved": "http://npmprivate.quantgroups.com/sdk-base/-/sdk-base-2.0.1.tgz",
"integrity": "sha1-ukAonovfJy7RHdnql+r5jgNtJMY=",
"dev": true,
"requires": {
"get-ready": "~1.0.0"
}
},
"stream-http": {
"version": "2.8.2",
"resolved": "http://npmprivate.quantgroups.com/stream-http/-/stream-http-2.8.2.tgz",
"integrity": "sha512-QllfrBhqF1DPcz46WxKTs6Mz1Bpc+8Qm6vbqOpVav5odAXwbyzwnEczoWqtxrsmlO+cJqtPrp/8gWKWjaKLLlA==",
"dev": true,
"requires": {
"builtin-status-codes": "^3.0.0",
"inherits": "^2.0.1",
"readable-stream": "^2.3.6",
"to-arraybuffer": "^1.0.0",
"xtend": "^4.0.0"
}
},
"string_decoder": {
"version": "1.1.1",
"resolved": "http://npmprivate.quantgroups.com/string_decoder/-/string_decoder-1.1.1.tgz",
"integrity": "sha512-n/ShnvDi6FHbbVfviro+WojiFzv+s8MPMHBczVePfUpDJLwoLT0ht1l4YwBCbi8pJAveEEdnkHyPyTP/mzRfwg==",
"dev": true,
"requires": {
"safe-buffer": "~5.1.0"
}
}
}
},
"align-text": { "align-text": {
"version": "0.1.4", "version": "0.1.4",
"resolved": "http://npmprivate.quantgroups.com/align-text/-/align-text-0.1.4.tgz", "resolved": "http://npmprivate.quantgroups.com/align-text/-/align-text-0.1.4.tgz",
...@@ -5261,6 +5383,12 @@ ...@@ -5261,6 +5383,12 @@
"integrity": "sha1-aN/1++YMUes3cl6p4+0xDcwed24=", "integrity": "sha1-aN/1++YMUes3cl6p4+0xDcwed24=",
"dev": true "dev": true
}, },
"bowser": {
"version": "1.9.4",
"resolved": "http://npmprivate.quantgroups.com/bowser/-/bowser-1.9.4.tgz",
"integrity": "sha512-9IdMmj2KjigRq6oWhmwv1W36pDuA4STQZ8q6YO9um+x07xgYNCD3Oou+WP/3L1HNz7iqythGet3/p4wvc8AAwQ==",
"dev": true
},
"boxen": { "boxen": {
"version": "1.3.0", "version": "1.3.0",
"resolved": "http://npmprivate.quantgroups.com/boxen/-/boxen-1.3.0.tgz", "resolved": "http://npmprivate.quantgroups.com/boxen/-/boxen-1.3.0.tgz",
...@@ -7997,6 +8125,12 @@ ...@@ -7997,6 +8125,12 @@
"integrity": "sha512-hBSVCvSmWC+QypYObzwGOd9wqdDpOt+0wl0KbU+R+uuZBS1jN8VsD1ss3irQDknRj5NvxiTF6oj/nDRnN/UQNw==", "integrity": "sha512-hBSVCvSmWC+QypYObzwGOd9wqdDpOt+0wl0KbU+R+uuZBS1jN8VsD1ss3irQDknRj5NvxiTF6oj/nDRnN/UQNw==",
"dev": true "dev": true
}, },
"dateformat": {
"version": "2.2.0",
"resolved": "http://npmprivate.quantgroups.com/dateformat/-/dateformat-2.2.0.tgz",
"integrity": "sha1-QGXiATz5+5Ft39gu+1Bq1MZ2kGI=",
"dev": true
},
"de-indent": { "de-indent": {
"version": "1.0.2", "version": "1.0.2",
"resolved": "http://npmprivate.quantgroups.com/de-indent/-/de-indent-1.0.2.tgz", "resolved": "http://npmprivate.quantgroups.com/de-indent/-/de-indent-1.0.2.tgz",
...@@ -9400,6 +9534,12 @@ ...@@ -9400,6 +9534,12 @@
"once": "^1.4.0" "once": "^1.4.0"
} }
}, },
"end-or-error": {
"version": "1.0.1",
"resolved": "http://npmprivate.quantgroups.com/end-or-error/-/end-or-error-1.0.1.tgz",
"integrity": "sha1-3HpiEP5403L+4kqLSJnb0VVBTcs=",
"dev": true
},
"enhanced-resolve": { "enhanced-resolve": {
"version": "4.5.0", "version": "4.5.0",
"resolved": "http://npmprivate.quantgroups.com/enhanced-resolve/-/enhanced-resolve-4.5.0.tgz", "resolved": "http://npmprivate.quantgroups.com/enhanced-resolve/-/enhanced-resolve-4.5.0.tgz",
...@@ -14123,6 +14263,12 @@ ...@@ -14123,6 +14263,12 @@
"verror": "1.10.0" "verror": "1.10.0"
} }
}, },
"jstoxml": {
"version": "2.2.9",
"resolved": "http://npmprivate.quantgroups.com/jstoxml/-/jstoxml-2.2.9.tgz",
"integrity": "sha512-OYWlK0j+roh+eyaMROlNbS5cd5R25Y+IUpdl7cNdB8HNrkgwQzIS7L9MegxOiWNBj9dQhA/yAxiMwCC5mwNoBw==",
"dev": true
},
"jsx-ast-utils": { "jsx-ast-utils": {
"version": "3.2.0", "version": "3.2.0",
"resolved": "http://npmprivate.quantgroups.com/jsx-ast-utils/-/jsx-ast-utils-3.2.0.tgz", "resolved": "http://npmprivate.quantgroups.com/jsx-ast-utils/-/jsx-ast-utils-3.2.0.tgz",
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