Skip to content

Commit

Permalink
feat: the browser needs to set cross domain and expose the x-oss-next…
Browse files Browse the repository at this point in the history
…-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 <csg01123119@alibaba-inc.com>
Co-authored-by: Undefined <peizerao@gmail.com>
  • Loading branch information
3 people authored Jul 20, 2023
1 parent b113222 commit ab2f4a3
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 11 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
35 changes: 35 additions & 0 deletions test/browser/browser.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
});
});
});
20 changes: 10 additions & 10 deletions test/node/object.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand Down

0 comments on commit ab2f4a3

Please sign in to comment.