Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore:6.22.0 #1344

Merged
merged 8 commits into from
Dec 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,18 @@

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.

## [6.22.0](https://github.com/ali-sdk/ali-oss/compare/v6.21.0...v6.22.0) (2024-11-29)

### Features

* 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))
* 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))
* 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))

### Bug Fixes

* 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))

## [6.21.0](https://github.com/ali-sdk/ali-oss/compare/v6.20.0...v6.21.0) (2024-08-16)

### Features
Expand Down
136 changes: 128 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,7 @@ Node.js >= 8.0.0 required. You can use 4.x in Node.js < 8.

### QA

You can join DingDing Talk Group, [Group Link](https://qr.dingtalk.com/action/joingroup?code=v1,k1,E60EuCmxajfilkaR/kknRcGR9UissskPEXu/1td36z0=)

<img src="task/dingding.jpg" height="400" title="dingding" width="300">
Please log in to the official website and contact technical support.

## License

Expand Down Expand Up @@ -144,8 +142,8 @@ All operation use es7 async/await to implement. All api is async function.
- [.copy(name, sourceName[, sourceBucket, options])](#copyname-sourcename-sourcebucket-options)
- [.putMeta(name, meta[, options])](#putmetaname-meta-options)
- [.deleteMulti(names[, options])](#deletemultinames-options)
- [.signatureUrl(name[, options])](#signatureurlname-options)
- [.asyncSignatureUrl(name[, options])](#signatureurlname-options)
- [.signatureUrl(name[, options, strictObjectNameValidation])](#signatureurlname-options-strictobjectnamevalidation)
- [.asyncSignatureUrl(name[, options, strictObjectNameValidation])](#asyncsignatureurlname-options-strictobjectnamevalidation)
- [.signatureUrlV4(method, expires[, request, objectName, additionalHeaders])](#signatureurlv4method-expires-request-objectname-additionalheaders)
- [.putACL(name, acl[, options])](#putaclname-acl-options)
- [.getACL(name[, options])](#getaclname-options)
Expand All @@ -162,6 +160,7 @@ All operation use es7 async/await to implement. All api is async function.
- [.listUploads(query[, options])](#listuploadsquery-options)
- [.abortMultipartUpload(name, uploadId[, options])](#abortmultipartuploadname-uploadid-options)
- [.calculatePostSignature(policy)](#calculatePostSignaturepolicy)
- [.signPostObjectPolicyV4(policy, date)](#signpostobjectpolicyv4policy-date)
- [.getObjectTagging(name, [, options])](#getObjectTaggingname-options)
- [.putObjectTagging(name, tag[, options])](#putObjectTaggingname-tag-options)
- [.deleteObjectTagging(name, [, options])](#deleteObjectTaggingname-options)
Expand Down Expand Up @@ -2449,6 +2448,9 @@ Success will return objects list on `objects` properties.
- size {Number} object size, e.g.: `344606`
- storageClass {String} storage class type, e.g.: `Standard`
- owner {Object} object owner, including `id` and `displayName`
- restoreInfo {Object|undefined} The restoration status of the object
- ongoingRequest {Boolean} Whether the restoration is ongoing
- expireDate {Date|undefined} The time before which the restored object can be read
- prefixes {Array<String>} prefix list
- isTruncated {Boolean} truncate or not
- nextMarker {String} next marker string
Expand Down Expand Up @@ -2515,6 +2517,9 @@ Success will return objects list on `objects` properties.
- size {Number} object size, e.g.: `344606`
- storageClass {String} storage class type, e.g.: `Standard`
- owner {Object|null} object owner, including `id` and `displayName`
- restoreInfo {Object|undefined} The restoration status of the object
- ongoingRequest {Boolean} Whether the restoration is ongoing
- expireDate {Date|undefined} The time before which the restored object can be read
- prefixes {Array<String>} prefix list
- isTruncated {Boolean} truncate or not
- nextContinuationToken {String} next continuation-token string
Expand Down Expand Up @@ -2595,6 +2600,9 @@ Success will return objects list on `objects` properties.
- versionId {String} object versionId
- storageClass {String} storage class type, e.g.: `Standard`
- owner {Object} object owner, including `id` and `displayName`
- restoreInfo {Object|undefined} The restoration status of the object
- ongoingRequest {Boolean} Whether the restoration is ongoing
- expireDate {Date|undefined} The time before which the restored object can be read
- deleteMarker {Array<ObjectDeleteMarker>} object delete marker info list
Each `ObjectDeleteMarker`
- name {String} object name on oss
Expand Down Expand Up @@ -2954,6 +2962,8 @@ parameters:
- [timeout] {Number} the operation timeout
- [versionId] {String} the version id of history object
- [type] {String} the default type is Archive
- [Days] {number} The duration within which the object remains in the restored state. The default value is 2.
- [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.

Success will return:

Expand All @@ -2965,27 +2975,54 @@ Success will return:

example:

- Restore an object with Archive type
- Restore an Archive object

```js
const result = await store.restore('ossdemo.txt');
console.log(result.status);
```

- Restore an object with ColdArchive type
- Restore a Cold Archive object

```js
const result = await store.restore('ossdemo.txt', { type: 'ColdArchive' });
console.log(result.status);
```

- Days for unfreezing Specifies the days for unfreezing
- Restore a Cold Archive object with Days

```js
const result = await store.restore('ossdemo.txt', { type: 'ColdArchive', Days: 2 });
console.log(result.status);
```

- Restore a Cold Archive object with Days and JobParameters
```js
const result = await store.restore('ossdemo.txt', { type: 'ColdArchive', Days: 2, JobParameters: 'Standard' });
console.log(result.status);
```

- Restore a Deep Cold Archive object

```js
const result = await store.restore('ossdemo.txt', { type: 'DeepColdArchive' });
console.log(result.status);
```

- Restore a Deep Cold Archive object with Days

```js
const result = await store.restore('ossdemo.txt', { type: 'DeepColdArchive', Days: 2 });
console.log(result.status);
```

- Restore a Deep Cold Archive object with Days and JobParameters

```js
const result = await store.restore('ossdemo.txt', { type: 'DeepColdArchive', Days: 2, JobParameters: 'Standard' });
console.log(result.status);
```

- Restore an history object

```js
Expand Down Expand Up @@ -3816,6 +3853,89 @@ Object:
- Signature {String}
- policy {Object} response info

### .signPostObjectPolicyV4(policy, date)

Get a V4 signature of the PostObject request.

parameters:

- 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.
- date {Date} The time when the request was initiated.

Success will return a V4 signature of the PostObject request.

example:

```js
const axios = require('axios');
const dateFormat = require('dateformat');
const FormData = require('form-data');
const { getCredential } = require('ali-oss/lib/common/signUtils');
const { getStandardRegion } = require('ali-oss/lib/common/utils/getStandardRegion');
const { policy2Str } = require('ali-oss/lib/common/utils/policy2Str');
const OSS = require('ali-oss');

const client = new OSS({
accessKeyId: 'yourAccessKeyId',
accessKeySecret: 'yourAccessKeySecret',
stsToken: 'yourSecurityToken',
bucket: 'yourBucket',
region: 'oss-cn-hangzhou'
});
const name = 'yourObjectName';
const formData = new FormData();
formData.append('key', name);
formData.append('Content-Type', 'yourObjectContentType');
// your object cache control
formData.append('Cache-Control', 'max-age=30');
const url = client.generateObjectUrl(name).replace(name, '');
const date = new Date();
// The expiration parameter specifies the expiration time of the request.
const expirationDate = new Date(date);
expirationDate.setMinutes(date.getMinutes() + 1);
// The time must follow the ISO 8601 standard
const formattedDate = dateFormat(date, "UTC:yyyymmdd'T'HHMMss'Z'");
const credential = getCredential(formattedDate.split('T')[0], getStandardRegion(client.options.region), client.options.accessKeyId);
formData.append('x-oss-date', formattedDate);
formData.append('x-oss-credential', credential);
formData.append('x-oss-signature-version', 'OSS4-HMAC-SHA256');
const policy = {
expiration: expirationDate.toISOString(),
conditions: [
{ bucket: client.options.bucket },
{'x-oss-credential': credential},
{'x-oss-date': formattedDate},
{'x-oss-signature-version': 'OSS4-HMAC-SHA256'},
['content-length-range', 1, 10],
['eq', '$success_action_status', '200'],
['starts-with', '$key', 'yourObjectName'],
['in', '$content-type', ['image/jpg', 'text/plain']],
['not-in', '$cache-control', ['no-cache']]
]
};

if (client.options.stsToken) {
policy.conditions.push({'x-oss-security-token': client.options.stsToken});
formData.append('x-oss-security-token', client.options.stsToken);
}

const signature = client.signPostObjectPolicyV4(policy, date);
formData.append('policy', Buffer.from(policy2Str(policy), 'utf8').toString('base64'));
formData.append('x-oss-signature', signature);
formData.append('success_action_status', '200');
formData.append('file', 'yourFileContent');

axios.post(url, formData, {
headers: {
'Content-Type': 'multipart/form-data'
}
}).then((result) => {
console.log(result.status);
}).catch((e) => {
console.log(e);
});
```

### .getObjectTagging(name[, options])

Obtains the tags of an object.
Expand Down
2 changes: 1 addition & 1 deletion karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ module.exports = function (config) {
concurrency: 1,
client: {
mocha: {
timeout: 6000
timeout: 15000
}
}
});
Expand Down
11 changes: 6 additions & 5 deletions lib/browser/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,7 @@ proto.requestError = async function requestError(result) {
this.debug(message, 'error');
error.message += `\nraw xml: ${message}`;
error.status = result.status;
error.requestId = result.headers['x-oss-request-id'];
error.requestId = result.headers && result.headers['x-oss-request-id'];
return error;
}

Expand All @@ -416,6 +416,7 @@ proto.requestError = async function requestError(result) {
err.requestId = info.RequestId;
err.hostId = info.HostId;
err.serverTime = info.ServerTime;
return err;
};

if (!result.data || !result.data.length) {
Expand All @@ -442,20 +443,20 @@ proto.requestError = async function requestError(result) {
err.name = 'UnknownError';
err.status = result.status;
err.res = result;
const ossErr = result.headers['x-oss-err'];
const ossErr = result.headers && result.headers['x-oss-err'];
if (ossErr) {
const message = atob(ossErr);
await setError(message);
err = await setError(message);
}
}
err.requestId = result.headers['x-oss-request-id'];
err.requestId = result.headers && result.headers['x-oss-request-id'];
err.host = '';
}
} else {
const message = String(result.data);
this.debug('request response error data: %s', message, 'error');

await setError(message);
err = await setError(message);
}

this.debug('generate error %j', err, 'error');
Expand Down
36 changes: 22 additions & 14 deletions lib/browser/object.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const { isBlob } = require('../common/utils/isBlob');
const { isFile } = require('../common/utils/isFile');
const { isBuffer } = require('../common/utils/isBuffer');
const { obj2xml } = require('../common/utils/obj2xml');
const { parseRestoreInfo } = require('../common/utils/parseRestoreInfo');

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

Expand Down Expand Up @@ -166,6 +167,7 @@ merge(proto, require('../common/object/generateObjectUrl'));
merge(proto, require('../common/object/signatureUrl'));
merge(proto, require('../common/object/asyncSignatureUrl'));
merge(proto, require('../common/object/signatureUrlV4'));
merge(proto, require('../common/object/signPostObjectPolicyV4'));

proto.putMeta = async function putMeta(name, meta, options) {
const copyResult = await this.copy(name, name, {
Expand All @@ -191,6 +193,7 @@ proto.list = async function list(query, options) {
if (!Array.isArray(objects)) {
objects = [objects];
}

objects = objects.map(obj => ({
name: obj.Key,
url: that._objectUrl(obj.Key),
Expand All @@ -202,7 +205,8 @@ proto.list = async function list(query, options) {
owner: {
id: obj.Owner.ID,
displayName: obj.Owner.DisplayName
}
},
restoreInfo: parseRestoreInfo(obj.RestoreInfo)
}));
}
let prefixes = result.data.CommonPrefixes || null;
Expand Down Expand Up @@ -245,6 +249,7 @@ proto.listV2 = async function listV2(query, options = {}) {
if (!Array.isArray(objects)) {
objects = [objects];
}

objects = objects.map(obj => {
let owner = null;
if (obj.Owner) {
Expand All @@ -261,7 +266,8 @@ proto.listV2 = async function listV2(query, options = {}) {
type: obj.Type,
size: Number(obj.Size),
storageClass: obj.StorageClass,
owner
owner,
restoreInfo: parseRestoreInfo(obj.RestoreInfo)
};
});
}
Expand Down Expand Up @@ -296,20 +302,22 @@ proto.restore = async function restore(name, options = { type: 'Archive' }) {
options.subres.versionId = options.versionId;
}
const params = this._objectRequestParams('POST', name, options);
if (options.type === 'ColdArchive') {
const paramsXMLObj = {
RestoreRequest: {
Days: options.Days ? options.Days : 2,
JobParameters: {
Tier: options.JobParameters ? options.JobParameters : 'Standard'
}
}
const paramsXMLObj = {
RestoreRequest: {
Days: options.Days ? options.Days : 2
}
};

if (options.type === 'ColdArchive' || options.type === 'DeepColdArchive') {
paramsXMLObj.RestoreRequest.JobParameters = {
Tier: options.JobParameters ? options.JobParameters : 'Standard'
};
params.content = obj2xml(paramsXMLObj, {
headers: true
});
params.mime = 'xml';
}

params.content = obj2xml(paramsXMLObj, {
headers: true
});
params.mime = 'xml';
params.successStatuses = [202];

const result = await this.request(params);
Expand Down
Loading
Loading