diff --git a/src/index.js b/src/index.js index d9848b5..f02f863 100644 --- a/src/index.js +++ b/src/index.js @@ -27,7 +27,7 @@ export default class Alioss { // 授权签名, 用于临时下载私有bucket的文件 auth(key) { - var time = Math.floor(Date.now() / 1000) + 1800 // 半小时内 + let time = Math.floor(Date.now() / 1000) + 1800 // 半小时内 return hmac( 'SHA-1', @@ -47,14 +47,14 @@ export default class Alioss { * size: 大小限制, 单位 MB 默认10MB */ sign(dir = '', size = 10) { - var time = new Date() - var params = { + let time = new Date() + let params = { conditions: [ ['content-length-range', 0, Math.floor(1024 * 1024 * size)], ['starts-with', '$key', dir ? dir.replace(/\/+$/, '') + '/' : ''] ] } - var policy = '' + let policy = '' time.setTime(time.getTime() + 60 * 60 * 1000) // 60分钟内有效 params.expiration = time.toISOString() @@ -67,8 +67,8 @@ export default class Alioss { } list({ prefix = '', delimiter = '/', max = 1000, token } = {}) { - var time = new Date().toGMTString() - var query = { + let time = new Date().toGMTString() + let query = { 'list-type': 2, prefix, delimiter, @@ -103,7 +103,7 @@ export default class Alioss { * key: 要保存的文件名, 带完整路径 */ upload(auth, file, key) { - var body = new FormData() + let body = new FormData() if (!file.type) { let ext = file.name.split('.').pop() @@ -124,8 +124,8 @@ export default class Alioss { } copy(origin, target) { - var time = new Date().toGMTString() - var headers = { + let time = new Date().toGMTString() + let headers = { 'x-oss-date': time, 'x-oss-copy-source': `/${this.#bucket}/${encodeURIComponent(origin)}` } @@ -153,7 +153,7 @@ export default class Alioss { } delete(key) { - var time = new Date().toGMTString() + let time = new Date().toGMTString() return hmac( 'SHA-1', diff --git a/src/lib/helper.js b/src/lib/helper.js index ddfea92..dba80d2 100644 --- a/src/lib/helper.js +++ b/src/lib/helper.js @@ -49,12 +49,12 @@ export function fixFile(name, data) { export function str2sign( method = 'GET', bucket, - { time, headers = {}, key, query } = {} + { time, contentType = '', headers = {}, key, query } = {} ) { let arr = [ method, '', // 请求内容的md5值, 用于服务端校验文件是否完整. 可以为空 - '', // 请求文件的content-type类型, 可以为空 + contentType, // 请求文件的content-type类型, 可以为空。不为空时, 注意表单提交时要统一 time, Object.keys(headers) .sort()