Skip to content

Commit

Permalink
fix: upyun token 生成逻辑
Browse files Browse the repository at this point in the history
  • Loading branch information
ATQQ committed Sep 30, 2024
1 parent 238fde4 commit 89a260b
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 14 deletions.
24 changes: 12 additions & 12 deletions packages/cli/upyun-token.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,19 +36,19 @@ function generateUpyunToken(operator, password, method, uriPrefix, expire) {
// 组合成要求的格式
return `UPYUN ${operator}:${token}`
}
function MD5(value) {
return crypto.createHash('md5').update(value).digest('hex')
}
// function MD5(value) {
// return crypto.createHash('md5').update(value).digest('hex')
// }

function tokenSign(operator, secret, method, uriPrefix, expire) {
const value = [method, uriPrefix, expire].filter(v => !!v).join('&')
const auth = hmacsha1(secret, value)
return `UPYUN ${operator}:${auth}`
}
// function tokenSign(operator, secret, method, uriPrefix, expire) {
// const value = [method, uriPrefix, expire].filter(v => !!v).join('&')
// const auth = hmacsha1(secret, value)
// return `UPYUN ${operator}:${auth}`
// }

function hmacsha1(secret, value) {
return crypto.createHmac('sha1', secret).update(value, 'utf8').digest().toString('base64')
}
// function hmacsha1(secret, value) {
// return crypto.createHmac('sha1', secret).update(value, 'utf8').digest().toString('base64')
// }

// 示例参数
const operator = process.env.UPYUN_OPERATOR
Expand All @@ -64,7 +64,7 @@ const domain = process.env.UPYUN_DOMAIN

const envToken = btoa(JSON.stringify({
// token: tokenSign(operator, MD5(password), method, uriPrefix, expire),
token: generateUpyunToken(operator, password, method, uriPrefix, expire),
token: generateUpyunToken(operator, password, method, uriPrefix, Math.round(expire / 1000)),
date: expire,
domain,
prefix,
Expand Down
2 changes: 1 addition & 1 deletion packages/client/src/components/ImageList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ const showImage = computed(() => {
</script>
<template>
<!-- 链接列表 -->
<p class="title">历史上传记录 ↓</p>
<p class="title">历史上传记录 ↓(本地存储)</p>
<ul class="el-upload-list el-upload-list--text">
<li class="el-upload-list__item" v-for="(image, idx) in showImage" :key="idx">
<div class="el-upload-list__item-info">
Expand Down
2 changes: 1 addition & 1 deletion packages/client/src/utils/upyun.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export async function uploadFile(file: File, ops: UPYunConfig) {
'Authorization': token,
'X-Date': new Date().toUTCString(),
'X-Upyun-Uri-Prefix': uriPrefix,
'X-Upyun-Expire': date,
'X-Upyun-Expire': Math.round(date / 1000),
}))
const key = await generateNewFileKey(file, prefix, scope)
// 测试逻辑
Expand Down

0 comments on commit 89a260b

Please sign in to comment.