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的文件
|
// 授权签名, 用于临时下载私有bucket的文件
|
||||||
auth(key) {
|
auth(key) {
|
||||||
var time = Math.floor(Date.now() / 1000) + 1800 // 半小时内
|
let 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) {
|
||||||
var time = new Date()
|
let time = new Date()
|
||||||
var params = {
|
let 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(/\/+$/, '') + '/' : '']
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
var policy = ''
|
let 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 } = {}) {
|
||||||
var time = new Date().toGMTString()
|
let time = new Date().toGMTString()
|
||||||
var query = {
|
let 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) {
|
||||||
var body = new FormData()
|
let 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) {
|
||||||
var time = new Date().toGMTString()
|
let time = new Date().toGMTString()
|
||||||
var headers = {
|
let 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) {
|
||||||
var time = new Date().toGMTString()
|
let time = new Date().toGMTString()
|
||||||
|
|
||||||
return hmac(
|
return hmac(
|
||||||
'SHA-1',
|
'SHA-1',
|
||||||
|
|
|
@ -37,7 +37,7 @@ export function getExt(str = '') {
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getMimeType(name) {
|
export function getMimeType(name) {
|
||||||
var ext = getExt(name)
|
let 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, headers = {}, key, query } = {}
|
{ time, contentType = '', headers = {}, key, query } = {}
|
||||||
) {
|
) {
|
||||||
let arr = [
|
let arr = [
|
||||||
method,
|
method,
|
||||||
'', // 请求内容的md5值, 用于服务端校验文件是否完整. 可以为空
|
'', // 请求内容的md5值, 用于服务端校验文件是否完整. 可以为空
|
||||||
'', // 请求文件的content-type类型, 可以为空
|
contentType, // 请求文件的content-type类型, 可以为空。不为空时, 注意表单提交时要统一
|
||||||
time,
|
time,
|
||||||
Object.keys(headers)
|
Object.keys(headers)
|
||||||
.sort()
|
.sort()
|
||||||
|
|
Loading…
Reference in New Issue