Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

ali-oss

Package Overview
Dependencies
Maintainers
2
Versions
127
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ali-oss - npm Package Compare versions

Comparing version 2.1.0 to 2.2.0

lib/image.js

5

History.md
2.2.0 / 2015-04-02
==================
* Image service API (@zensh)
2.1.0 / 2015-03-23

@@ -3,0 +8,0 @@ ==================

24

lib/client.js

@@ -53,3 +53,3 @@ /**!

timeout: '60s',
bucket: null,
bucket: null
};

@@ -77,2 +77,6 @@

merge(proto, require('./bucket'));
/**
* ImageClient class
*/
Client.ImageClient = require('./image')(Client);

@@ -163,3 +167,3 @@ proto.setRegion = function (region) {

proto.request = function* (params) {
var host = this.options.host;
var host = params.host || this.options.host;
if (params.region) {

@@ -169,8 +173,11 @@ host = this._getRegionHost(params.region);

var headers = {
Date: new Date().toGMTString(),
Host: host
Date: new Date().toGMTString()
};
if (params.content || params.stream) {
headers['Content-Type'] = mime.lookup(params.mime || path.extname(params.name));
if (params.mime && params.mime.indexOf('/') > 0) {
headers['Content-Type'] = params.mime;
} else {
headers['Content-Type'] = mime.lookup(params.mime || path.extname(params.name));
}
if (params.content) {

@@ -190,9 +197,2 @@ headers['Content-Md5'] = crypto

var resource = params.resource;
if (!resource) {
if (!this.options.bucket) {
throw new Error('Please create a bucket first');
}
resource = '/' + this.options.bucket + '/' + params.name;
}
var authResource = params.authResource || resource;

@@ -199,0 +199,0 @@ headers.authorization = this.authorization(params.method, authResource, headers);

@@ -32,27 +32,23 @@ /**!

proto.put = function* (name, file, options) {
name = this._objectName(name);
options = options || {};
var data = yield* this._getContent(file);
var headers = options.headers || {};
this._convertMetaToHeaders(options.meta, headers);
options.headers = options.headers || {};
convertMetaToHeaders(options.meta, options.headers);
if (!headers['Content-Length']) {
if (!options.headers['Content-Length']) {
if (data.size === null) {
throw new TypeError('streaming upload must given the `Content-Length` header');
}
headers['Content-Length'] = data.size;
options.headers['Content-Length'] = data.size;
}
var result = yield* this.request({
name: name,
content: data.content,
stream: data.stream,
headers: headers,
timeout: options.timeout,
mime: options.mime,
method: 'PUT',
successStatuses: [200]
});
var params = this._objectRequestParams('PUT', name, options);
params.mime = options.mime;
params.stream = data.stream;
params.content = data.content;
params.successStatuses = [200];
var result = yield* this.request(params);
return {

@@ -65,16 +61,11 @@ name: name,

proto.head = function* (name, options) {
name = this._objectName(name);
options = options || {};
var result = yield* this.request({
name: name,
timeout: options.timeout,
headers: options.headers,
method: 'HEAD',
successStatuses: [200, 304]
});
var params = this._objectRequestParams('HEAD', name, options);
params.successStatuses = [200, 304];
var result = yield* this.request(params);
var data = {
status: result.status,
meta: null,
res: result.res,
status: result.status
};

@@ -96,3 +87,2 @@

proto.get = function* (name, file, options) {
name = this._objectName(name);
var writeStream = null;

@@ -114,10 +104,8 @@ var needDestroy = false;

try {
result = yield* this.request({
name: name,
headers: options.headers,
timeout: options.timeout,
method: 'GET',
writeStream: writeStream,
successStatuses: [200, 206, 304]
});
var params = this._objectRequestParams('GET', name, options);
params.writeStream = writeStream;
params.successStatuses = [200, 206, 304];
result = yield* this.request(params);
if (needDestroy) {

@@ -137,4 +125,4 @@ writeStream.destroy();

return {
content: result.data,
res: result.res,
content: result.data
};

@@ -144,13 +132,9 @@ };

proto.getStream = function* (name, options) {
name = this._objectName(name);
options = options || {};
var result = yield* this.request({
name: name,
headers: options.headers,
timeout: options.timeout,
method: 'GET',
successStatuses: [200, 304],
customResponse: true,
});
var params = this._objectRequestParams('GET', name, options);
params.customResponse = true;
params.successStatuses = [200, 206, 304];
var result = yield* this.request(params);
return {

@@ -166,10 +150,7 @@ stream: result.res,

proto.delete = function* (name, options) {
name = this._objectName(name);
var result = yield* this.request({
name: name,
method: 'DELETE',
timeout: options && options.timeout,
successStatuses: [204]
});
var params = this._objectRequestParams('DELETE', name, options);
params.successStatuses = [204];
var result = yield* this.request(params);
return {

@@ -193,12 +174,11 @@ res: result.res

debug('delete multi objects: %s', xml);
var result = yield this.request({
method: 'POST',
name: '?delete',
content: xml,
mime: 'xml',
timeout: options.timeout,
successStatuses: [200],
xmlResponse: true,
});
var params = this._objectRequestParams('POST', '?delete', options);
params.mime = 'xml';
params.content = xml;
params.xmlResponse = true;
params.successStatuses = [200];
var result = yield* this.request(params);
var r = result.data;

@@ -215,4 +195,4 @@ var deleted = r && r.Deleted || null;

return {
deleted: deleted,
res: result.res,
deleted: deleted
};

@@ -222,29 +202,25 @@ };

proto.copy = function* (name, sourceName, options) {
name = this._objectName(name);
if (sourceName[0] !== '/') {
// copy same bucket object
sourceName = '/' + this.options.bucket + '/' + sourceName;
}
options = options || {};
var headers = options.headers || {};
for (var k in headers) {
headers['x-oss-copy-source-' + k.toLowerCase()] = headers[k];
options.headers = options.headers || {};
for (var k in options.headers) {
options.headers['x-oss-copy-source-' + k.toLowerCase()] = options.headers[k];
}
if (options.meta) {
headers['x-oss-metadata-directive'] = 'REPLACE';
options.headers['x-oss-metadata-directive'] = 'REPLACE';
}
this._convertMetaToHeaders(options.meta, headers);
convertMetaToHeaders(options.meta, options.headers);
headers['x-oss-copy-source'] = sourceName;
if (sourceName[0] !== '/') {
// copy same bucket object
sourceName = '/' + this.options.bucket + '/' + sourceName;
}
options.headers['x-oss-copy-source'] = sourceName;
var result = yield* this.request({
method: 'PUT',
name: name,
headers: headers,
timeout: options.timeout,
successStatuses: [200, 304],
xmlResponse: true,
});
var params = this._objectRequestParams('PUT', name, options);
params.xmlResponse = true;
params.successStatuses = [200, 304];
var result = yield* this.request(params);
var data = result.data;

@@ -273,11 +249,10 @@ if (data) {

// prefix, marker, max-keys, delimiter
var result = yield* this.request({
method: 'GET',
name: '',
query: query,
timeout: options && options.timeout,
successStatuses: [200],
xmlResponse: true,
});
var params = this._objectRequestParams('GET', '', options);
params.query = query;
params.xmlResponse = true;
params.successStatuses = [200];
var result = yield* this.request(params);
var objects = result.data.Contents;

@@ -313,12 +288,14 @@ if (objects) {

return {
res: result.res,
objects: objects,
prefixes: prefixes,
isTruncated: result.data.IsTruncated === 'true',
nextMarker: result.data.NextMarker || null,
res: result.res
isTruncated: result.data.IsTruncated === 'true'
};
};
proto.signatureUrl = function (name) {
var resourceName = '/' + this.options.bucket + '/' + name;
proto.signatureUrl = function (name, customHost) {
name = this._objectName(name);
var options = this.options;
var authResource = '/' + options.bucket + '/' + name;
var expires = utility.timestamp() + 1800;

@@ -330,3 +307,3 @@ var params = [

expires, // Expires
resourceName,
authResource
];

@@ -336,30 +313,12 @@

var signature = crypto.createHmac('sha1', this.options.accessKeySecret);
var signature = crypto.createHmac('sha1', options.accessKeySecret);
signature = signature.update(params.join('\n')).digest('base64');
var url = this._objectUrl(name);
return url + '?OSSAccessKeyId=' + encodeURIComponent(this.options.accessKeyId) +
'&Expires=' + expires + '&Signature=' + encodeURIComponent(signature);
};
proto._objectName = function (name) {
if (name[0] === '/') {
name = name.substring(1);
}
return name;
};
var url = 'http://';
url += customHost ? (customHost + '/' + name) : (options.host + authResource);
proto._objectUrl = function (name) {
return 'http://' + this.options.host + '/' + this.options.bucket + '/' + name;
return url + '?OSSAccessKeyId=' + encodeURIComponent(options.accessKeyId) +
'&Expires=' + expires + '&Signature=' + encodeURIComponent(signature);
};
proto._convertMetaToHeaders = function (meta, headers) {
if (!meta) {
return;
}
for (var k in meta) {
headers['x-oss-meta-' + k] = meta[k];
}
};
/**

@@ -403,2 +362,44 @@ * get content from string(file path), buffer(file content), stream(file stream)

/**
* generator request params
* @return {Object} params
*
* @api private
*/
proto._objectRequestParams = function (method, name, options) {
if (!this.options.bucket) {
throw new Error('Please create a bucket first');
}
options = options || {};
name = this._objectName(name);
var resource = '/' + this.options.bucket + '/' + name;
var params = {
name: name,
method: method,
resource: resource,
timeout: options.timeout
};
if (options.headers) {
params.headers = options.headers;
}
return params;
};
proto._objectName = function (name) {
return name.replace(/^\/+/, '');
};
function convertMetaToHeaders(meta, headers) {
if (!meta) {
return;
}
for (var k in meta) {
headers['x-oss-meta-' + k] = meta[k];
}
}
function statFile(filepath) {

@@ -405,0 +406,0 @@ return function (callback) {

{
"name": "ali-oss",
"version": "2.1.0",
"version": "2.2.0",
"description": "aliyun oss(open storage service) node client",

@@ -5,0 +5,0 @@ "main": "index.js",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc