Skip to content

Commit

Permalink
chore: release 6.17.0 (#1047)
Browse files Browse the repository at this point in the history
* docs: update outdated links. (#976)

Co-authored-by: richex <i@richex.cn>

* feat: add new init params maxSockets

* feat: add develop gitaction (#1017)

* fix listV2 params error (#1011)

* chore: develop merge master (#1035)

sync master

* chore(CI):github action optimized (#1040)

* chore(test): test case optimized (#1041)

* fix: fix list() and listV2() params and test case (#1043)

* fix(test): test case optimized (#1044)

* fix(test): test case optimized (#1045)

* chore: use stream-http 2.8.2

* chore: rebuild

* chore: rebuild

* chore: document the completion

Co-authored-by: richex-cn <hzxtiger@vip.qq.com>
Co-authored-by: richex <i@richex.cn>
Co-authored-by: peize.rpz <peize.rpz@alibaba-inc.com>
Co-authored-by: taotao7 <moca_tao7@foxmail.com>
  • Loading branch information
5 people authored Jan 27, 2022
1 parent 17206a1 commit a759699
Show file tree
Hide file tree
Showing 14 changed files with 794 additions and 55 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.


## [6.16.0](https://github.com/aliyun/oss-nodejs-sdk/compare/v6.15.0...v6.16.0) (2021-07-12)


Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,7 @@ options:
- [enableProxy] {Boolean}, Enable proxy request, default is false.
- [proxy] {String | Object}, proxy agent uri or options, default is null.
- [retryMax] {Number}, used by auto retry send request count when request error is net error or timeout. **_NOTE:_** Not support `put` with stream, `putStream`, `append` with stream because the stream can only be consumed once
- [maxSockets] {Number} Maximum number of sockets to allow per host. Default is infinity

example:

Expand Down
3 changes: 2 additions & 1 deletion browser-build.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ function build(options, callback) {
builtins: {
...require("browserify/lib/builtins"),
_process: path.join(__dirname, "shims/process.js"),
url: path.join(__dirname, "shims/url/index.js")
url: path.join(__dirname, "shims/url/index.js"),
http: path.join(__dirname, "shims/stream-http/index.js")
}
};
browserify(brOpts).add('./lib/browser.js')
Expand Down
5 changes: 2 additions & 3 deletions example/src/template/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@
<html>
<head>
<title>OSS in Browser</title>
<link rel="stylesheet" href="https://cdn.bootcss.com/bootstrap/3.3.5/css/bootstrap.min.css" />
<script src="https://cdn.bootcss.com/jquery/3.3.1/jquery.min.js"></script>
<script src="https://cdn.bootcss.com/bootstrap/4.1.1/js/bootstrap.bundle.js"></script>
<link rel="stylesheet" href="https://cdn.bootcdn.net/ajax/libs/twitter-bootstrap/3.3.5/css/bootstrap.min.css" />
<script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
</head>
<body>
<div id="main">
Expand Down
14 changes: 7 additions & 7 deletions lib/browser/object.js
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ proto.list = async function list(query, options) {
params.successStatuses = [200];

const result = await this.request(params);
let objects = result.data.Contents;
let objects = result.data.Contents || [];
const that = this;
if (objects) {
if (!Array.isArray(objects)) {
Expand Down Expand Up @@ -220,8 +220,6 @@ proto.list = async function list(query, options) {

proto.listV2 = async function listV2(query, options = {}) {
const continuation_token = query['continuation-token'] || query.continuationToken;
delete query['continuation-token'];
delete query.continuationToken;
if (continuation_token) {
options.subres = Object.assign(
{
Expand All @@ -232,11 +230,13 @@ proto.listV2 = async function listV2(query, options = {}) {
}
const params = this._objectRequestParams('GET', '', options);
params.query = Object.assign({ 'list-type': 2 }, query);
delete params.query['continuation-token'];
delete params.query.continuationToken;
params.xmlResponse = true;
params.successStatuses = [200];

const result = await this.request(params);
let objects = result.data.Contents;
let objects = result.data.Contents || [];
const that = this;
if (objects) {
if (!Array.isArray(objects)) {
Expand All @@ -252,9 +252,9 @@ proto.listV2 = async function listV2(query, options = {}) {
storageClass: obj.StorageClass,
owner: obj.Owner
? {
id: obj.Owner.ID,
displayName: obj.Owner.DisplayName
}
id: obj.Owner.ID,
displayName: obj.Owner.DisplayName
}
: null
}));
}
Expand Down
45 changes: 29 additions & 16 deletions lib/client.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

const debug = require('debug')('ali-oss');
const sendToWormhole = require('stream-wormhole');
const xml = require('xml2js');
Expand Down Expand Up @@ -38,6 +37,10 @@ function Client(options, ctx) {
this.urllib = this.options.urllib;
} else {
this.urllib = urllib;
if (this.options.maxSockets) {
globalHttpAgent.maxSockets = this.options.maxSockets;
globalHttpsAgent.maxSockets = this.options.maxSockets;
}
this.agent = this.options.agent || globalHttpAgent;
this.httpsAgent = this.options.httpsAgent || globalHttpsAgent;
}
Expand Down Expand Up @@ -146,7 +149,12 @@ proto.authorization = function authorization(method, resource, subres, headers)
parameters: subres
});

return signUtils.authorization(this.options.accessKeyId, this.options.accessKeySecret, stringToSign, this.options.headerEncoding);
return signUtils.authorization(
this.options.accessKeyId,
this.options.accessKeySecret,
stringToSign,
this.options.headerEncoding
);
};

/**
Expand Down Expand Up @@ -247,7 +255,7 @@ proto._escape = function _escape(name) {
*/

proto._getUserAgent = function _getUserAgent() {
const agent = (process && process.browser) ? 'js' : 'nodejs';
const agent = process && process.browser ? 'js' : 'nodejs';
const sdk = `aliyun-sdk-${agent}/${pkg.version}`;
let plat = platform.description;
if (!plat && process) {
Expand All @@ -271,7 +279,7 @@ proto._checkUserAgent = function _checkUserAgent(ua) {
*/

proto.checkBrowserAndVersion = function checkBrowserAndVersion(name, version) {
return ((bowser.name === name) && (bowser.version.split('.')[0] === version));
return bowser.name === name && bowser.version.split('.')[0] === version;
};

/**
Expand All @@ -286,16 +294,20 @@ proto.parseXML = function parseXMLThunk(str) {
if (Buffer.isBuffer(str)) {
str = str.toString();
}
xml.parseString(str, {
explicitRoot: false,
explicitArray: false
}, (err, result) => {
if (err) {
reject(err);
} else {
resolve(result);
xml.parseString(
str,
{
explicitRoot: false,
explicitArray: false
},
(err, result) => {
if (err) {
reject(err);
} else {
resolve(result);
}
}
});
);
});
};

Expand All @@ -312,7 +324,8 @@ proto.requestError = async function requestError(result) {
err = new Error(result.message);
err.name = result.name;
} else if (!result.data || !result.data.length) {
if (result.status === -1 || result.status === -2) { // -1 is net error , -2 is timeout
if (result.status === -1 || result.status === -2) {
// -1 is net error , -2 is timeout
err = new Error(result.message);
err.name = result.name;
err.status = result.status;
Expand Down Expand Up @@ -343,7 +356,7 @@ proto.requestError = async function requestError(result) {

let info;
try {
info = await this.parseXML(message) || {};
info = (await this.parseXML(message)) || {};
} catch (error) {
debug(message);
error.message += `\nraw xml: ${message}`;
Expand All @@ -352,7 +365,7 @@ proto.requestError = async function requestError(result) {
return error;
}

let msg = info.Message || (`unknow request error, status: ${result.status}`);
let msg = info.Message || `unknow request error, status: ${result.status}`;
if (info.Condition) {
msg += ` (condition: ${info.Condition})`;
}
Expand Down
6 changes: 4 additions & 2 deletions lib/object.js
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ proto.list = async function list(query, options) {
params.successStatuses = [200];

const result = await this.request(params);
let objects = result.data.Contents;
let objects = result.data.Contents || [];
const that = this;
if (objects) {
if (!Array.isArray(objects)) {
Expand Down Expand Up @@ -254,11 +254,13 @@ proto.listV2 = async function listV2(query = {}, options = {}) {
}
const params = this._objectRequestParams('GET', '', options);
params.query = Object.assign({ 'list-type': 2 }, query);
delete params.query['continuation-token'];
delete query.continuationToken;
params.xmlResponse = true;
params.successStatuses = [200];

const result = await this.request(params);
let objects = result.data.Contents;
let objects = result.data.Contents || [];
const that = this;
if (objects) {
if (!Array.isArray(objects)) {
Expand Down
86 changes: 86 additions & 0 deletions shims/stream-http/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
//"version": "2.8.2",
var ClientRequest = require('./lib/request')
var response = require('./lib/response')
var extend = require('xtend')
var statusCodes = require('builtin-status-codes')
var url = require('url')

var http = exports

http.request = function (opts, cb) {
if (typeof opts === 'string')
opts = url.parse(opts)
else
opts = extend(opts)

// Normally, the page is loaded from http or https, so not specifying a protocol
// will result in a (valid) protocol-relative url. However, this won't work if
// the protocol is something else, like 'file:'
var defaultProtocol = global.location.protocol.search(/^https?:$/) === -1 ? 'http:' : ''

var protocol = opts.protocol || defaultProtocol
var host = opts.hostname || opts.host
var port = opts.port
var path = opts.path || '/'

// Necessary for IPv6 addresses
if (host && host.indexOf(':') !== -1)
host = '[' + host + ']'

// This may be a relative url. The browser should always be able to interpret it correctly.
opts.url = (host ? (protocol + '//' + host) : '') + (port ? ':' + port : '') + path
opts.method = (opts.method || 'GET').toUpperCase()
opts.headers = opts.headers || {}

// Also valid opts.auth, opts.mode

var req = new ClientRequest(opts)
if (cb)
req.on('response', cb)
return req
}

http.get = function get (opts, cb) {
var req = http.request(opts, cb)
req.end()
return req
}

http.ClientRequest = ClientRequest
http.IncomingMessage = response.IncomingMessage

http.Agent = function () {}
http.Agent.defaultMaxSockets = 4

http.globalAgent = new http.Agent()

http.STATUS_CODES = statusCodes

http.METHODS = [
'CHECKOUT',
'CONNECT',
'COPY',
'DELETE',
'GET',
'HEAD',
'LOCK',
'M-SEARCH',
'MERGE',
'MKACTIVITY',
'MKCOL',
'MOVE',
'NOTIFY',
'OPTIONS',
'PATCH',
'POST',
'PROPFIND',
'PROPPATCH',
'PURGE',
'PUT',
'REPORT',
'SEARCH',
'SUBSCRIBE',
'TRACE',
'UNLOCK',
'UNSUBSCRIBE'
]
73 changes: 73 additions & 0 deletions shims/stream-http/lib/capability.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
exports.fetch = isFunction(global.fetch) && isFunction(global.ReadableStream)

exports.writableStream = isFunction(global.WritableStream)

exports.abortController = isFunction(global.AbortController)

exports.blobConstructor = false
try {
new Blob([new ArrayBuffer(1)])
exports.blobConstructor = true
} catch (e) {}

// The xhr request to example.com may violate some restrictive CSP configurations,
// so if we're running in a browser that supports `fetch`, avoid calling getXHR()
// and assume support for certain features below.
var xhr
function getXHR () {
// Cache the xhr value
if (xhr !== undefined) return xhr

if (global.XMLHttpRequest) {
xhr = new global.XMLHttpRequest()
// If XDomainRequest is available (ie only, where xhr might not work
// cross domain), use the page location. Otherwise use example.com
// Note: this doesn't actually make an http request.
try {
xhr.open('GET', global.XDomainRequest ? '/' : 'https://example.com')
} catch(e) {
xhr = null
}
} else {
// Service workers don't have XHR
xhr = null
}
return xhr
}

function checkTypeSupport (type) {
var xhr = getXHR()
if (!xhr) return false
try {
xhr.responseType = type
return xhr.responseType === type
} catch (e) {}
return false
}

// For some strange reason, Safari 7.0 reports typeof global.ArrayBuffer === 'object'.
// Safari 7.1 appears to have fixed this bug.
var haveArrayBuffer = typeof global.ArrayBuffer !== 'undefined'
var haveSlice = haveArrayBuffer && isFunction(global.ArrayBuffer.prototype.slice)

// If fetch is supported, then arraybuffer will be supported too. Skip calling
// checkTypeSupport(), since that calls getXHR().
exports.arraybuffer = exports.fetch || (haveArrayBuffer && checkTypeSupport('arraybuffer'))

// These next two tests unavoidably show warnings in Chrome. Since fetch will always
// be used if it's available, just return false for these to avoid the warnings.
exports.msstream = !exports.fetch && haveSlice && checkTypeSupport('ms-stream')
exports.mozchunkedarraybuffer = !exports.fetch && haveArrayBuffer &&
checkTypeSupport('moz-chunked-arraybuffer')

// If fetch is supported, then overrideMimeType will be supported too. Skip calling
// getXHR().
exports.overrideMimeType = exports.fetch || (getXHR() ? isFunction(getXHR().overrideMimeType) : false)

exports.vbArray = isFunction(global.VBArray)

function isFunction (value) {
return typeof value === 'function'
}

xhr = null // Help gc
Loading

0 comments on commit a759699

Please sign in to comment.