From ab2f4a3c795d1ab61b54112f3fc081d8afb39b7f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=A1=BA=E5=88=9A?= <735073554@qq.com> Date: Thu, 20 Jul 2023 15:43:52 +0800 Subject: [PATCH] feat: the browser needs to set cross domain and expose the x-oss-next-append-position header (#1218) * feat: add test cases for browser append() * fix: delete only test * fix: fix browser test case append() * feat: the browser needs to set cross domain and expose the x-oss-next-append-position header --------- Co-authored-by: csg01123119 Co-authored-by: Undefined --- README.md | 2 +- test/browser/browser.test.js | 35 +++++++++++++++++++++++++++++++++++ test/node/object.test.js | 20 ++++++++++---------- 3 files changed, 46 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 0f4f5b0b9..203860350 100644 --- a/README.md +++ b/README.md @@ -1880,7 +1880,7 @@ object: - headers {Object} response headers - size {Number} response size - rt {Number} request total use time (ms) -- nextAppendPosition {String} the next position +- nextAppendPosition {String} the next position(The browser needs to set cross domain and expose the x-oss-next-append-position header) example: diff --git a/test/browser/browser.test.js b/test/browser/browser.test.js index c4e53d83d..3a9886d52 100644 --- a/test/browser/browser.test.js +++ b/test/browser/browser.test.js @@ -2449,4 +2449,39 @@ describe('browser', () => { assert.equal(header['x-oss-server-side-encryption'], undefined); }); }); + + describe('append()', () => { + const name = `/${prefix}ali-sdk/oss/apend${Date.now()}`; + let store; + before(() => { + store = oss(ossConfig); + }); + + afterEach(async () => { + await store.delete(name); + }); + + it('should apend object with content blob', async () => { + let object = await store.append(name, new Blob(['foo'])); + const { nextAppendPosition } = object; + assert.strictEqual(object.res.status, 200); + assert.strictEqual(nextAppendPosition, '3'); + assert.strictEqual(object.res.headers['x-oss-next-append-position'], '3'); + + let res = await store.get(name); + assert.strictEqual(res.content.toString(), 'foo'); + assert.strictEqual(res.res.headers['x-oss-next-append-position'], '3'); + + object = await store.append(name, new Blob(['bar']), { + position: nextAppendPosition + }); + assert.strictEqual(object.res.status, 200); + assert.strictEqual(object.nextAppendPosition, '6'); + assert.strictEqual(object.res.headers['x-oss-next-append-position'], '6'); + + res = await store.get(name, { subres: { 'response-cache-control': 'no-store' } }); + assert.strictEqual(res.content.toString(), 'foobar'); + assert.strictEqual(res.res.headers['x-oss-next-append-position'], '6'); + }); + }); }); diff --git a/test/node/object.test.js b/test/node/object.test.js index 31a2a4fc7..baed1a88e 100644 --- a/test/node/object.test.js +++ b/test/node/object.test.js @@ -2115,24 +2115,24 @@ describe('test/object.test.js', () => { it('should apend object with content buffer', async () => { let object = await store.append(name, Buffer.from('foo')); - assert(object.res.status === 200); - assert(object.nextAppendPosition === '3'); - assert(object.res.headers['x-oss-next-append-position'] === '3'); + assert.strictEqual(object.res.status, 200); + assert.strictEqual(object.nextAppendPosition, '3'); + assert.strictEqual(object.res.headers['x-oss-next-append-position'], '3'); let res = await store.get(name); - assert(res.content.toString() === 'foo'); - assert(res.res.headers['x-oss-next-append-position'] === '3'); + assert.strictEqual(res.content.toString(), 'foo'); + assert.strictEqual(res.res.headers['x-oss-next-append-position'], '3'); object = await store.append(name, Buffer.from('bar'), { position: 3 }); - assert(object.res.status === 200); - assert(object.nextAppendPosition === '6'); - assert(object.res.headers['x-oss-next-append-position'] === '6'); + assert.strictEqual(object.res.status, 200); + assert.strictEqual(object.nextAppendPosition, '6'); + assert.strictEqual(object.res.headers['x-oss-next-append-position'], '6'); res = await store.get(name); - assert(res.content.toString() === 'foobar'); - assert(res.res.headers['x-oss-next-append-position'] === '6'); + assert.strictEqual(res.content.toString(), 'foobar'); + assert.strictEqual(res.res.headers['x-oss-next-append-position'], '6'); }); it('should apend object with local file path', async () => {