From ac500d3d87a911ec359d9ba781006034a78c1db2 Mon Sep 17 00:00:00 2001 From: mzy1212 Date: Thu, 21 Nov 2024 10:59:59 +0800 Subject: [PATCH] feat: restore support DeepColdArchive type (#1337) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat: restore support DeepColdArchive type * feat: restore support DeepColdArchive type * feat: restore support DeepColdArchive type * feat: restore support DeepColdArchive type --------- Co-authored-by: 孟凡荣 --- README.md | 27 ++++++++++++ lib/browser/object.js | 2 +- lib/object.js | 2 +- test/browser/browser.test.js | 63 +++++++++++++++++++++++++- test/node/bucket.test.js | 11 +++-- test/node/multiversion.test.js | 2 +- test/node/object.test.js | 81 +++++++++++++++++++++++++++++++++- 7 files changed, 177 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 9b904698..abf2225c 100644 --- a/README.md +++ b/README.md @@ -2995,6 +2995,33 @@ const result = await store.restore('ossdemo.txt', { type: 'ColdArchive', Days: 2 console.log(result.status); ``` +- JobParameters for unfreezing Specifies the JobParameters for unfreezing +```js +const result = await store.restore('ossdemo.txt', { type: 'ColdArchive', Days: 2, JobParameters: 'Standard' }); +console.log(result.status); +``` + +- Restore an object with DeepColdArchive type + +```js +const result = await store.restore('ossdemo.txt', { type: 'DeepColdArchive' }); +console.log(result.status); +``` + +- Days for unfreezing Specifies the days for unfreezing + +```js +const result = await store.restore('ossdemo.txt', { type: 'DeepColdArchive', Days: 2 }); +console.log(result.status); +``` + +- JobParameters for unfreezing Specifies the JobParameters for unfreezing + +```js +const result = await store.restore('ossdemo.txt', { type: 'DeepColdArchive', Days: 2, JobParameters: 'Standard' }); +console.log(result.status); +``` + - Restore an history object ```js diff --git a/lib/browser/object.js b/lib/browser/object.js index 03c7b03c..df202f6f 100644 --- a/lib/browser/object.js +++ b/lib/browser/object.js @@ -301,7 +301,7 @@ 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') { + if (options.type === 'ColdArchive' || options.type === 'DeepColdArchive') { const paramsXMLObj = { RestoreRequest: { Days: options.Days ? options.Days : 2, diff --git a/lib/object.js b/lib/object.js index 649651a5..21770ec0 100644 --- a/lib/object.js +++ b/lib/object.js @@ -324,7 +324,7 @@ 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') { + if (options.type === 'ColdArchive' || options.type === 'DeepColdArchive') { const paramsXMLObj = { RestoreRequest: { Days: options.Days ? options.Days : 2, diff --git a/test/browser/browser.test.js b/test/browser/browser.test.js index 2297ef78..034ab04d 100644 --- a/test/browser/browser.test.js +++ b/test/browser/browser.test.js @@ -2693,7 +2693,7 @@ describe('browser', () => { }); it('ColdArchive choice Days', async () => { - const name = '/oss/daysRestore.js'; + const name = '/oss/daysColdRestore.js'; const options = { headers: { 'x-oss-storage-class': 'ColdArchive' @@ -2707,6 +2707,22 @@ describe('browser', () => { assert.equal(result.res.status, 202); }); + it('ColdArchive choice JobParameters', async () => { + const name = '/oss/JobParametersColdRestore.js'; + const options = { + headers: { + 'x-oss-storage-class': 'ColdArchive' + } + }; + await store.put(name, Buffer.from('abc'), options); + const result = await store.restore(name, { + type: 'ColdArchive', + Days: 2, + JobParameters: 'Standard' + }); + assert.equal(result.res.status, 202); + }); + it('ColdArchive is Accepted', async () => { const name = '/oss/coldRestore.js'; const options = { @@ -2720,6 +2736,51 @@ describe('browser', () => { }); assert.equal(result.res.status, 202); }); + + it('DeepColdArchive choice Days', async () => { + const name = '/oss/daysDeepColdRestore.js'; + const options = { + headers: { + 'x-oss-storage-class': 'DeepColdArchive' + } + }; + await store.put(name, Buffer.from('abc'), options); + const result = await store.restore(name, { + type: 'DeepColdArchive', + Days: 2 + }); + assert.equal(result.res.status, 202); + }); + + it('DeepColdArchive choice JobParameters', async () => { + const name = '/oss/JobParametersDeepColdRestore.js'; + const options = { + headers: { + 'x-oss-storage-class': 'DeepColdArchive' + } + }; + await store.put(name, Buffer.from('abc'), options); + const result = await store.restore(name, { + type: 'DeepColdArchive', + Days: 2, + JobParameters: 'Standard' + }); + assert.equal(result.res.status, 202); + }); + + it('DeepColdArchive is Accepted', async () => { + const name = '/oss/deepColdRestore.js'; + const options = { + headers: { + 'x-oss-storage-class': 'DeepColdArchive' + } + }; + await store.put(name, Buffer.from(__filename), options); + const result = await store.restore(name, { + type: 'DeepColdArchive' + }); + assert.equal(result.res.status, 202); + }); }); describe('multipartCopy()', () => { diff --git a/test/node/bucket.test.js b/test/node/bucket.test.js index d2b88671..b60140bc 100644 --- a/test/node/bucket.test.js +++ b/test/node/bucket.test.js @@ -13,7 +13,6 @@ describe('test/bucket.test.js', () => { const { prefix, includesConf } = utils; let store; let bucket; - const bucketRegion = 'oss-ap-southeast-1'; // oss-ap-southeast-1 suport PutBucketLifecycle DeepColdArchive const { accountId } = config; [ { @@ -25,7 +24,7 @@ describe('test/bucket.test.js', () => { ].forEach((moreConfigs, idx) => { describe(`test bucket in iterate ${idx}`, () => { before(async () => { - store = oss({ ...config, ...moreConfigs, region: bucketRegion }); + store = oss({ ...config, ...moreConfigs }); bucket = `ali-oss-test-bucket-${prefix.replace(/[/.]/g, '-')}${idx}`; const result = await store.putBucket(bucket, { timeout }); @@ -134,9 +133,9 @@ describe('test/bucket.test.js', () => { const result = await store.getBucketInfo(bucket); assert.equal(result.res.status, 200); - assert.equal(result.bucket.Location, `${bucketRegion}`); - assert.equal(result.bucket.ExtranetEndpoint, `${bucketRegion}.aliyuncs.com`); - assert.equal(result.bucket.IntranetEndpoint, `${bucketRegion}-internal.aliyuncs.com`); + assert.equal(result.bucket.Location, `${config.region}`); + assert.equal(result.bucket.ExtranetEndpoint, `${config.region}.aliyuncs.com`); + assert.equal(result.bucket.IntranetEndpoint, `${config.region}-internal.aliyuncs.com`); assert.equal(result.bucket.AccessControlList.Grant, 'private'); assert.equal(result.bucket.StorageClass, 'Standard'); }); @@ -151,7 +150,7 @@ describe('test/bucket.test.js', () => { describe('getBucketLoaction', () => { it('it should return loaction this.region', async () => { const result = await store.getBucketLocation(bucket); - assert.equal(result.location, bucketRegion); + assert.equal(result.location, config.region); }); it('it should return NoSuchBucketError when bucket not exist', async () => { diff --git a/test/node/multiversion.test.js b/test/node/multiversion.test.js index 3ecaf644..43c4c3c8 100644 --- a/test/node/multiversion.test.js +++ b/test/node/multiversion.test.js @@ -23,7 +23,7 @@ describe('test/multiversion.test.js', () => { describe(`test multiversion in iterate ${idx}`, () => { before(async () => { // oss-ap-southeast-1 suport PutBucketLifecycle DeepColdArchive - store = oss({ ...config, ...moreConfigs, region: 'oss-ap-southeast-1' }); + store = oss({ ...config, ...moreConfigs }); bucket = `ali-oss-test-bucket-version-${prefix.replace(/[/.]/g, '-')}${idx}`; const result = await store.putBucket(bucket); diff --git a/test/node/object.test.js b/test/node/object.test.js index 8fe3f776..9ecf3a31 100644 --- a/test/node/object.test.js +++ b/test/node/object.test.js @@ -2475,7 +2475,13 @@ describe('test/object.test.js', () => { }); it('ColdArchive choice Days', async () => { - const name = '/oss/daysRestore.js'; + const name = '/oss/daysColdRestore.js'; + const options = { + headers: { + 'x-oss-storage-class': 'ColdArchive' + } + }; + await store.put(name, Buffer.from('abc'), options); const result = await store.restore(name, { type: 'ColdArchive', Days: 2 @@ -2486,6 +2492,25 @@ describe('test/object.test.js', () => { ); }); + it('ColdArchive choice JobParameters', async () => { + const name = '/oss/JobParametersColdRestore.js'; + const options = { + headers: { + 'x-oss-storage-class': 'ColdArchive' + } + }; + await store.put(name, Buffer.from('abc'), options); + const result = await store.restore(name, { + type: 'ColdArchive', + Days: 2, + JobParameters: 'Standard' + }); + assert.equal( + ['Expedited', 'Standard', 'Bulk'].includes(result.res.headers['x-oss-object-restore-priority']), + true + ); + }); + it('ColdArchive is Accepted', async () => { const name = '/oss/coldRestore.js'; const result = await store.restore(name, { @@ -2496,6 +2521,60 @@ describe('test/object.test.js', () => { true ); }); + + it('DeepColdArchive choice Days', async () => { + const name = '/oss/daysDeepColdRestore.js'; + const options = { + headers: { + 'x-oss-storage-class': 'DeepColdArchive' + } + }; + await store.put(name, Buffer.from('abc'), options); + const result = await store.restore(name, { + type: 'DeepColdArchive', + Days: 2 + }); + assert.equal( + ['Expedited', 'Standard', 'Bulk'].includes(result.res.headers['x-oss-object-restore-priority']), + true + ); + }); + + it('DeepColdArchive choice JobParameters', async () => { + const name = '/oss/JobParametersDeepColdRestore.js'; + const options = { + headers: { + 'x-oss-storage-class': 'DeepColdArchive' + } + }; + await store.put(name, Buffer.from('abc'), options); + const result = await store.restore(name, { + type: 'DeepColdArchive', + Days: 2, + JobParameters: 'Standard' + }); + assert.equal( + ['Expedited', 'Standard', 'Bulk'].includes(result.res.headers['x-oss-object-restore-priority']), + true + ); + }); + + it('DeepColdArchive is Accepted', async () => { + const name = '/oss/deepColdRestore.js'; + const options = { + headers: { + 'x-oss-storage-class': 'DeepColdArchive' + } + }; + await store.put(name, Buffer.from(__filename), options); + const result = await store.restore(name, { + type: 'DeepColdArchive' + }); + assert.equal( + ['Expedited', 'Standard', 'Bulk'].includes(result.res.headers['x-oss-object-restore-priority']), + true + ); + }); }); describe('symlink()', () => {