Skip to content
This repository was archived by the owner on Apr 10, 2022. It is now read-only.

[feature]添加了腾讯云的cos存储支持,并重构了oss上传方法 #21

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion web/dashboard/.env.development
Original file line number Diff line number Diff line change
Expand Up @@ -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 = ""
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 = ""
13 changes: 12 additions & 1 deletion web/dashboard/.env.production
Original file line number Diff line number Diff line change
Expand Up @@ -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 = ""
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 = ""
13 changes: 12 additions & 1 deletion web/dashboard/.env.test
Original file line number Diff line number Diff line change
Expand Up @@ -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 = ""
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 = ""
13 changes: 12 additions & 1 deletion web/dashboard/.env.uat
Original file line number Diff line number Diff line change
Expand Up @@ -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 = ""
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 = ""
1 change: 1 addition & 0 deletions web/dashboard/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
15 changes: 15 additions & 0 deletions web/dashboard/src/libs/cloud.js
Original file line number Diff line number Diff line change
@@ -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;
37 changes: 37 additions & 0 deletions web/dashboard/src/libs/cos.js
Original file line number Diff line number Diff line change
@@ -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;
4 changes: 3 additions & 1 deletion web/dashboard/src/libs/oss.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(() => {
});
};
Expand Down
6 changes: 3 additions & 3 deletions web/dashboard/src/views/rn/editPackage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@
<script>
import { isLogin, getApp, getAppId, getApps, switchApp } from '@/libs/account';
import {http, hasValue, fmtFileSize, getGUID, getFileName} from '@/libs/util';
import uploadFileToOSS from '@/libs/oss';
import uploadFileToCloud from '@/libs/cloud';

export default {
name: 'rn-edit',
Expand Down Expand Up @@ -285,9 +285,9 @@
let fileData = getFileName(file.name);
this.fileItem.name = `${this.appId}-${this.editForm.rnName}-${fileData.name}-${this.editForm.rnVersion}.${fileData.ext}`;
let guid = this.fileItem.guid;
uploadFileToOSS(file, this.fileItem.name, response => {
uploadFileToCloud(file, this.fileItem.name, response => {
if (guid !== this.fileItem.guid) return false;
this.editForm.resourceUrl = response.res.requestUrls[0];
this.editForm.resourceUrl = response.fileCloudUrl;
this.editForm.rnSize = file.size / 1024;
this.fileItem = {
name: '',
Expand Down
9 changes: 5 additions & 4 deletions web/dashboard/src/views/version/android/uploadApk.vue
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@ import {
getGUID,
hasValue
} from '@/libs/util';
import uploadFileToOSS from '@/libs/oss';
import uploadFileToCloud from '@/libs/cloud';

export default {
name: 'upload-apk',
props: {
Expand Down Expand Up @@ -206,16 +207,16 @@ export default {
}`;

/**
* 上传至OSS
* 上传至云存储
*/
uploadFileToOSS(
uploadFileToCloud(
file.file,
file.name,
response => {
/**
* 创建 Apk
*/
this.postApk(file, response.res.requestUrls[0]);
this.postApk(file, response.fileCloudUrl);
},
progress => {
file.percent = parseInt(progress) - 1 < 0 ? 0 : parseInt(progress) - 1;
Expand Down