nekosapi
Version:
Async wrapper for NekosAPI
41 lines • 1.66 kB
JavaScript
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const axios_1 = __importDefault(require("axios"));
const socks_proxy_agent_1 = require("socks-proxy-agent");
class Base {
socks5Proxy;
constructor(proxy) {
if (proxy) {
this.socks5Proxy = proxy;
}
}
async fetchResponse(url, config) {
const promise = async () => {
if (this.socks5Proxy != undefined) {
const proxyURL = `${this.socks5Proxy.protocol}://${this.socks5Proxy.auth.username}:${this.socks5Proxy.auth.password}@${this.socks5Proxy.host}:${this.socks5Proxy.port}`;
return axios_1.default.get(url.toString(), Object.assign({
httpsAgent: new socks_proxy_agent_1.SocksProxyAgent(proxyURL),
responseType: "json",
}, config));
}
else {
return axios_1.default.get(url.toString(), {
responseType: "json",
});
}
};
const response = await promise();
await Base.checkResponseCode(response);
return response.data;
}
static async checkResponseCode(response) {
if (response.status > 200 && response.status <= 300) {
throw new Error(`An error occurred while fetching data from the server. ${response.statusText}. Status: ${response.status}. ${response.request?.url || ""}`);
}
}
}
exports.default = Base;
//# sourceMappingURL=base.js.map
;