Skip to content

Commit 3c4da70

Browse files
authored
Merge pull request #1344 from ali-sdk/master
chore:6.22.0
2 parents bf82680 + ac7c817 commit 3c4da70

26 files changed

+957
-152
lines changed

CHANGELOG.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,18 @@
22

33
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
44

5+
## [6.22.0](https://github.com/ali-sdk/ali-oss/compare/v6.21.0...v6.22.0) (2024-11-29)
6+
7+
### Features
8+
9+
* list object functions support return restore info ([#1339](https://github.com/ali-sdk/ali-oss/issues/1339)) ([986b743](https://github.com/ali-sdk/ali-oss/commit/986b7432f06b216eea24ae0f7b437aaf8786a3d4))
10+
* support restore Deep Cold Archive object ([#1337](https://github.com/ali-sdk/ali-oss/issues/1337)) ([ac500d3](https://github.com/ali-sdk/ali-oss/commit/ac500d3d87a911ec359d9ba781006034a78c1db2))
11+
* support PostObject policy V4 signature and restore archive object with setting of days ([#1340](https://github.com/ali-sdk/ali-oss/issues/1340)) ([ca8c027](https://github.com/ali-sdk/ali-oss/commit/ca8c027264a875e56f2740fa88b45dd562c2b809))
12+
13+
### Bug Fixes
14+
15+
* fix requestError return null and signatureUrlV4 run in Node 8.x ([#1338](https://github.com/ali-sdk/ali-oss/issues/1338)) ([439ffde](https://github.com/ali-sdk/ali-oss/commit/439ffded0bf9f8b9e73bed9a917d5265b80e8286))
16+
517
## [6.21.0](https://github.com/ali-sdk/ali-oss/compare/v6.20.0...v6.21.0) (2024-08-16)
618

719
### Features

README.md

Lines changed: 128 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,7 @@ Node.js >= 8.0.0 required. You can use 4.x in Node.js < 8.
4242

4343
### QA
4444

45-
You can join DingDing Talk Group, [Group Link](https://qr.dingtalk.com/action/joingroup?code=v1,k1,E60EuCmxajfilkaR/kknRcGR9UissskPEXu/1td36z0=)
46-
47-
<img src="task/dingding.jpg" height="400" title="dingding" width="300">
45+
Please log in to the official website and contact technical support.
4846

4947
## License
5048

@@ -144,8 +142,8 @@ All operation use es7 async/await to implement. All api is async function.
144142
- [.copy(name, sourceName[, sourceBucket, options])](#copyname-sourcename-sourcebucket-options)
145143
- [.putMeta(name, meta[, options])](#putmetaname-meta-options)
146144
- [.deleteMulti(names[, options])](#deletemultinames-options)
147-
- [.signatureUrl(name[, options])](#signatureurlname-options)
148-
- [.asyncSignatureUrl(name[, options])](#signatureurlname-options)
145+
- [.signatureUrl(name[, options, strictObjectNameValidation])](#signatureurlname-options-strictobjectnamevalidation)
146+
- [.asyncSignatureUrl(name[, options, strictObjectNameValidation])](#asyncsignatureurlname-options-strictobjectnamevalidation)
149147
- [.signatureUrlV4(method, expires[, request, objectName, additionalHeaders])](#signatureurlv4method-expires-request-objectname-additionalheaders)
150148
- [.putACL(name, acl[, options])](#putaclname-acl-options)
151149
- [.getACL(name[, options])](#getaclname-options)
@@ -162,6 +160,7 @@ All operation use es7 async/await to implement. All api is async function.
162160
- [.listUploads(query[, options])](#listuploadsquery-options)
163161
- [.abortMultipartUpload(name, uploadId[, options])](#abortmultipartuploadname-uploadid-options)
164162
- [.calculatePostSignature(policy)](#calculatePostSignaturepolicy)
163+
- [.signPostObjectPolicyV4(policy, date)](#signpostobjectpolicyv4policy-date)
165164
- [.getObjectTagging(name, [, options])](#getObjectTaggingname-options)
166165
- [.putObjectTagging(name, tag[, options])](#putObjectTaggingname-tag-options)
167166
- [.deleteObjectTagging(name, [, options])](#deleteObjectTaggingname-options)
@@ -2449,6 +2448,9 @@ Success will return objects list on `objects` properties.
24492448
- size {Number} object size, e.g.: `344606`
24502449
- storageClass {String} storage class type, e.g.: `Standard`
24512450
- owner {Object} object owner, including `id` and `displayName`
2451+
- restoreInfo {Object|undefined} The restoration status of the object
2452+
- ongoingRequest {Boolean} Whether the restoration is ongoing
2453+
- expireDate {Date|undefined} The time before which the restored object can be read
24522454
- prefixes {Array<String>} prefix list
24532455
- isTruncated {Boolean} truncate or not
24542456
- nextMarker {String} next marker string
@@ -2515,6 +2517,9 @@ Success will return objects list on `objects` properties.
25152517
- size {Number} object size, e.g.: `344606`
25162518
- storageClass {String} storage class type, e.g.: `Standard`
25172519
- owner {Object|null} object owner, including `id` and `displayName`
2520+
- restoreInfo {Object|undefined} The restoration status of the object
2521+
- ongoingRequest {Boolean} Whether the restoration is ongoing
2522+
- expireDate {Date|undefined} The time before which the restored object can be read
25182523
- prefixes {Array<String>} prefix list
25192524
- isTruncated {Boolean} truncate or not
25202525
- nextContinuationToken {String} next continuation-token string
@@ -2595,6 +2600,9 @@ Success will return objects list on `objects` properties.
25952600
- versionId {String} object versionId
25962601
- storageClass {String} storage class type, e.g.: `Standard`
25972602
- owner {Object} object owner, including `id` and `displayName`
2603+
- restoreInfo {Object|undefined} The restoration status of the object
2604+
- ongoingRequest {Boolean} Whether the restoration is ongoing
2605+
- expireDate {Date|undefined} The time before which the restored object can be read
25982606
- deleteMarker {Array<ObjectDeleteMarker>} object delete marker info list
25992607
Each `ObjectDeleteMarker`
26002608
- name {String} object name on oss
@@ -2954,6 +2962,8 @@ parameters:
29542962
- [timeout] {Number} the operation timeout
29552963
- [versionId] {String} the version id of history object
29562964
- [type] {String} the default type is Archive
2965+
- [Days] {number} The duration within which the object remains in the restored state. The default value is 2.
2966+
- [JobParameters] {string} The container that stores the restoration priority. This parameter is valid only when you restore Cold Archive or Deep Cold Archive objects. The default value is Standard.
29572967
29582968
Success will return:
29592969
@@ -2965,27 +2975,54 @@ Success will return:
29652975
29662976
example:
29672977
2968-
- Restore an object with Archive type
2978+
- Restore an Archive object
29692979
29702980
```js
29712981
const result = await store.restore('ossdemo.txt');
29722982
console.log(result.status);
29732983
```
29742984
2975-
- Restore an object with ColdArchive type
2985+
- Restore a Cold Archive object
29762986
29772987
```js
29782988
const result = await store.restore('ossdemo.txt', { type: 'ColdArchive' });
29792989
console.log(result.status);
29802990
```
29812991
2982-
- Days for unfreezing Specifies the days for unfreezing
2992+
- Restore a Cold Archive object with Days
29832993
29842994
```js
29852995
const result = await store.restore('ossdemo.txt', { type: 'ColdArchive', Days: 2 });
29862996
console.log(result.status);
29872997
```
29882998
2999+
- Restore a Cold Archive object with Days and JobParameters
3000+
```js
3001+
const result = await store.restore('ossdemo.txt', { type: 'ColdArchive', Days: 2, JobParameters: 'Standard' });
3002+
console.log(result.status);
3003+
```
3004+
3005+
- Restore a Deep Cold Archive object
3006+
3007+
```js
3008+
const result = await store.restore('ossdemo.txt', { type: 'DeepColdArchive' });
3009+
console.log(result.status);
3010+
```
3011+
3012+
- Restore a Deep Cold Archive object with Days
3013+
3014+
```js
3015+
const result = await store.restore('ossdemo.txt', { type: 'DeepColdArchive', Days: 2 });
3016+
console.log(result.status);
3017+
```
3018+
3019+
- Restore a Deep Cold Archive object with Days and JobParameters
3020+
3021+
```js
3022+
const result = await store.restore('ossdemo.txt', { type: 'DeepColdArchive', Days: 2, JobParameters: 'Standard' });
3023+
console.log(result.status);
3024+
```
3025+
29893026
- Restore an history object
29903027
29913028
```js
@@ -3816,6 +3853,89 @@ Object:
38163853
- Signature {String}
38173854
- policy {Object} response info
38183855
3856+
### .signPostObjectPolicyV4(policy, date)
3857+
3858+
Get a V4 signature of the PostObject request.
3859+
3860+
parameters:
3861+
3862+
- policy {string | Object} The policy form field in a PostObject request is used to specify the expiration time and conditions of the PostObject request that you initiate to upload an object by using an HTML form. The value of the policy form field is a JSON string or an object.
3863+
- date {Date} The time when the request was initiated.
3864+
3865+
Success will return a V4 signature of the PostObject request.
3866+
3867+
example:
3868+
3869+
```js
3870+
const axios = require('axios');
3871+
const dateFormat = require('dateformat');
3872+
const FormData = require('form-data');
3873+
const { getCredential } = require('ali-oss/lib/common/signUtils');
3874+
const { getStandardRegion } = require('ali-oss/lib/common/utils/getStandardRegion');
3875+
const { policy2Str } = require('ali-oss/lib/common/utils/policy2Str');
3876+
const OSS = require('ali-oss');
3877+
3878+
const client = new OSS({
3879+
accessKeyId: 'yourAccessKeyId',
3880+
accessKeySecret: 'yourAccessKeySecret',
3881+
stsToken: 'yourSecurityToken',
3882+
bucket: 'yourBucket',
3883+
region: 'oss-cn-hangzhou'
3884+
});
3885+
const name = 'yourObjectName';
3886+
const formData = new FormData();
3887+
formData.append('key', name);
3888+
formData.append('Content-Type', 'yourObjectContentType');
3889+
// your object cache control
3890+
formData.append('Cache-Control', 'max-age=30');
3891+
const url = client.generateObjectUrl(name).replace(name, '');
3892+
const date = new Date();
3893+
// The expiration parameter specifies the expiration time of the request.
3894+
const expirationDate = new Date(date);
3895+
expirationDate.setMinutes(date.getMinutes() + 1);
3896+
// The time must follow the ISO 8601 standard
3897+
const formattedDate = dateFormat(date, "UTC:yyyymmdd'T'HHMMss'Z'");
3898+
const credential = getCredential(formattedDate.split('T')[0], getStandardRegion(client.options.region), client.options.accessKeyId);
3899+
formData.append('x-oss-date', formattedDate);
3900+
formData.append('x-oss-credential', credential);
3901+
formData.append('x-oss-signature-version', 'OSS4-HMAC-SHA256');
3902+
const policy = {
3903+
expiration: expirationDate.toISOString(),
3904+
conditions: [
3905+
{ bucket: client.options.bucket },
3906+
{'x-oss-credential': credential},
3907+
{'x-oss-date': formattedDate},
3908+
{'x-oss-signature-version': 'OSS4-HMAC-SHA256'},
3909+
['content-length-range', 1, 10],
3910+
['eq', '$success_action_status', '200'],
3911+
['starts-with', '$key', 'yourObjectName'],
3912+
['in', '$content-type', ['image/jpg', 'text/plain']],
3913+
['not-in', '$cache-control', ['no-cache']]
3914+
]
3915+
};
3916+
3917+
if (client.options.stsToken) {
3918+
policy.conditions.push({'x-oss-security-token': client.options.stsToken});
3919+
formData.append('x-oss-security-token', client.options.stsToken);
3920+
}
3921+
3922+
const signature = client.signPostObjectPolicyV4(policy, date);
3923+
formData.append('policy', Buffer.from(policy2Str(policy), 'utf8').toString('base64'));
3924+
formData.append('x-oss-signature', signature);
3925+
formData.append('success_action_status', '200');
3926+
formData.append('file', 'yourFileContent');
3927+
3928+
axios.post(url, formData, {
3929+
headers: {
3930+
'Content-Type': 'multipart/form-data'
3931+
}
3932+
}).then((result) => {
3933+
console.log(result.status);
3934+
}).catch((e) => {
3935+
console.log(e);
3936+
});
3937+
```
3938+
38193939
### .getObjectTagging(name[, options])
38203940
38213941
Obtains the tags of an object.

karma.conf.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ module.exports = function (config) {
3434
concurrency: 1,
3535
client: {
3636
mocha: {
37-
timeout: 6000
37+
timeout: 15000
3838
}
3939
}
4040
});

lib/browser/client.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -400,7 +400,7 @@ proto.requestError = async function requestError(result) {
400400
this.debug(message, 'error');
401401
error.message += `\nraw xml: ${message}`;
402402
error.status = result.status;
403-
error.requestId = result.headers['x-oss-request-id'];
403+
error.requestId = result.headers && result.headers['x-oss-request-id'];
404404
return error;
405405
}
406406

@@ -416,6 +416,7 @@ proto.requestError = async function requestError(result) {
416416
err.requestId = info.RequestId;
417417
err.hostId = info.HostId;
418418
err.serverTime = info.ServerTime;
419+
return err;
419420
};
420421

421422
if (!result.data || !result.data.length) {
@@ -442,20 +443,20 @@ proto.requestError = async function requestError(result) {
442443
err.name = 'UnknownError';
443444
err.status = result.status;
444445
err.res = result;
445-
const ossErr = result.headers['x-oss-err'];
446+
const ossErr = result.headers && result.headers['x-oss-err'];
446447
if (ossErr) {
447448
const message = atob(ossErr);
448-
await setError(message);
449+
err = await setError(message);
449450
}
450451
}
451-
err.requestId = result.headers['x-oss-request-id'];
452+
err.requestId = result.headers && result.headers['x-oss-request-id'];
452453
err.host = '';
453454
}
454455
} else {
455456
const message = String(result.data);
456457
this.debug('request response error data: %s', message, 'error');
457458

458-
await setError(message);
459+
err = await setError(message);
459460
}
460461

461462
this.debug('generate error %j', err, 'error');

lib/browser/object.js

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ const { isBlob } = require('../common/utils/isBlob');
99
const { isFile } = require('../common/utils/isFile');
1010
const { isBuffer } = require('../common/utils/isBuffer');
1111
const { obj2xml } = require('../common/utils/obj2xml');
12+
const { parseRestoreInfo } = require('../common/utils/parseRestoreInfo');
1213

1314
// var assert = require('assert');
1415

@@ -166,6 +167,7 @@ merge(proto, require('../common/object/generateObjectUrl'));
166167
merge(proto, require('../common/object/signatureUrl'));
167168
merge(proto, require('../common/object/asyncSignatureUrl'));
168169
merge(proto, require('../common/object/signatureUrlV4'));
170+
merge(proto, require('../common/object/signPostObjectPolicyV4'));
169171

170172
proto.putMeta = async function putMeta(name, meta, options) {
171173
const copyResult = await this.copy(name, name, {
@@ -191,6 +193,7 @@ proto.list = async function list(query, options) {
191193
if (!Array.isArray(objects)) {
192194
objects = [objects];
193195
}
196+
194197
objects = objects.map(obj => ({
195198
name: obj.Key,
196199
url: that._objectUrl(obj.Key),
@@ -202,7 +205,8 @@ proto.list = async function list(query, options) {
202205
owner: {
203206
id: obj.Owner.ID,
204207
displayName: obj.Owner.DisplayName
205-
}
208+
},
209+
restoreInfo: parseRestoreInfo(obj.RestoreInfo)
206210
}));
207211
}
208212
let prefixes = result.data.CommonPrefixes || null;
@@ -245,6 +249,7 @@ proto.listV2 = async function listV2(query, options = {}) {
245249
if (!Array.isArray(objects)) {
246250
objects = [objects];
247251
}
252+
248253
objects = objects.map(obj => {
249254
let owner = null;
250255
if (obj.Owner) {
@@ -261,7 +266,8 @@ proto.listV2 = async function listV2(query, options = {}) {
261266
type: obj.Type,
262267
size: Number(obj.Size),
263268
storageClass: obj.StorageClass,
264-
owner
269+
owner,
270+
restoreInfo: parseRestoreInfo(obj.RestoreInfo)
265271
};
266272
});
267273
}
@@ -296,20 +302,22 @@ proto.restore = async function restore(name, options = { type: 'Archive' }) {
296302
options.subres.versionId = options.versionId;
297303
}
298304
const params = this._objectRequestParams('POST', name, options);
299-
if (options.type === 'ColdArchive') {
300-
const paramsXMLObj = {
301-
RestoreRequest: {
302-
Days: options.Days ? options.Days : 2,
303-
JobParameters: {
304-
Tier: options.JobParameters ? options.JobParameters : 'Standard'
305-
}
306-
}
305+
const paramsXMLObj = {
306+
RestoreRequest: {
307+
Days: options.Days ? options.Days : 2
308+
}
309+
};
310+
311+
if (options.type === 'ColdArchive' || options.type === 'DeepColdArchive') {
312+
paramsXMLObj.RestoreRequest.JobParameters = {
313+
Tier: options.JobParameters ? options.JobParameters : 'Standard'
307314
};
308-
params.content = obj2xml(paramsXMLObj, {
309-
headers: true
310-
});
311-
params.mime = 'xml';
312315
}
316+
317+
params.content = obj2xml(paramsXMLObj, {
318+
headers: true
319+
});
320+
params.mime = 'xml';
313321
params.successStatuses = [202];
314322

315323
const result = await this.request(params);

0 commit comments

Comments
 (0)