From 79a1900fefe97aaae1f930a2d90346feefc24828 Mon Sep 17 00:00:00 2001 From: abbott Date: Sun, 13 Sep 2020 13:35:19 +0800 Subject: [PATCH] =?UTF-8?q?[feature]=E6=B7=BB=E5=8A=A0=E4=BA=86=E8=85=BE?= =?UTF-8?q?=E8=AE=AF=E4=BA=91=E7=9A=84cos=E5=AD=98=E5=82=A8=E6=94=AF?= =?UTF-8?q?=E6=8C=81=EF=BC=8C=E5=B9=B6=E9=87=8D=E6=9E=84=E4=BA=86oss?= =?UTF-8?q?=E4=B8=8A=E4=BC=A0=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- web/dashboard/.env.development | 13 ++++++- web/dashboard/.env.production | 13 ++++++- web/dashboard/.env.test | 13 ++++++- web/dashboard/.env.uat | 13 ++++++- web/dashboard/package.json | 1 + web/dashboard/src/libs/cloud.js | 15 ++++++++ web/dashboard/src/libs/cos.js | 37 +++++++++++++++++++ web/dashboard/src/libs/oss.js | 4 +- web/dashboard/src/views/rn/editPackage.vue | 6 +-- .../src/views/version/android/uploadApk.vue | 9 +++-- 10 files changed, 112 insertions(+), 12 deletions(-) create mode 100644 web/dashboard/src/libs/cloud.js create mode 100644 web/dashboard/src/libs/cos.js diff --git a/web/dashboard/.env.development b/web/dashboard/.env.development index f324ce5..04f19f9 100644 --- a/web/dashboard/.env.development +++ b/web/dashboard/.env.development @@ -4,8 +4,19 @@ VUE_APP_HTTP_TIMEOUT = 15000 VUE_APP_HTTP_API = "http://localhost:8088/manager" VUE_APP_TITLE = "APP 管理平台 - 开发" +#上传到云的开关 +VUE_APP_CLOUD_STORAGE_TYPE_ENABLE = "1" + # OSS 配置 +VUE_APP_OSS_CLOUD_STORAGE_TYPE = "1" VUE_APP_OSS_REGION = "" VUE_APP_OSS_KEYID = "" VUE_APP_OSS_KEYSECRET = "" -VUE_APP_OSS_BUCKET = "" \ No newline at end of file +VUE_APP_OSS_BUCKET = "" + +# COS 配置 +VUE_APP_COS_CLOUD_STORAGE_TYPE = "2" +VUE_APP_COS_REGION = "" +VUE_APP_COS_KEYID = "" +VUE_APP_COS_KEYSECRET = "" +VUE_APP_COS_BUCKET = "" \ No newline at end of file diff --git a/web/dashboard/.env.production b/web/dashboard/.env.production index 24b4e56..7c056c9 100644 --- a/web/dashboard/.env.production +++ b/web/dashboard/.env.production @@ -4,8 +4,19 @@ VUE_APP_HTTP_TIMEOUT = 15000 VUE_APP_HTTP_API = "http://localhost:8088/manager" VUE_APP_TITLE = "APP 管理平台 - 开发" +#上传到云的开关 +VUE_APP_CLOUD_STORAGE_TYPE_ENABLE = "1" + # OSS 配置 +VUE_APP_OSS_CLOUD_STORAGE_TYPE = "1" VUE_APP_OSS_REGION = "" VUE_APP_OSS_KEYID = "" VUE_APP_OSS_KEYSECRET = "" -VUE_APP_OSS_BUCKET = "" \ No newline at end of file +VUE_APP_OSS_BUCKET = "" + +# COS 配置 +VUE_APP_COS_CLOUD_STORAGE_TYPE = "2" +VUE_APP_COS_REGION = "" +VUE_APP_COS_KEYID = "" +VUE_APP_COS_KEYSECRET = "" +VUE_APP_COS_BUCKET = "" \ No newline at end of file diff --git a/web/dashboard/.env.test b/web/dashboard/.env.test index 6c52ad2..9221d62 100644 --- a/web/dashboard/.env.test +++ b/web/dashboard/.env.test @@ -4,8 +4,19 @@ VUE_APP_HTTP_TIMEOUT = 15000 VUE_APP_HTTP_API = "http://localhost:8088/manager" VUE_APP_TITLE = "APP 管理平台 - 开发" +#上传到云的开关 +VUE_APP_CLOUD_STORAGE_TYPE_ENABLE = "1" + # OSS 配置 +VUE_APP_OSS_CLOUD_STORAGE_TYPE = "1" VUE_APP_OSS_REGION = "" VUE_APP_OSS_KEYID = "" VUE_APP_OSS_KEYSECRET = "" -VUE_APP_OSS_BUCKET = "" \ No newline at end of file +VUE_APP_OSS_BUCKET = "" + +# COS 配置 +VUE_APP_COS_CLOUD_STORAGE_TYPE = "2" +VUE_APP_COS_REGION = "" +VUE_APP_COS_KEYID = "" +VUE_APP_COS_KEYSECRET = "" +VUE_APP_COS_BUCKET = "" \ No newline at end of file diff --git a/web/dashboard/.env.uat b/web/dashboard/.env.uat index 0ffac08..b261641 100644 --- a/web/dashboard/.env.uat +++ b/web/dashboard/.env.uat @@ -4,8 +4,19 @@ VUE_APP_HTTP_TIMEOUT = 15000 VUE_APP_HTTP_API = "http://localhost:8088/manager" VUE_APP_TITLE = "APP 管理平台 - 开发" +#上传到云的开关 +VUE_APP_CLOUD_STORAGE_TYPE_ENABLE = "1" + # OSS 配置 +VUE_APP_OSS_CLOUD_STORAGE_TYPE = "1" VUE_APP_OSS_REGION = "" VUE_APP_OSS_KEYID = "" VUE_APP_OSS_KEYSECRET = "" -VUE_APP_OSS_BUCKET = "" \ No newline at end of file +VUE_APP_OSS_BUCKET = "" + +# COS 配置 +VUE_APP_COS_CLOUD_STORAGE_TYPE = "2" +VUE_APP_COS_REGION = "" +VUE_APP_COS_KEYID = "" +VUE_APP_COS_KEYSECRET = "" +VUE_APP_COS_BUCKET = "" \ No newline at end of file diff --git a/web/dashboard/package.json b/web/dashboard/package.json index c1a69c3..9e04b6a 100644 --- a/web/dashboard/package.json +++ b/web/dashboard/package.json @@ -17,6 +17,7 @@ "axios": "^0.18.0", "co": "^4.6.0", "codemirror": "^5.39.0", + "cos-js-sdk-v5": "^0.5.27", "filesize": "^3.6.1", "iview": "^3.2.2", "js-beautify": "^1.7.5", diff --git a/web/dashboard/src/libs/cloud.js b/web/dashboard/src/libs/cloud.js new file mode 100644 index 0000000..0c4e6f3 --- /dev/null +++ b/web/dashboard/src/libs/cloud.js @@ -0,0 +1,15 @@ +import uploadFileToOSS from '@/libs/oss'; +import uploadFileToCOS from '@/libs/cos'; + +const uploadFileToCloud = (file, fileName = '', callBack, progressCB = null) => { + switch (process.env.VUE_APP_CLOUD_STORAGE_TYPE_ENABLE) { + case process.env.VUE_APP_OSS_CLOUD_STORAGE_TYPE: + uploadFileToOSS(file, fileName, callBack, progressCB); + break; + case process.env.VUE_APP_COS_CLOUD_STORAGE_TYPE: + uploadFileToCOS(file, fileName, callBack, progressCB); + break; + } +}; + +export default uploadFileToCloud; diff --git a/web/dashboard/src/libs/cos.js b/web/dashboard/src/libs/cos.js new file mode 100644 index 0000000..6ccf082 --- /dev/null +++ b/web/dashboard/src/libs/cos.js @@ -0,0 +1,37 @@ +import COS from 'cos-js-sdk-v5'; + +const client = new COS({ + SecretId: process.env.VUE_APP_COS_KEYID, + SecretKey: process.env.VUE_APP_COS_KEYSECRET +}); + +const uploadFileToCOS = (file, fileName = '', callBack, progressCB = null) => { + client.putObject({ + Bucket: process.env.VUE_APP_COS_BUCKET, + /* 必须 */ + Region: process.env.VUE_APP_COS_REGION, + /* 存储桶所在地域,必须字段 */ + Key: fileName, + /* 必须 */ + StorageClass: 'STANDARD', + Body: file, // 上传文件对象 + onProgress: function (progressData) { + console.log('progress data:', progressData); + if (progressCB !== null) { + progressCB(progressData.percent * 100); + } + // console.log(JSON.stringify(progressData)); + } + }, function (err, data) { + console.log('err && data', err, data); + if (data && !err) { + callBack({ + fileCloudUrl: data.Location + }); + } + + console.log(err || data); + }); +}; + +export default uploadFileToCOS; diff --git a/web/dashboard/src/libs/oss.js b/web/dashboard/src/libs/oss.js index 9b4d058..6a79adc 100644 --- a/web/dashboard/src/libs/oss.js +++ b/web/dashboard/src/libs/oss.js @@ -18,7 +18,9 @@ const uploadFileToOSS = (file, fileName = '', callBack, progressCB = null) => { }); // 上传完成 let response = yield client.head(name); - callBack(response); + callBack({ + fileCloudUrl: response.res.requestUrls[0] + }); }).catch(() => { }); }; diff --git a/web/dashboard/src/views/rn/editPackage.vue b/web/dashboard/src/views/rn/editPackage.vue index b69a008..e9c6e7e 100644 --- a/web/dashboard/src/views/rn/editPackage.vue +++ b/web/dashboard/src/views/rn/editPackage.vue @@ -97,7 +97,7 @@