Skip to content

Commit ab2f4a3

Browse files
shungangcsg01123119PeterRao
authoredJul 20, 2023
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 <csg01123119@alibaba-inc.com> Co-authored-by: Undefined <peizerao@gmail.com>
1 parent b113222 commit ab2f4a3

File tree

3 files changed

+46
-11
lines changed

3 files changed

+46
-11
lines changed
 

‎README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1880,7 +1880,7 @@ object:
18801880
- headers {Object} response headers
18811881
- size {Number} response size
18821882
- rt {Number} request total use time (ms)
1883-
- nextAppendPosition {String} the next position
1883+
- nextAppendPosition {String} the next position(The browser needs to set cross domain and expose the x-oss-next-append-position header)
18841884
18851885
example:
18861886

‎test/browser/browser.test.js

+35
Original file line numberDiff line numberDiff line change
@@ -2449,4 +2449,39 @@ describe('browser', () => {
24492449
assert.equal(header['x-oss-server-side-encryption'], undefined);
24502450
});
24512451
});
2452+
2453+
describe('append()', () => {
2454+
const name = `/${prefix}ali-sdk/oss/apend${Date.now()}`;
2455+
let store;
2456+
before(() => {
2457+
store = oss(ossConfig);
2458+
});
2459+
2460+
afterEach(async () => {
2461+
await store.delete(name);
2462+
});
2463+
2464+
it('should apend object with content blob', async () => {
2465+
let object = await store.append(name, new Blob(['foo']));
2466+
const { nextAppendPosition } = object;
2467+
assert.strictEqual(object.res.status, 200);
2468+
assert.strictEqual(nextAppendPosition, '3');
2469+
assert.strictEqual(object.res.headers['x-oss-next-append-position'], '3');
2470+
2471+
let res = await store.get(name);
2472+
assert.strictEqual(res.content.toString(), 'foo');
2473+
assert.strictEqual(res.res.headers['x-oss-next-append-position'], '3');
2474+
2475+
object = await store.append(name, new Blob(['bar']), {
2476+
position: nextAppendPosition
2477+
});
2478+
assert.strictEqual(object.res.status, 200);
2479+
assert.strictEqual(object.nextAppendPosition, '6');
2480+
assert.strictEqual(object.res.headers['x-oss-next-append-position'], '6');
2481+
2482+
res = await store.get(name, { subres: { 'response-cache-control': 'no-store' } });
2483+
assert.strictEqual(res.content.toString(), 'foobar');
2484+
assert.strictEqual(res.res.headers['x-oss-next-append-position'], '6');
2485+
});
2486+
});
24522487
});

‎test/node/object.test.js

+10-10
Original file line numberDiff line numberDiff line change
@@ -2115,24 +2115,24 @@ describe('test/object.test.js', () => {
21152115

21162116
it('should apend object with content buffer', async () => {
21172117
let object = await store.append(name, Buffer.from('foo'));
2118-
assert(object.res.status === 200);
2119-
assert(object.nextAppendPosition === '3');
2120-
assert(object.res.headers['x-oss-next-append-position'] === '3');
2118+
assert.strictEqual(object.res.status, 200);
2119+
assert.strictEqual(object.nextAppendPosition, '3');
2120+
assert.strictEqual(object.res.headers['x-oss-next-append-position'], '3');
21212121

21222122
let res = await store.get(name);
2123-
assert(res.content.toString() === 'foo');
2124-
assert(res.res.headers['x-oss-next-append-position'] === '3');
2123+
assert.strictEqual(res.content.toString(), 'foo');
2124+
assert.strictEqual(res.res.headers['x-oss-next-append-position'], '3');
21252125

21262126
object = await store.append(name, Buffer.from('bar'), {
21272127
position: 3
21282128
});
2129-
assert(object.res.status === 200);
2130-
assert(object.nextAppendPosition === '6');
2131-
assert(object.res.headers['x-oss-next-append-position'] === '6');
2129+
assert.strictEqual(object.res.status, 200);
2130+
assert.strictEqual(object.nextAppendPosition, '6');
2131+
assert.strictEqual(object.res.headers['x-oss-next-append-position'], '6');
21322132

21332133
res = await store.get(name);
2134-
assert(res.content.toString() === 'foobar');
2135-
assert(res.res.headers['x-oss-next-append-position'] === '6');
2134+
assert.strictEqual(res.content.toString(), 'foobar');
2135+
assert.strictEqual(res.res.headers['x-oss-next-append-position'], '6');
21362136
});
21372137

21382138
it('should apend object with local file path', async () => {

0 commit comments

Comments
 (0)
Please sign in to comment.