Skip to content

Commit 041591b

Browse files
Ari1cPeterRao
authored andcommitted
Add symlink api (#673)
* FEAT: add symlink api or test cases * FIX: opt symlink code * OPT: test case decode
1 parent a35c8b6 commit 041591b

File tree

4 files changed

+179
-0
lines changed

4 files changed

+179
-0
lines changed

README.md

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,8 @@ All operation use es7 async/await to implement. All api is async function.
106106
- [.putACL(name, acl[, options])](#putaclname-acl-options)
107107
- [.getACL(name[, options])](#getaclname-options)
108108
- [.restore(name[, options])](#restorename-options)
109+
- [.putSymlink(name, targetName[, options])](#putsymlinkname-targetname-options)
110+
- [.getSymlink(name[, options])](#getsymlinkname-options)
109111
- [.initMultipartUpload(name[, options])](#initmultipartuploadname-options)
110112
- [.uploadPart(name, uploadId, partNo, file, start, end[, options])](#uploadpartname-uploadid-partno-file-start-end-options)
111113
- [.uploadPartCopy(name, uploadId, partNo, range, sourceData[, options])](#uploadpartcopyname-uploadid-partno-range-sourcedata-options)
@@ -1761,6 +1763,63 @@ const result = await store.restore('ossdemo.txt');
17611763
console.log(result.status);
17621764
```
17631765
1766+
### .putSymlink(name, targetName[, options])
1767+
1768+
PutSymlink
1769+
1770+
parameters:
1771+
1772+
- name {String} object name
1773+
- targetName {String} target name
1774+
- [options] {Object} optional parameters
1775+
- [headers] {Object} extra headers
1776+
- [x-oss-storsge-calss] {String} set the header x-oss-storage-class
1777+
1778+
Success will return
1779+
1780+
- res {Object} response info, including
1781+
- status {Number} response status
1782+
- headers {Object} response headers
1783+
- size {Number} response size
1784+
- rt {Number} request total use time (ms)
1785+
1786+
example:
1787+
1788+
```js
1789+
const options = {
1790+
headers: {
1791+
'x-oss-storage-class': 'IA'
1792+
}
1793+
}
1794+
const result = await store.putSymlink('ossdemo.txt', 'targetName', options)
1795+
console.log(result.status)
1796+
```
1797+
1798+
### .getSymlink(name[, options])
1799+
1800+
GetSymlink
1801+
1802+
parameters:
1803+
1804+
- name {String} object name
1805+
- [options] {Object} optional parameters
1806+
1807+
Success will return
1808+
1809+
- targetName {String} symlink info
1810+
- res {Object} response info, including
1811+
- status {Number} response status
1812+
- headers {Object} response headers
1813+
- size {Number} response size
1814+
- rt {Number} request total use time (ms)
1815+
1816+
example:
1817+
1818+
```js
1819+
const result = await store.getSymlink('ossdemo.txt')
1820+
console.log(result.status)
1821+
```
1822+
17641823
### .initMultipartUpload(name[, options])
17651824
Before transmitting data in the Multipart Upload mode,
17661825
you must call the Initiate Multipart Upload interface to notify the OSS to initiate a Multipart Upload event.

lib/browser/object.js

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -430,6 +430,56 @@ proto.restore = async function restore(name, options) {
430430
};
431431
};
432432

433+
/**
434+
* putSymlink
435+
* @param {Sting} name - object name
436+
* @param {String} targetName - target name
437+
* @param {Object} options
438+
* @param {{res}}
439+
*/
440+
441+
proto.putSymlink = async function putSymlink(name, targetName, options) {
442+
options = options || {};
443+
options.headers = options.headers || {};
444+
this._convertMetaToHeaders(options.meta, options.headers);
445+
options.headers['x-oss-symlink-target'] = targetName;
446+
options.subres = 'symlink';
447+
448+
if (options.storageClass) {
449+
options.headers['x-oss-storage-class'] = options.storageClass;
450+
}
451+
452+
name = this._objectName(name);
453+
const params = this._objectRequestParams('PUT', name, options);
454+
455+
params.successStatuses = [200];
456+
const result = await this.request(params);
457+
return {
458+
res: result.res
459+
};
460+
};
461+
462+
/**
463+
* getSymlink
464+
* @param {String} -object name
465+
* @param {Object} options
466+
* @param {{res}}
467+
*/
468+
469+
proto.getSymlink = async function getSymlink(name, options) {
470+
options = options || {};
471+
options.subres = 'symlink';
472+
name = this._objectName(name);
473+
const params = this._objectRequestParams('GET', name, options);
474+
params.successStatuses = [200];
475+
const result = await this.request(params);
476+
const target = result.res.headers['x-oss-symlink-target'];
477+
return {
478+
targetName: target,
479+
res: result.res
480+
};
481+
};
482+
433483
proto.signatureUrl = function signatureUrl(name, options) {
434484
options = options || {};
435485
name = this._objectName(name);

lib/object.js

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -447,6 +447,56 @@ proto.restore = async function restore(name, options) {
447447
};
448448
};
449449

450+
/**
451+
* putSymlink
452+
* @param {Sting} name - object name
453+
* @param {String} targetName - target name
454+
* @param {Object} options
455+
* @param {{res}}
456+
*/
457+
458+
proto.putSymlink = async function putSymlink(name, targetName, options) {
459+
options = options || {};
460+
options.headers = options.headers || {};
461+
this._convertMetaToHeaders(options.meta, options.headers);
462+
options.headers['x-oss-symlink-target'] = targetName;
463+
options.subres = 'symlink';
464+
465+
if (options.storageClass) {
466+
options.headers['x-oss-storage-class'] = options.storageClass;
467+
}
468+
469+
name = this._objectName(name);
470+
const params = this._objectRequestParams('PUT', name, options);
471+
472+
params.successStatuses = [200];
473+
const result = await this.request(params);
474+
return {
475+
res: result.res
476+
};
477+
};
478+
479+
/**
480+
* getSymlink
481+
* @param {String} -object name
482+
* @param {Object} options
483+
* @param {{res}}
484+
*/
485+
486+
proto.getSymlink = async function getSymlink(name, options) {
487+
options = options || {};
488+
options.subres = 'symlink';
489+
name = this._objectName(name);
490+
const params = this._objectRequestParams('GET', name, options);
491+
params.successStatuses = [200];
492+
const result = await this.request(params);
493+
const target = result.res.headers['x-oss-symlink-target'];
494+
return {
495+
targetName: target,
496+
res: result.res
497+
};
498+
};
499+
450500
proto.signatureUrl = function signatureUrl(name, options) {
451501
options = options || {};
452502
name = this._objectName(name);

test/node/object.test.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1639,4 +1639,24 @@ describe('test/object.test.js', () => {
16391639
}
16401640
});
16411641
});
1642+
describe('symlink()', () => {
1643+
it('Should put and get Symlink', async () => {
1644+
const name = '/oss/symlink.js';
1645+
const test = 'test-symlink.js';
1646+
let result = await store.put(name, __filename);
1647+
1648+
const options = {
1649+
headers: {
1650+
'x-oss-storsge-calss': 'IA'
1651+
}
1652+
}
1653+
result = await store.putSymlink(test, name, options);
1654+
assert.equal(result.res.status, 200);
1655+
1656+
result = await store.getSymlink(test);
1657+
assert.equal(typeof result.res.headers['x-oss-storage-class'], 'string');
1658+
assert.equal(decodeURIComponent(result.targetName), name);
1659+
assert.equal(result.res.status, 200);
1660+
});
1661+
});
16421662
});

0 commit comments

Comments
 (0)