Skip to content

Commit

Permalink
Merge pull request #93 from lurunze1226/feat-symlink
Browse files Browse the repository at this point in the history
feat: 支持查看设置软链接
  • Loading branch information
lurunze1226 authored Feb 16, 2023
2 parents efbfd5b + bd5c86c commit 8903354
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 5 deletions.
45 changes: 44 additions & 1 deletion src/bos_client.js
Original file line number Diff line number Diff line change
Expand Up @@ -1013,6 +1013,47 @@ BosClient.prototype.postObject = function (bucketName, key, data, options) {
});
};

/**
* 获取软连接,需要对软连接有读取权限,接口响应头的x-bce-symlink-target指向目标文件
*/
BosClient.prototype.getSymlink = function (bucketName, objectName, options) {
options = options || {};

return this.sendRequest('GET', {
bucketName,
key: objectName,
params: {symlink: ''},
config: options.config
});
}

/**
* 为BOS的相同bucket下已有的目的object创建软链接
* @param {string} bucketName 桶名称
* @param {string} objectName 软连接文件名称
* @param {string} target 目标对象名称
* @param {boolean} overwrite 是否覆盖同名Object,默认允许覆盖
*/
BosClient.prototype.putSymlink = function (bucketName, objectName, target, overwrite, options) {
options = options || {};
var headers = {};

if (!target) {
throw new TypeError('target object should not be empty.');
}

headers[H.X_BCE_SYMLINK_TARGET] = target;
headers[H.X_BCE_FORBID_OVERWRITE] = overwrite === true;

return this.sendRequest('PUT', {
bucketName,
key: objectName,
params: {symlink: ''},
headers: headers,
config: options.config
});
}

// --- E N D ---

BosClient.prototype.sendRequest = function (httpMethod, varArgs) {
Expand Down Expand Up @@ -1128,7 +1169,9 @@ BosClient.prototype._prepareObjectHeaders = function (options) {
H.X_BCE_STORAGE_CLASS,
H.X_BCE_SERVER_SIDE_ENCRYPTION,
H.X_BCE_RESTORE_DAYS,
H.X_BCE_RESTORE_TIER
H.X_BCE_RESTORE_TIER,
H.X_BCE_SYMLINK_TARGET,
H.X_BCE_FORBID_OVERWRITE
];
var metaSize = 0;
var headers = u.pick(options, function (value, key) {
Expand Down
2 changes: 2 additions & 0 deletions src/headers.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ exports.X_BCE_STORAGE_CLASS = 'x-bce-storage-class';
exports.X_BCE_SERVER_SIDE_ENCRYPTION = 'x-bce-server-side-encryption';
exports.X_BCE_RESTORE_DAYS = 'x-bce-restore-days';
exports.X_BCE_RESTORE_TIER = 'x-bce-restore-tier';
exports.X_BCE_SYMLINK_TARGET = 'x-bce-symlink-target';
exports.X_BCE_FORBID_OVERWRITE = 'x-bce-forbid-overwrite';

exports.X_HTTP_HEADERS = 'http_headers';
exports.X_BODY = 'body';
Expand Down
8 changes: 4 additions & 4 deletions test/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ module.exports = {
'ak': process.env.BOS_AK,
'sk': process.env.BOS_SK,
},
'account': {
'id': process.env.ONLINE_USER_ID || '04e0d2c9e8ef478c951b97714c092f77',
'displayName': process.env.ONLINE_USER_NAME || 'PASSPORT:105016607'
}
// 'account': {
// 'id': process.env.ONLINE_USER_ID || '04e0d2c9e8ef478c951b97714c092f77',
// 'displayName': process.env.ONLINE_USER_NAME || 'PASSPORT:105016607'
// }
},
'bcc': {
'endpoint': 'http://bcc.bce-api.baidu.com',
Expand Down
8 changes: 8 additions & 0 deletions test/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@

const BosClient = require('../').BosClient;
const config = require('./config');

console.log(config.bos);
const client = new BosClient(config.bos);

(async function () {})()

0 comments on commit 8903354

Please sign in to comment.