Compare commits
2 Commits
58e3caaf97
...
870ec3ba08
Author | SHA1 | Date |
---|---|---|
yutent | 870ec3ba08 | |
yutent | e82e727952 |
20
src/index.js
20
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
|
||||
*/
|
||||
policy(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',
|
||||
|
|
|
@ -37,7 +37,7 @@ export function getExt(str = '') {
|
|||
}
|
||||
|
||||
export function getMimeType(name) {
|
||||
var ext = getExt(name)
|
||||
let ext = getExt(name)
|
||||
return MIME_TYPES[ext] || DEFAULT_MIME_TYPE
|
||||
}
|
||||
|
||||
|
@ -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()
|
||||
|
|
Loading…
Reference in New Issue