cataclym / nekosapi Goto Github PK
View Code? Open in Web Editor NEWAsync API wrapper for Nekos API
Home Page: https://www.npmjs.com/package/nekosapi
Async API wrapper for Nekos API
Home Page: https://www.npmjs.com/package/nekosapi
https://nekos.nekidev.com/ will stop working in about 15 days. The best choice would be to move to https://v1.nekosapi.com/api/ . It points to the same host but that domain won't expire.
(Another choice would be to use https://api.nekosapi.com/v1/ but that points to nekosapi's server which proxies the connection to vercel. It'd end up making requests take more to complete)
Hello! Please, add proxy support. I think is not currently supported by native fetch
, so I'm using it with axios, like:
import {NekosAPI} from "nekosapi/v3/index.js";
import { SocksProxyAgent } from "socks-proxy-agent";
import axios, { AxiosResponse } from "axios";
type ProxyAuth = {
username: string;
password: string;
}
type CustomProxy = {
protocol: string;
host: string;
port: number;
auth: ProxyAuth;
}
export const Socks5Proxy: CustomProxy = {
protocol: 'socks5',
host: process.env.PROXY_HOST!,
port: parseFloat(process.env.PROXY_PORT!),
auth: {
username: process.env.PROXY_USER != undefined ? process.env.PROXY_USER : "",
password: process.env.PROXY_PASS != undefined ? process.env.PROXY_PASS : ""
}
}
function checkResponseCode(response: AxiosResponse<any, any>) {
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}`)
}
}
async function fetchResponse<T>(url: URL): Promise<T> {
const proxy = process.env.PROXY_HOST != undefined ? Socks5Proxy : false;
let agent;
if (proxy) {
const proxyURL = `${proxy.protocol}://${proxy.auth.username}:${proxy.auth.password}@${proxy.host}:${proxy.port}`;
agent = new SocksProxyAgent(proxyURL);
}
const response = await axios.get(
url.toString(),
{
httpsAgent: agent,
responseType: "json"
}
)
checkResponseCode(response);
return <T> await response.data;
}
export class NekosAPIAxiosProxy extends NekosAPI {
constructor() {
super();
(this as any).checkResponseCode = checkResponseCode;
(this as any).fetchResponse = fetchResponse;
}
}
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.