You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
parttimejob/node_modules/ali-oss/lib/setConfig.ts

53 lines
1.1 KiB

1 month ago
import urllib from 'urllib';
import AgentKeepalive from 'agentkeepalive';
import { getUserAgent } from './common/utils/getUserAgent';
import initOptions from './common/client/initOptions';
const HttpsAgentKeepalive = AgentKeepalive.HttpsAgent;
const globalHttpAgent = new AgentKeepalive();
const globalHttpsAgent = new HttpsAgentKeepalive();
class Client {
options;
urllib;
agent;
httpsAgent;
ctx;
userAgent;
constructor(options, ctx) {
if (!(this instanceof Client)) {
return new Client(options, ctx);
}
if (options && options.inited) {
this.options = options;
} else {
this.options = initOptions(options);
}
// support custom agent and urllib client
if (this.options.urllib) {
this.urllib = this.options.urllib;
} else {
this.urllib = urllib;
this.agent = this.options.agent || globalHttpAgent;
this.httpsAgent = this.options.httpsAgent || globalHttpsAgent;
}
this.ctx = ctx;
this.userAgent = getUserAgent();
}
}
let client;
export const setConfig = (options, ctx) => {
client = new Client(options, ctx);
};
export { client };