Compare commits

..

No commits in common. "870ec3ba0812c1d1103eace0294d75c8410705ee" and "58e3caaf97afc3556f9995b44593ca3c76b74df4" have entirely different histories.

2 changed files with 13 additions and 13 deletions

View File

@ -27,7 +27,7 @@ export default class Alioss {
// 授权签名, 用于临时下载私有bucket的文件 // 授权签名, 用于临时下载私有bucket的文件
auth(key) { auth(key) {
let time = Math.floor(Date.now() / 1000) + 1800 // 半小时内 var time = Math.floor(Date.now() / 1000) + 1800 // 半小时内
return hmac( return hmac(
'SHA-1', 'SHA-1',
@ -47,14 +47,14 @@ export default class Alioss {
* size: 大小限制, 单位 MB 默认10MB * size: 大小限制, 单位 MB 默认10MB
*/ */
policy(dir = '', size = 10) { policy(dir = '', size = 10) {
let time = new Date() var time = new Date()
let params = { var params = {
conditions: [ conditions: [
['content-length-range', 0, Math.floor(1024 * 1024 * size)], ['content-length-range', 0, Math.floor(1024 * 1024 * size)],
['starts-with', '$key', dir ? dir.replace(/\/+$/, '') + '/' : ''] ['starts-with', '$key', dir ? dir.replace(/\/+$/, '') + '/' : '']
] ]
} }
let policy = '' var policy = ''
time.setTime(time.getTime() + 60 * 60 * 1000) // 60分钟内有效 time.setTime(time.getTime() + 60 * 60 * 1000) // 60分钟内有效
params.expiration = time.toISOString() params.expiration = time.toISOString()
@ -67,8 +67,8 @@ export default class Alioss {
} }
list({ prefix = '', delimiter = '/', max = 1000, token } = {}) { list({ prefix = '', delimiter = '/', max = 1000, token } = {}) {
let time = new Date().toGMTString() var time = new Date().toGMTString()
let query = { var query = {
'list-type': 2, 'list-type': 2,
prefix, prefix,
delimiter, delimiter,
@ -103,7 +103,7 @@ export default class Alioss {
* key: 要保存的文件名, 带完整路径 * key: 要保存的文件名, 带完整路径
*/ */
upload(auth, file, key) { upload(auth, file, key) {
let body = new FormData() var body = new FormData()
if (!file.type) { if (!file.type) {
let ext = file.name.split('.').pop() let ext = file.name.split('.').pop()
@ -124,8 +124,8 @@ export default class Alioss {
} }
copy(origin, target) { copy(origin, target) {
let time = new Date().toGMTString() var time = new Date().toGMTString()
let headers = { var headers = {
'x-oss-date': time, 'x-oss-date': time,
'x-oss-copy-source': `/${this.#bucket}/${encodeURIComponent(origin)}` 'x-oss-copy-source': `/${this.#bucket}/${encodeURIComponent(origin)}`
} }
@ -153,7 +153,7 @@ export default class Alioss {
} }
delete(key) { delete(key) {
let time = new Date().toGMTString() var time = new Date().toGMTString()
return hmac( return hmac(
'SHA-1', 'SHA-1',

View File

@ -37,7 +37,7 @@ export function getExt(str = '') {
} }
export function getMimeType(name) { export function getMimeType(name) {
let ext = getExt(name) var ext = getExt(name)
return MIME_TYPES[ext] || DEFAULT_MIME_TYPE return MIME_TYPES[ext] || DEFAULT_MIME_TYPE
} }
@ -49,12 +49,12 @@ export function fixFile(name, data) {
export function str2sign( export function str2sign(
method = 'GET', method = 'GET',
bucket, bucket,
{ time, contentType = '', headers = {}, key, query } = {} { time, headers = {}, key, query } = {}
) { ) {
let arr = [ let arr = [
method, method,
'', // 请求内容的md5值, 用于服务端校验文件是否完整. 可以为空 '', // 请求内容的md5值, 用于服务端校验文件是否完整. 可以为空
contentType, // 请求文件的content-type类型, 可以为空。不为空时, 注意表单提交时要统一 '', // 请求文件的content-type类型, 可以为空
time, time,
Object.keys(headers) Object.keys(headers)
.sort() .sort()