Skip to content

Commit

Permalink
fix: queries sort in signatureUrl and add cases
Browse files Browse the repository at this point in the history
  • Loading branch information
zhengzuoyu.zzy authored and elwing63 committed Aug 16, 2024
1 parent c52bd5b commit b3cc7a0
Show file tree
Hide file tree
Showing 17 changed files with 600 additions and 295 deletions.
188 changes: 91 additions & 97 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1760,22 +1760,22 @@ store.put('ossdemo/demo.txt', filepath).then((result) => {
console.log(result);
});
{
name: 'ossdemo/demo.txt',
res: {
status: 200,
headers: {
date: 'Tue, 17 Feb 2015 13:28:17 GMT',
'content-length': '0',
connection: 'close',
etag: '"BF7A03DA01440845BC5D487B369BC168"',
server: 'AliyunOSS',
'x-oss-request-id': '54E341F1707AA0275E829244'
},
size: 0,
rt: 92
}
}
// {
// name: 'ossdemo/demo.txt',
// res: {
// status: 200,
// headers: {
// date: 'Tue, 17 Feb 2015 13:28:17 GMT',
// 'content-length': '0',
// connection: 'close',
// etag: '"BF7A03DA01440845BC5D487B369BC168"',
// server: 'AliyunOSS',
// 'x-oss-request-id': '54E341F1707AA0275E829244'
// },
// size: 0,
// rt: 92
// }
// }
```

- Add an object through content buffer
Expand All @@ -1785,23 +1785,23 @@ store.put('ossdemo/buffer', Buffer.from('foo content')).then((result) => {
console.log(result);
});
{
name: 'ossdemo/buffer',
url: 'http://demo.oss-cn-hangzhou.aliyuncs.com/ossdemo/buffer',
res: {
status: 200,
headers: {
date: 'Tue, 17 Feb 2015 13:28:17 GMT',
'content-length': '0',
connection: 'close',
etag: '"xxx"',
server: 'AliyunOSS',
'x-oss-request-id': '54E341F1707AA0275E829243'
},
size: 0,
rt: 92
}
}
// {
// name: 'ossdemo/buffer',
// url: 'http://demo.oss-cn-hangzhou.aliyuncs.com/ossdemo/buffer',
// res: {
// status: 200,
// headers: {
// date: 'Tue, 17 Feb 2015 13:28:17 GMT',
// 'content-length': '0',
// connection: 'close',
// etag: '"xxx"',
// server: 'AliyunOSS',
// 'x-oss-request-id': '54E341F1707AA0275E829243'
// },
// size: 0,
// rt: 92
// }
// }
```

- Add an object through readstream
Expand All @@ -1812,23 +1812,23 @@ store.put('ossdemo/readstream.txt', fs.createReadStream(filepath)).then((result)
console.log(result);
});
{
name: 'ossdemo/readstream.txt',
url: 'http://demo.oss-cn-hangzhou.aliyuncs.com/ossdemo/readstream.txt',
res: {
status: 200,
headers: {
date: 'Tue, 17 Feb 2015 13:28:17 GMT',
'content-length': '0',
connection: 'close',
etag: '"BF7A03DA01440845BC5D487B369BC168"',
server: 'AliyunOSS',
'x-oss-request-id': '54E341F1707AA0275E829242'
},
size: 0,
rt: 92
}
}
// {
// name: 'ossdemo/readstream.txt',
// url: 'http://demo.oss-cn-hangzhou.aliyuncs.com/ossdemo/readstream.txt',
// res: {
// status: 200,
// headers: {
// date: 'Tue, 17 Feb 2015 13:28:17 GMT',
// 'content-length': '0',
// connection: 'close',
// etag: '"BF7A03DA01440845BC5D487B369BC168"',
// server: 'AliyunOSS',
// 'x-oss-request-id': '54E341F1707AA0275E829242'
// },
// size: 0,
// rt: 92
// }
// }
```

### .putStream(name, stream[, options])
Expand Down Expand Up @@ -1883,23 +1883,23 @@ store.putStream('ossdemo/readstream.txt', fs.createReadStream(filepath)).then((r
console.log(result);
});
{
name: 'ossdemo/readstream.txt',
url: 'http://demo.oss-cn-hangzhou.aliyuncs.com/ossdemo/readstream.txt',
res: {
status: 200,
headers: {
date: 'Tue, 17 Feb 2015 13:28:17 GMT',
'content-length': '0',
connection: 'close',
etag: '"BF7A03DA01440845BC5D487B369BC168"',
server: 'AliyunOSS',
'x-oss-request-id': '54E341F1707AA0275E829242'
},
size: 0,
rt: 92
}
}
// {
// name: 'ossdemo/readstream.txt',
// url: 'http://demo.oss-cn-hangzhou.aliyuncs.com/ossdemo/readstream.txt',
// res: {
// status: 200,
// headers: {
// date: 'Tue, 17 Feb 2015 13:28:17 GMT',
// 'content-length': '0',
// connection: 'close',
// etag: '"BF7A03DA01440845BC5D487B369BC168"',
// server: 'AliyunOSS',
// 'x-oss-request-id': '54E341F1707AA0275E829242'
// },
// size: 0,
// rt: 92
// }
// }
```

### .append(name, file[, options])
Expand Down Expand Up @@ -2020,14 +2020,14 @@ await this.store.put('ossdemo/head-meta', Buffer.from('foo'), {
const object = await this.store.head('ossdemo/head-meta');
console.log(object);

{
status: 200,
meta: {
uid: '1',
path: 'foo/demo.txt'
},
res: { ... }
}
// {
// status: 200,
// meta: {
// uid: '1',
// path: 'foo/demo.txt'
// },
// res: { ... }
// }
```
- Head a not exists object
Expand Down Expand Up @@ -2065,10 +2065,10 @@ await this.store.put('ossdemo/object-meta', Buffer.from('foo'));
const object = await this.store.getObjectMeta('ossdemo/object-meta');
console.log(object);

{
status: 200,
res: { ... }
}
// {
// status: 200,
// res: { ... }
// }
```
### .get(name[, file, options])
Expand Down Expand Up @@ -3341,7 +3341,7 @@ parameters:
- file {String|File(only support Browser)|Blob(only support Browser)|Buffer} file path or HTML5 Web File or web Blob or content buffer
- [options] {Object} optional args
- [parallel] {Number} the number of parts to be uploaded in parallel
- [partSize] {Number} the suggested size for each part, defalut `1024 * 1024`(1MB), minimum `100 * 1024`(100KB)
- [partSize] {Number} the suggested size for each part, default `1024 * 1024`(1MB), minimum `100 * 1024`(100KB)
- [progress] {Function} function | async | Promise, the progress callback called after each
successful upload of one part, it will be given three parameters:
(percentage {Number}, checkpoint {Object}, res {Object})
Expand Down Expand Up @@ -3452,7 +3452,6 @@ const result2 = await store.multipartUpload('object', '/tmp/file', {
> tips: abort multipartUpload support on node and browser
```js
//start upload
let abortCheckpoint;
store.multipartUpload('object', '/tmp/file', {
Expand All @@ -3461,17 +3460,16 @@ store.multipartUpload('object', '/tmp/file', {
}
}).then(res => {
// do something
}.catch(err => {
}).catch(err => {
//if abort will catch abort event
if (err.name === 'abort') {
// handle abort
console.log('error: ', err.message)
}
}))
});
// abort
store.abortMultipartUpload(abortCheckpoint.name, abortCheckpoint.uploadId)
store.abortMultipartUpload(abortCheckpoint.name, abortCheckpoint.uploadId);
```
- multipartUpload with cancel
Expand Down Expand Up @@ -3624,8 +3622,7 @@ console.log(result);
- multipartUploadCopy with abort
```js
//start upload
// start upload
let abortCheckpoint;
store.multipartUploadCopy('object', {
sourceKey: 'sourceKey',
Expand All @@ -3636,18 +3633,17 @@ store.multipartUploadCopy('object', {
}
}).then(res => {
// do something
}.catch(err => {
}).catch(err => {
//if abort will catch abort event
if (err.name === 'abort') {
// handle abort
console.log('error: ', err.message)
}
}))
//the other event to abort, for example: click event
//to abort upload must use the same client instance
store.abortMultipartUpload(abortCheckpoint.name, abortCheckpoint.uploadId)
});
// the other event to abort, for example: click event
// to abort upload must use the same client instance
store.abortMultipartUpload(abortCheckpoint.name, abortCheckpoint.uploadId);
```
- multipartUploadCopy with cancel
Expand Down Expand Up @@ -4245,7 +4241,7 @@ const oss = require('ali-oss');
const imgClient = oss.ImageClient({
accessKeyId: 'your access key',
accessKeySecret: 'your access secret',
bucket: 'my_image_bucket'
bucket: 'my_image_bucket',
imageHost: 'thumbnail.myimageservice.com'
});
```
Expand Down Expand Up @@ -4616,9 +4612,7 @@ Success will return full signature url.
example:
```js
const url = imgClient.signatureUrl('
');
// http://thumbnail.myimageservice.com/demo.jpg@200w_200h?OSSAccessKeyId=uZxyLARzYZtGwHKY&Expires=1427803849&Signature=JSPRe06%2FjQpQSj5zlx2ld1V%2B35I%3D
const url = imgClient.signatureUrl('name');
```
## Cluster Mode
Expand Down
10 changes: 5 additions & 5 deletions lib/browser/managed-upload.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ const proto = exports;
* @param {String} name
* @param {String|File|Buffer} file
* @param {Object} options
* {Object} options.callback The callback parameter is composed of a JSON string encoded in Base64
* {Object} [options.callback] The callback parameter is composed of a JSON string encoded in Base64
* {String} options.callback.url the OSS sends a callback request to this URL
* {String} options.callback.host The host header value for initiating callback requests
* {String} [options.callback.host] The host header value for initiating callback requests
* {String} options.callback.body The value of the request body when a callback is initiated
* {String} options.callback.contentType The Content-Type of the callback requests initiatiated
* {Boolean} options.callback.callbackSNI Do you want to send the Server Name Indication
* {Object} options.callback.customValue Custom parameters are a map of key-values, e.g:
* {String} [options.callback.contentType] The Content-Type of the callback requests initiated
* {Boolean} [options.callback.callbackSNI] Whether OSS sends SNI to the origin address specified by callbackUrl when a callback request is initiated from the client
* {Object} [options.callback.customValue] Custom parameters are a map of key-values, e.g:
* customValue = {
* key1: 'value1',
* key2: 'value2'
Expand Down
9 changes: 5 additions & 4 deletions lib/browser/object.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,13 @@ proto.append = async function append(name, file, options) {
* @param {String} name the object key
* @param {Mixed} file String(file path)/Buffer/ReadableStream
* @param {Object} options
* {Object} options.callback The callback parameter is composed of a JSON string encoded in Base64
* {Object} [options.callback] The callback parameter is composed of a JSON string encoded in Base64
* {String} options.callback.url the OSS sends a callback request to this URL
* {String} options.callback.host The host header value for initiating callback requests
* {String} [options.callback.host] The host header value for initiating callback requests
* {String} options.callback.body The value of the request body when a callback is initiated
* {String} options.callback.contentType The Content-Type of the callback requests initiatiated
* {Object} options.callback.customValue Custom parameters are a map of key-values, e.g:
* {String} [options.callback.contentType] The Content-Type of the callback requests initiated
* {Boolean} [options.callback.callbackSNI] Whether OSS sends SNI to the origin address specified by callbackUrl when a callback request is initiated from the client
* {Object} [options.callback.customValue] Custom parameters are a map of key-values, e.g:
* customValue = {
* key1: 'value1',
* key2: 'value2'
Expand Down
30 changes: 15 additions & 15 deletions lib/common/bucket/putBucketLifecycle.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ function checkDaysAndDate(obj, key) {
const { days, createdBeforeDate } = obj;
if (!days && !createdBeforeDate) {
throw new Error(`${key} must includes days or createdBeforeDate`);
} else if (days && !/^[1-9][0-9]*$/.test(days)) {
} else if (days && (isArray(days) || !/^[1-9][0-9]*$/.test(days))) {
throw new Error('days must be a positive integer');
} else if (createdBeforeDate && !/\d{4}-\d{2}-\d{2}T00:00:00.000Z/.test(createdBeforeDate)) {
throw new Error('createdBeforeDate must be date and conform to iso8601 format');
Expand All @@ -77,7 +77,7 @@ function checkNoncurrentDays(obj, key) {
const { noncurrentDays } = obj;
if (!noncurrentDays) {
throw new Error(`${key} must includes noncurrentDays`);
} else if (noncurrentDays && !/^[1-9][0-9]*$/.test(noncurrentDays)) {
} else if (noncurrentDays && (isArray(noncurrentDays) || !/^[1-9][0-9]*$/.test(noncurrentDays))) {
throw new Error('noncurrentDays must be a positive integer');
}
}
Expand Down Expand Up @@ -106,7 +106,19 @@ function checkRule(rule) {

if (rule.prefix === undefined) throw new Error('Rule must includes prefix');

if (!['Enabled', 'Disabled'].includes(rule.status)) throw new Error('Status must be Enabled or Disabled');
if (!['Enabled', 'Disabled'].includes(rule.status)) throw new Error('Status must be Enabled or Disabled');

if (
!rule.expiration &&
!rule.noncurrentVersionExpiration &&
!rule.abortMultipartUpload &&
!rule.transition &&
!rule.noncurrentVersionTransition
) {
throw new Error(
'Rule must includes expiration or noncurrentVersionExpiration or abortMultipartUpload or transition or noncurrentVersionTransition'
);
}

if (rule.transition) {
checkStorageClass(rule.transition.storageClass);
Expand All @@ -125,18 +137,6 @@ function checkRule(rule) {
checkDaysAndDate(rule.abortMultipartUpload, 'AbortMultipartUpload');
}

if (
!rule.expiration &&
!rule.noncurrentVersionExpiration &&
!rule.abortMultipartUpload &&
!rule.transition &&
!rule.noncurrentVersionTransition
) {
throw new Error(
'Rule must includes expiration or noncurrentVersionExpiration or abortMultipartUpload or transition or noncurrentVersionTransition'
);
}

if (rule.noncurrentVersionTransition) {
checkStorageClass(rule.noncurrentVersionTransition.storageClass);
checkNoncurrentDays(rule.noncurrentVersionTransition, 'NoncurrentVersionTransition');
Expand Down
Loading

0 comments on commit b3cc7a0

Please sign in to comment.