import crypto from 'crypto-js'; import { encode, decode } from './base64.js'; import moment from 'moment' // 计算签名。 function computeSignature(accessKeySecret, canonicalString) { return crypto.enc.Base64.stringify(crypto.HmacSHA1(canonicalString, accessKeySecret)); } function getPolicy(){ const date = new Date(); date.setHours(date.getHours() + 1); const policyText = { expiration: date.toISOString(), // 设置policy过期时间。 conditions: [ // 限制上传大小。 ["content-length-range", 0, 1024 * 1024 * 1024], ], }; return policyText; } function getKey(i,ext){ let now=new Date(); let date=moment(now).format('yyyyMMDD'); let time=moment(now).format('HHmmss'); let longTime=moment(now).format('yyyyMMDDHHmmss'); let userId=JSON.parse(uni.getStorageSync('user')).id; return `${date}/${userId}/${time}/${longTime}${i}.${ext}` } module.exports={ computeSignature, getPolicy, getKey }