Skip to content

Commit

Permalink
fix: fix_cos
Browse files Browse the repository at this point in the history
  • Loading branch information
dfounderliu committed Apr 8, 2020
1 parent e40432c commit 59ff692
Showing 1 changed file with 2 additions and 15 deletions.
17 changes: 2 additions & 15 deletions src/serverless.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,7 @@
const {Component} = require('@serverless/core')
const ensureObject = require('type/object/ensure')
const ensureIterable = require('type/iterable/ensure')
const ensureString = require('type/string/ensure')
const Cam = require('tencent-cloud-sdk').cam
const {Scf, Cos} = require('tencent-component-toolkit')

class Express extends Component {
async getUserInfo(credentials) {
const cam = new Cam(credentials)
return await cam.request({
Action: 'GetUserAppId',
Version: '2019-01-16'
})
}

getDefaultProtocol(protocols) {
if (String(protocols).includes('https')) {
return 'https'
Expand All @@ -29,7 +17,6 @@ class Express extends Component {

// 默认值
const region = inputs.region || "ap-guangzhou"
const userInfo = await this.getUserInfo(credentials)

const code = {}

Expand All @@ -41,7 +28,7 @@ class Express extends Component {
// 创建存储桶 + 设置生命周期
if (!inputs.src.bucket) {
await cos.deploy({
bucket: code.bucket + '-' + userInfo.Response.AppId,
bucket: code.bucket + '-' + credentials.tmpSecrets.appId,
force: true,
lifecycle: [
{
Expand All @@ -58,7 +45,7 @@ class Express extends Component {
// 上传代码
if (!inputs.src.object) {
await cos.upload({
bucket: code.bucket + '-' + userInfo.Response.AppId,
bucket: code.bucket + '-' + credentials.tmpSecrets.appId,
file: inputs.src.path || inputs.src,
key: code.object
})
Expand Down

0 comments on commit 59ff692

Please sign in to comment.