diff --git a/dist/index.d.ts b/dist/index.d.ts index e448010..76db495 100644 --- a/dist/index.d.ts +++ b/dist/index.d.ts @@ -1,14 +1,10 @@ interface Proxy { host: string; port: number; -} -interface SocksProxy extends Proxy { - protocol: 'socks5' | 'socks4'; + protocol: 'http' | 'https' | 'socks4' | 'socks5'; } interface Options { - httpProxy?: Proxy; - httpsProxy?: Proxy; - socksProxy?: SocksProxy; + proxy: Proxy; } interface Collection { name: string; @@ -44,4 +40,4 @@ declare class nextdav { private buildContentsObject; } -export { Collection, File, Options, Proxy, SocksProxy, nextdav as default }; +export { Collection, File, Options, Proxy, nextdav as default }; diff --git a/dist/index.js b/dist/index.js index ef88c6a..7600557 100644 --- a/dist/index.js +++ b/dist/index.js @@ -37,7 +37,6 @@ module.exports = __toCommonJS(src_exports); // src/nextdav.class.ts var import_url = require("url"); var import_path = require("path"); -var import_crypto = __toESM(require("crypto")); var import_fast_xml_parser = require("fast-xml-parser"); var import_http_proxy_agent = __toESM(require("http-proxy-agent")); var import_https_proxy_agent = __toESM(require("https-proxy-agent")); @@ -52,27 +51,34 @@ var nextdav = class { * Create WebDav client */ async getClient() { - var _a, _b, _c; + var _a; const gotModule = await import("got"); let httpAgent; - if ((_a = this.options) == null ? void 0 : _a.httpProxy) { - httpAgent = (0, import_http_proxy_agent.default)(this.options.httpProxy); - } let httpsAgent; - if ((_b = this.options) == null ? void 0 : _b.httpsProxy) { - httpsAgent = (0, import_https_proxy_agent.default)({ - host: this.options.httpsProxy.host, - port: this.options.httpsProxy.port, - secureOptions: import_crypto.default.constants.SSL_OP_LEGACY_SERVER_CONNECT - }); - } - if ((_c = this.options) == null ? void 0 : _c.socksProxy) { - httpAgent = new import_socks_proxy_agent.SocksProxyAgent( - `${this.options.socksProxy.protocol}://${this.options.socksProxy.host}:${this.options.socksProxy.port}` - ); - httpsAgent = new import_socks_proxy_agent.SocksProxyAgent( - `${this.options.socksProxy.protocol}://${this.options.socksProxy.host}:${this.options.socksProxy.port}` - ); + if ((_a = this.options) == null ? void 0 : _a.proxy) { + switch (this.options.proxy.protocol) { + case "http": + httpAgent = (0, import_http_proxy_agent.default)({ + host: this.options.proxy.host, + port: this.options.proxy.port + }); + break; + case "https": + httpsAgent = (0, import_https_proxy_agent.default)({ + host: this.options.proxy.host, + port: this.options.proxy.port + }); + break; + case "socks4": + case "socks5": + httpAgent = new import_socks_proxy_agent.SocksProxyAgent( + `${this.options.proxy.protocol}://${this.options.proxy.host}:${this.options.proxy.port}` + ); + httpsAgent = new import_socks_proxy_agent.SocksProxyAgent( + `${this.options.proxy.protocol}://${this.options.proxy.host}:${this.options.proxy.port}` + ); + break; + } } return gotModule.default.extend({ headers: { diff --git a/dist/index.mjs b/dist/index.mjs index 356809f..7d7c13e 100644 --- a/dist/index.mjs +++ b/dist/index.mjs @@ -1,7 +1,6 @@ // src/nextdav.class.ts import { URL } from "url"; import { join, basename, dirname } from "path"; -import crypto from "crypto"; import { XMLParser } from "fast-xml-parser"; import HttpProxyAgent from "http-proxy-agent"; import HttpsProxyAgent from "https-proxy-agent"; @@ -16,27 +15,34 @@ var nextdav = class { * Create WebDav client */ async getClient() { - var _a, _b, _c; + var _a; const gotModule = await import("got"); let httpAgent; - if ((_a = this.options) == null ? void 0 : _a.httpProxy) { - httpAgent = HttpProxyAgent(this.options.httpProxy); - } let httpsAgent; - if ((_b = this.options) == null ? void 0 : _b.httpsProxy) { - httpsAgent = HttpsProxyAgent({ - host: this.options.httpsProxy.host, - port: this.options.httpsProxy.port, - secureOptions: crypto.constants.SSL_OP_LEGACY_SERVER_CONNECT - }); - } - if ((_c = this.options) == null ? void 0 : _c.socksProxy) { - httpAgent = new SocksProxyAgent( - `${this.options.socksProxy.protocol}://${this.options.socksProxy.host}:${this.options.socksProxy.port}` - ); - httpsAgent = new SocksProxyAgent( - `${this.options.socksProxy.protocol}://${this.options.socksProxy.host}:${this.options.socksProxy.port}` - ); + if ((_a = this.options) == null ? void 0 : _a.proxy) { + switch (this.options.proxy.protocol) { + case "http": + httpAgent = HttpProxyAgent({ + host: this.options.proxy.host, + port: this.options.proxy.port + }); + break; + case "https": + httpsAgent = HttpsProxyAgent({ + host: this.options.proxy.host, + port: this.options.proxy.port + }); + break; + case "socks4": + case "socks5": + httpAgent = new SocksProxyAgent( + `${this.options.proxy.protocol}://${this.options.proxy.host}:${this.options.proxy.port}` + ); + httpsAgent = new SocksProxyAgent( + `${this.options.proxy.protocol}://${this.options.proxy.host}:${this.options.proxy.port}` + ); + break; + } } return gotModule.default.extend({ headers: { diff --git a/package.json b/package.json index 6318927..08f4553 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "nextdav", - "version": "0.0.11-dev", + "version": "0.0.12-dev", "description": "A WebDav client specifically created for Nextcloud", "main": "./dist/index.js", "module": "./dist/index.mjs",