feat/api-prox: add GET proxy

This commit is contained in:
Kentai Radiquum 2025-09-06 14:40:22 +05:00
parent 1a439f0a77
commit 32e830cae1
Signed by: Radiquum
GPG key ID: 858E8EE696525EED
3 changed files with 49 additions and 8 deletions

View file

@ -2,7 +2,18 @@
// {EPOCH * 1000 + MAJOR}.MINOR.PATCH
export const appVersion = "0000.0.0";
export const baseUrls = [
export const BASE_URLS = [
"https://api-s.anixsekai.com/",
"https://api.anixsekai.com/",
];
export type ANIXART_HEADERST = {
"User-Agent": string;
"Content-Type": string;
"Api-Version"?: string;
};
export const ANIXART_UA = "AnixartApp/9.0 BETA 5-25062213 (Android 9; SDK 28; arm64-v8a; samsung SM-G975N; en)";
export const ANIXART_HEADERS: ANIXART_HEADERST = {
"User-Agent": ANIXART_UA,
"Content-Type": "application/json; charset=UTF-8",
};

View file

@ -1,12 +1,11 @@
import { Hono } from "hono";
import { logger } from "hono/logger";
import { RouteLogger } from "./utils/logger.js";
import { trimTrailingSlash } from "hono/trailing-slash";
import { asciiHTML, separatorHTML } from "./utils/info.js";
import { appVersion } from "./config.js";
import { ANIXART_HEADERS, appVersion, BASE_URLS } from "./config.js";
import { tryCatchAPI } from "./utils/tryCatch.js";
const app = new Hono({ strict: true });
app.use(trimTrailingSlash());
const app = new Hono({ strict: false });
app.use(logger(RouteLogger));
app.get("/", (c) => {
@ -62,4 +61,35 @@ app.get("/health/json", (c) => {
return c.json({ status: "OK", version: appVersion });
});
app.get("/favicon.ico", (c) => {
return c.text("", 404);
})
app.get("/*", async (c) => {
console.log("--- Trying to proxy `GET` request")
const url = new URL(c.req.url);
const currentBaseURL = new URL(BASE_URLS[Math.floor(Math.random() * BASE_URLS.length)]);
url.protocol = currentBaseURL.protocol;
url.host = currentBaseURL.host;
url.port = currentBaseURL.port;
if (url.searchParams.get("API-Version") == "v2" || c.req.header("API-Version") == "v2") {
ANIXART_HEADERS["Api-Version"] = "v2";
url.searchParams.delete("API-Version");
}
console.log("--- URL:", `${url.protocol}//${url.host}${url.pathname}`);
const { data, error } = await tryCatchAPI(fetch(url.toString(), {
method: "GET",
headers: ANIXART_HEADERS
}));
if (error) {
return c.json(error);
}
//@ts-ignore
return c.json(data);
})
export default app;

View file

@ -4,16 +4,16 @@ export const RouteLogger = (message: string) => {
const method = args[1];
const url = new URL("http://example.com" + args[2]);
if (url.searchParams.get("token")) {
url.searchParams.set("token", "*********");
url.searchParams.set("token", "***");
}
if (direction == "<--") {
console.log(`REQ | ${method} ${url.pathname}${url.search}`);
console.log(`--> REQ | ${method} ${url.pathname}${url.search}`);
} else {
const status = args[3];
const time = args[4];
console.log(
`RES | ${method} ${url.pathname}${url.search} ${status} ${time}`
`<-- RES | ${method} ${url.pathname}${url.search} ${status} ${time}`
);
}
};