bce-sdk-js
Advanced tools
Comparing version 0.2.1 to 0.2.2
@@ -44,2 +44,1 @@ /** | ||
/* vim: set ts=4 sw=4 sts=4 tw=120: */ |
{ | ||
"name": "bce-sdk-js", | ||
"version": "0.2.1", | ||
"version": "0.2.2", | ||
"description": "Baidu Cloud Engine JavaScript SDK", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -166,2 +166,1 @@ /** | ||
/* vim: set ts=4 sw=4 sts=4 tw=120: */ |
@@ -101,3 +101,3 @@ /** | ||
/* | ||
/** | ||
var body = { | ||
@@ -222,2 +222,1 @@ // MICRO,SMALL,MEDIUM,LARGE,XLARGE,XXLARGE | ||
/* vim: set ts=4 sw=4 sts=4 tw=120: */ |
@@ -114,2 +114,1 @@ /** | ||
/* vim: set ts=4 sw=4 sts=4 tw=120: */ |
@@ -350,7 +350,1 @@ /** | ||
/* vim: set ts=4 sw=4 sts=4 tw=120: */ |
@@ -35,2 +35,1 @@ /** | ||
/* vim: set ts=4 sw=4 sts=4 tw=120: */ |
@@ -83,2 +83,1 @@ /** | ||
/* vim: set ts=4 sw=4 sts=4 tw=120: */ |
@@ -224,2 +224,1 @@ /** | ||
/* vim: set ts=4 sw=4 sts=4 tw=120: */ |
@@ -63,2 +63,1 @@ /** | ||
/* vim: set ts=4 sw=4 sts=4 tw=120: */ |
@@ -35,2 +35,6 @@ /** | ||
exports.omitNull = function (value, key, object) { | ||
return value != null; | ||
}; | ||
/** | ||
@@ -192,3 +196,3 @@ * 自适应的按需上传文件 | ||
/*eslint-disable*/ | ||
var _partSize = Math.min(leftSize, partSize); | ||
var xPartSize = Math.min(leftSize, partSize); | ||
/*eslint-enable*/ | ||
@@ -201,9 +205,9 @@ tasks.push({ | ||
partNumber: partNumber, | ||
partSize: _partSize, | ||
partSize: xPartSize, | ||
start: offset, | ||
stop: offset + _partSize - 1 | ||
stop: offset + xPartSize - 1 | ||
}); | ||
leftSize -= _partSize; | ||
offset += _partSize; | ||
leftSize -= xPartSize; | ||
offset += xPartSize; | ||
partNumber += 1; | ||
@@ -225,2 +229,1 @@ } | ||
/* vim: set ts=4 sw=4 sts=4 tw=120: */ |
@@ -19,2 +19,3 @@ /** | ||
/* eslint max-params:[0,10] */ | ||
/* globals ArrayBuffer */ | ||
@@ -225,3 +226,3 @@ var http = require('http'); | ||
} | ||
/* | ||
/** | ||
if (typeof FormData !== 'undefined' && data instanceof FormData) { | ||
@@ -409,2 +410,1 @@ } | ||
/* vim: set ts=4 sw=4 sts=4 tw=120: */ |
@@ -285,2 +285,1 @@ /** | ||
/* vim: set ts=4 sw=4 sts=4 tw=120: */ |
@@ -470,2 +470,1 @@ /** | ||
/* vim: set ts=4 sw=4 sts=4 tw=120: */ |
@@ -230,2 +230,1 @@ /** | ||
/* vim: set ts=4 sw=4 sts=4 tw=120: */ |
@@ -25,2 +25,3 @@ /** | ||
* @param {string} boundary The multipart boundary. | ||
* @constructor | ||
*/ | ||
@@ -84,2 +85,1 @@ function Multipart(boundary) { | ||
/* vim: set ts=4 sw=4 sts=4 tw=120: */ |
@@ -91,2 +91,1 @@ /** | ||
/* vim: set ts=4 sw=4 sts=4 tw=120: */ |
@@ -288,2 +288,1 @@ /** | ||
/* vim: set ts=4 sw=4 sts=4 tw=120: */ |
@@ -169,5 +169,1 @@ /** | ||
/* vim: set ts=4 sw=4 sts=4 tw=120: */ |
@@ -42,2 +42,1 @@ /** | ||
/* vim: set ts=4 sw=4 sts=4 tw=120: */ |
@@ -71,2 +71,1 @@ /** | ||
/* vim: set ts=4 sw=4 sts=4 tw=120: */ |
@@ -26,4 +26,9 @@ /** | ||
var BosClient = require('./bos_client'); | ||
var H = require('./headers'); | ||
var helper = require('./helper'); | ||
var Media = require('./vod/Media'); | ||
var Notification = require('./vod/Notification'); | ||
var Player = require('./vod/Player'); | ||
var PresetGroup = require('./vod/PresetGroup'); | ||
var Statistic = require('./vod/Statistic'); | ||
var StrategyGroup = require('./vod/StrategyGroup'); | ||
@@ -41,17 +46,2 @@ /** | ||
BceBaseClient.call(this, config, 'vod', false); | ||
var bosConfig = this.config.bos || {}; | ||
if (!bosConfig.credentials) { | ||
bosConfig.credentials = this.config.credentials; | ||
} | ||
if (!bosConfig.sessionToken) { | ||
bosConfig.sessionToken = this.config.sessionToken; | ||
} | ||
this._bosClient = new BosClient(bosConfig); | ||
var client = this; | ||
this._bosClient.on('progress', function (evt) { | ||
client.emit('progress', evt); | ||
}); | ||
} | ||
@@ -63,23 +53,25 @@ util.inherits(VodClient, BceBaseClient); | ||
VodClient.prototype.createMediaResource = function (title, description, blob, options) { | ||
options = options || {}; | ||
var mediaId; | ||
var client = this; | ||
var bosClient = this._bosClient; | ||
return client._generateMediaId(options) | ||
.then(function (res) { | ||
mediaId = res.body.mediaId; | ||
return helper.upload(bosClient, res.body.sourceBucket, res.body.sourceKey, blob, options); | ||
}) | ||
.then(function () { | ||
return client._createMediaResource(mediaId, title, description, options); | ||
var self = this; | ||
var mediaClient = new Media(this.config); | ||
return mediaClient.apply().then(function (res) { | ||
var bosClient = new BosClient({ | ||
endpoint: 'http://' + res.body.host, | ||
credentials: self.config.credentials, | ||
sessionToken: self.config.sessionToken | ||
}); | ||
bosClient.on('progress', function (evt) { | ||
self.emit('progress', evt); | ||
}); | ||
return helper.upload(bosClient, res.body.sourceBucket, res.body.sourceKey, blob, options); | ||
}).then(function () { | ||
return mediaClient.process(title, u.extend({description: description}, options)); | ||
}); | ||
}; | ||
VodClient.prototype.getMediaResource = function (mediaId, options) { | ||
return this.buildRequest('GET', mediaId, null, options); | ||
VodClient.prototype.getMediaResource = function (mediaId) { | ||
return new Media(this.config).setMediaId(mediaId).get(); | ||
}; | ||
VodClient.prototype.listMediaResource = function (options) { | ||
return this.buildRequest('GET', null, null, options); | ||
return new Media(this.config).list(options); | ||
}; | ||
@@ -91,97 +83,49 @@ | ||
VodClient.prototype.updateMediaResource = function (mediaId, title, description, options) { | ||
options = options || {}; | ||
return this.buildRequest('PUT', mediaId, 'attributes', u.extend(options, { | ||
body: JSON.stringify({ | ||
title: title, | ||
description: description | ||
}) | ||
})); | ||
VodClient.prototype.updateMediaResource = function (mediaId, title, description) { | ||
return new Media(this.config).setMediaId(mediaId).update(title, description); | ||
}; | ||
VodClient.prototype.stopMediaResource = function (mediaId, options) { | ||
return this.buildRequest('PUT', mediaId, 'disable', options); | ||
return new Media(this.config).setMediaId(mediaId).disable(); | ||
}; | ||
VodClient.prototype.publishMediaResource = function (mediaId, options) { | ||
return this.buildRequest('PUT', mediaId, 'publish', options); | ||
return new Media(this.config).setMediaId(mediaId).resume(); | ||
}; | ||
VodClient.prototype.deleteMediaResource = function (mediaId, options) { | ||
return this.buildRequest('DELETE', mediaId, null, options); | ||
return new Media(this.config).setMediaId(mediaId).remove(); | ||
}; | ||
VodClient.prototype.rerunMediaResource = function (mediaId, options) { | ||
return this.buildRequest('PUT', mediaId, 'rerun', options); | ||
VodClient.prototype.getPlayableUrl = function (mediaId, transcodingPresetName) { | ||
return new Player(this.config).setMediaId(mediaId).delivery(transcodingPresetName); | ||
}; | ||
VodClient.prototype.getPlayableUrl = function (mediaId, options) { | ||
var url = '/v1/media/' + mediaId + '/delivery'; | ||
return this._buildRequest('GET', url, null, null, options); | ||
}; | ||
VodClient.prototype.getPlayerCode = function (mediaId, width, height, autoStart, options) { | ||
var url = '/v1/media/' + mediaId + '/code'; | ||
options = options || {}; | ||
return this._buildRequest('GET', url, null, null, u.extend(options, { | ||
params: { | ||
ak: this.config.credentials.ak, | ||
width: width, | ||
height: height, | ||
autostart: autoStart | ||
} | ||
})); | ||
return new Player(this.config).setMediaId(mediaId).code(u.extend({ | ||
ak: this.config.credentials.ak, | ||
width: width, | ||
height: height, | ||
autostart: autoStart | ||
}, options)); | ||
}; | ||
VodClient.prototype._generateMediaId = function (options) { | ||
return this.buildRequest('POST', null, 'apply', options); | ||
VodClient.prototype._generateMediaId = function () { | ||
return new Media(this.config).apply(); | ||
}; | ||
VodClient.prototype._createMediaResource = function (mediaId, title, description, options) { | ||
var params = {title: title}; | ||
if (description) { | ||
params.description = description; | ||
} | ||
options = options || {}; | ||
if (options.sourceExtension) { | ||
params.sourceExtension = options.sourceExtension; | ||
delete options.sourceExtension; | ||
} | ||
return this.buildRequest('PUT', mediaId, 'process', u.extend(options, { | ||
body: JSON.stringify(params) | ||
})); | ||
return new Media(this.config).setMediaId(mediaId).process(title, u.extend({ | ||
description: description | ||
}, options)); | ||
}; | ||
// --- E N D --- | ||
VodClient.prototype.buildRequest = function (verb, mediaId, query, options) { | ||
return this._buildRequest(verb, '/v1/media', mediaId, query, options); | ||
}; | ||
VodClient.Media = Media; | ||
VodClient.Notification = Notification; | ||
VodClient.Player = Player; | ||
VodClient.PresetGroup = PresetGroup; | ||
VodClient.Statistic = Statistic; | ||
VodClient.StrategyGroup = StrategyGroup; | ||
VodClient.prototype._buildRequest = function (verb, url, mediaId, query, options) { | ||
var defaultArgs = { | ||
body: null, | ||
headers: {}, | ||
params: {}, | ||
config: {} | ||
}; | ||
options = u.extend(defaultArgs, options); | ||
if (mediaId) { | ||
url += '/' + mediaId; | ||
} | ||
if (query) { | ||
options.params[query] = ''; | ||
} | ||
if (!options.headers.hasOwnProperty(H.CONTENT_TYPE)) { | ||
options.headers[H.CONTENT_TYPE] = 'application/json'; | ||
} | ||
if (!options.headers.hasOwnProperty(H.ACCEPT_ENCODING)) { | ||
options.headers[H.ACCEPT_ENCODING] = 'gzip, deflate'; | ||
} | ||
if (!options.headers.hasOwnProperty(H.ACCEPT)) { | ||
options.headers[H.ACCEPT] = '*/*'; | ||
} | ||
return this.sendRequest(verb, url, options); | ||
}; | ||
// --- E N D --- | ||
module.exports = VodClient; |
@@ -44,10 +44,1 @@ /** | ||
/* vim: set ts=4 sw=4 sts=4 tw=120: */ |
59
x.js
@@ -15,39 +15,42 @@ /** | ||
var BosClient = require('.').BosClient; | ||
var DocClient = require('.').DocClient; | ||
var config = { | ||
credentials: { | ||
ak: '503b4e569beb4ce880c74128dcac7526', | ||
sk: '2f42945972d4497b930ab6a369bfc333' | ||
ak: 'dc15dad4c4fb470b9f531b152dbc34cd', | ||
sk: 'cf399b4c220f425988271ec618bf462a' | ||
} | ||
}; | ||
var bucket = 'yuedu-cms'; | ||
var client = new BosClient(config); | ||
client.listBuckets().then(function (response) { | ||
console.log(response.body); | ||
}).catch(function (error) { | ||
console.log(error); | ||
}); | ||
/* | ||
var client = new BosClient(config); | ||
var headers = { | ||
'Expires': '-1', | ||
'Cache-Control': 'no-cache' | ||
}; | ||
function listAllObjects(bucket) { | ||
var objects = []; | ||
var dirs = []; | ||
client.putObjectFromFile('bce-bos-uploader', 'x.js', __filename, headers); | ||
*/ | ||
return new Promise(function (resolve, reject) { | ||
function listObjects(opt_marker) { | ||
var marker = opt_marker || ''; | ||
client.listObjects(bucket, {marker: marker, maxKeys: 1000, delimiter:'/'}) | ||
.then(function (response) { | ||
objects.push.apply(objects, response.body.contents); | ||
dirs.push.apply(dirs, response.body.commonPrefixes || []); | ||
if (response.body.isTruncated === false) { | ||
dirs = dirs.map(item => item.prefix); | ||
resolve({objects, dirs}); | ||
} | ||
else { | ||
return listObjects(response.body.nextMarker); | ||
} | ||
}) | ||
.catch(function (error) { | ||
console.log(error); | ||
}); | ||
} | ||
listObjects(); | ||
}); | ||
} | ||
/* | ||
var doc = new DocClient.Document(config); | ||
var bucket = 'bce-bos-uploader'; | ||
var object = '为高效开票服务的一些优化点.docx'; | ||
doc.createFromBos(bucket, object, 'a.docx', 'docx') | ||
.then(function (response) { | ||
console.log(response); | ||
}) | ||
.catch(function (error) { | ||
console.log(error); | ||
}); | ||
*/ | ||
listAllObjects(bucket).then(function (response) { | ||
console.log(response); | ||
}); |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
11158553
146
36007