irc_web/.svn/pristine/9c/9cf5d83b78c41158c4fc2a79a3d...

49 lines
1.6 KiB
Plaintext

const OSS = require('ali-oss')
import Vue from 'vue'
const { GenerateSTS } = require('../api/user.js')
import { getToken } from '@/utils/auth'
Vue.prototype.OSSclientConfig = {
}
let rOss
let t1, t2
let time = 1000
function timeout () {
t1 = setInterval(async () => {
var token = getToken()
if (token) {
let res = await GenerateSTS()
Vue.prototype.OSSclientConfig.region = res.Result.Region
Vue.prototype.OSSclientConfig.accessKeyId = res.Result.AccessKeyId
Vue.prototype.OSSclientConfig.accessKeySecret = res.Result.AccessKeySecret
Vue.prototype.OSSclientConfig.bucket = res.Result.BucketName
Vue.prototype.OSSclientConfig.basePath = res.Result.ViewEndpoint
Vue.prototype.OSSclientConfig.stsToken = res.Result.SecurityToken
Vue.prototype.OSSclient = new OSS(Vue.prototype.OSSclientConfig)
time = 60000 * 10
} else {
time = 1000
}
}, time)
}
async function ossGenerateSTS() {
let res = await GenerateSTS()
Vue.prototype.OSSclientConfig.region = res.Result.Region
Vue.prototype.OSSclientConfig.accessKeyId = res.Result.AccessKeyId
// Vue.prototype.OSSclientConfig.accessKeyId = 'mpXG7Nu6zTpsDrI1'
Vue.prototype.OSSclientConfig.accessKeySecret = res.Result.AccessKeySecret
// Vue.prototype.OSSclientConfig.accessKeySecret = 'yNINcEb099SkNfF6vYKaoP8TZNI3xZ'
Vue.prototype.OSSclientConfig.bucket = res.Result.BucketName
Vue.prototype.OSSclientConfig.basePath = res.Result.ViewEndpoint
Vue.prototype.OSSclientConfig.stsToken = res.Result.SecurityToken
Vue.prototype.OSSclient = new OSS(Vue.prototype.OSSclientConfig)
return rOss
}
export const OSSclient = ossGenerateSTS