|
|
@@ -18,6 +18,10 @@
|
|
|
// #ifdef APP-PLUS
|
|
|
|
|
|
//#endif
|
|
|
+
|
|
|
+
|
|
|
+import getFileAccessUrl from "@/js_sdk/tencentcloud-plugin-cos/get-file-access-url";
|
|
|
+
|
|
|
console.log('COS加载js版本')
|
|
|
import COS from "cos-js-sdk-v5"
|
|
|
// import COS from "./cos-wx-sdk-v5.min"
|
|
|
@@ -25,6 +29,7 @@ import COS from "cos-js-sdk-v5"
|
|
|
// import COS from "cos-nodejs-sdk-v5"
|
|
|
import tools from "./tools";
|
|
|
import {getTxySts} from "@/api/common";
|
|
|
+import {secretId, secretKey} from "@/uniCloud-aliyun/cloudfunctions/tencentcloud-plugin/config";
|
|
|
|
|
|
|
|
|
|
|
|
@@ -35,43 +40,40 @@ let Bucket = 'icoco-1317650740';
|
|
|
let Region = 'ap-guangzhou';
|
|
|
|
|
|
let cos=null;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 获取sts权限信息
|
|
|
+ * @returns {Promise<*>}
|
|
|
+ */
|
|
|
+ async function getSts(){
|
|
|
+ let cosToken=tools.getCosToken()
|
|
|
+ if(!cosToken) {
|
|
|
+ let res =await getTxySts()
|
|
|
+ if(res.code===0){
|
|
|
+ tools.setCosToken(res.data)
|
|
|
+ setTimeout(()=>{
|
|
|
+ cos=null
|
|
|
+ tools.delCosToken()
|
|
|
+ },(res.data.expiredTime-res.data.startTime))
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return cosToken
|
|
|
+}
|
|
|
+
|
|
|
function startCos(){
|
|
|
console.log('startCos-----------------')
|
|
|
cos = new COS({
|
|
|
- getAuthorization: function (options, callback) {
|
|
|
+ getAuthorization:async function (options, callback) {
|
|
|
console.log('---------------获取初始化信息')
|
|
|
- let cosToken=tools.getCosToken()
|
|
|
+ let cosToken= await getSts()
|
|
|
console.log(cosToken)
|
|
|
- if(cosToken){
|
|
|
- callback({
|
|
|
- TmpSecretId: cosToken.credentials.tmpSecretId,
|
|
|
- TmpSecretKey: cosToken.credentials.tmpSecretKey,
|
|
|
- XCosSecurityToken: cosToken.credentials.sessionToken,
|
|
|
- StartTime: cosToken.startTime*1, // 时间戳,单位秒,如:1580000000,建议返回服务器时间作为签名的开始时间,避免用户浏览器本地时间偏差过大导致签名错误
|
|
|
- ExpiredTime: cosToken.expiredTime*1, // 时间戳,单位秒,如:1580000900
|
|
|
- })
|
|
|
- }else {
|
|
|
- getTxySts().then((res)=>{
|
|
|
-
|
|
|
- console.log('---------------获取初始化信息')
|
|
|
- if(res.code===0){
|
|
|
- tools.setCosToken(res.data)
|
|
|
- callback({
|
|
|
- TmpSecretId: res.data.credentials.tmpSecretId,
|
|
|
- TmpSecretKey: res.data.credentials.tmpSecretKey,
|
|
|
- XCosSecurityToken: res.data.credentials.sessionToken,
|
|
|
- StartTime: res.data.startTime*1, // 时间戳,单位秒,如:1580000000,建议返回服务器时间作为签名的开始时间,避免用户浏览器本地时间偏差过大导致签名错误
|
|
|
- ExpiredTime: res.data.expiredTime*1, // 时间戳,单位秒,如:1580000900
|
|
|
- })
|
|
|
- setTimeout(()=>{
|
|
|
- cos=null
|
|
|
- tools.delCosToken()
|
|
|
- },(res.data.expiredTime-res.data.startTime))
|
|
|
- }
|
|
|
- })
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
+ callback({
|
|
|
+ TmpSecretId: cosToken.credentials.tmpSecretId,
|
|
|
+ TmpSecretKey: cosToken.credentials.tmpSecretKey,
|
|
|
+ XCosSecurityToken: cosToken.credentials.sessionToken,
|
|
|
+ StartTime: cosToken.startTime*1, // 时间戳,单位秒,如:1580000000,建议返回服务器时间作为签名的开始时间,避免用户浏览器本地时间偏差过大导致签名错误
|
|
|
+ ExpiredTime: cosToken.expiredTime*1, // 时间戳,单位秒,如:1580000900
|
|
|
+ })
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
@@ -123,6 +125,20 @@ cosServe.txUploadFile=function (file,folder){
|
|
|
|
|
|
}
|
|
|
|
|
|
+cosServe.getSignObject=async function (url){
|
|
|
+ if(!url){
|
|
|
+ return ''
|
|
|
+ }
|
|
|
+
|
|
|
+ console.log(url)
|
|
|
+ url= url.replace('https://','')
|
|
|
+ url= url.replace('http://','')
|
|
|
+ url= url.replace('icoco-1317650740.cos.ap-guangzhou.myqcloud.com/','')
|
|
|
+ let signUrl = await getFileAccessUrl(url);
|
|
|
+ console.log(signUrl)
|
|
|
+ return signUrl
|
|
|
+
|
|
|
+}
|
|
|
|
|
|
cosServe.getSignUrl= function (url){
|
|
|
if(!url){
|