feat/api-prox: finding of working api base
Some checks are pending
Build and Publish 'anix-api-prox' to Docker Hub / publish (push) Waiting to run
Build and Publish 'anix' to Docker Hub / publish (push) Waiting to run

fix/anix: broken api url
This commit is contained in:
Kentai Radiquum 2025-08-16 03:03:22 +05:00
parent 30285e84c6
commit aaca8c7f3c
Signed by: Radiquum
GPG key ID: 858E8EE696525EED
3 changed files with 55 additions and 18 deletions

View file

@ -3,6 +3,7 @@ import {
ANIXART_HEADERS,
ANIXART_HEADERST,
asJSON,
getAnixartApiBaseUrl,
GetHook,
logger,
PostHook,
@ -360,7 +361,8 @@ app.post("/*path", async (req, res) => {
return;
});
app.listen(PORT, HOST, function () {
app.listen(PORT, HOST, async function () {
loadHooks();
await getAnixartApiBaseUrl();
logger.info(`Server listen: http://${HOST}:${PORT}`);
});

View file

@ -1,12 +1,18 @@
export const corsHeaders = {
"Access-Control-Allow-Origin": "*",
"Access-Control-Allow-Headers": "Origin, X-Requested-With, Content-Type, Accept, Sign",
"Access-Control-Allow-Headers":
"Origin, X-Requested-With, Content-Type, Accept, Sign",
"Access-Control-Allow-Methods": "GET,HEAD,POST,OPTIONS",
"Cache-Control": "no-cache",
};
import { Request, Response } from "express";
export function asJSON(req: Request,res: Response, object: any, status: number) {
export function asJSON(
req: Request,
res: Response,
object: any,
status: number
) {
corsHeaders["Access-Control-Allow-Origin"] = req.headers.origin || "*";
res.status(status).type("application/json");
@ -14,20 +20,6 @@ export function asJSON(req: Request,res: Response, object: any, status: number)
res.send(JSON.stringify(object));
}
export const ANIXART_UA =
"AnixartApp/9.0 BETA 5-25062213 (Android 9; SDK 28; arm64-v8a; samsung SM-G975N; en)";
export const ANIXART_API = "https://api.anixart.app";
export type ANIXART_HEADERST = {
"User-Agent": string;
"Content-Type": string;
"Api-Version"?: string;
};
export const ANIXART_HEADERS: ANIXART_HEADERST = {
"User-Agent": ANIXART_UA,
"Content-Type": "application/json; charset=UTF-8",
};
type LogLevel = "debug" | "info" | "warn" | "error" | "disable";
export class Log {
level: LogLevel;
@ -108,6 +100,49 @@ export class Log {
export const logger = new Log((process.env.LOG_LEVEL as LogLevel) || "info");
export const ANIXART_UA =
"AnixartApp/9.0 BETA 5-25062213 (Android 9; SDK 28; arm64-v8a; samsung SM-G975N; en)";
export let ANIXART_API: string | null = null; // "https://api.anixart-app.com";
const _anixart_baseUrlList = [
"https://api.anixart-app.com",
"https://api-s.anixsekai.com",
"https://api.anixart.tv",
"https://api-s2.anixart.tv",
];
export async function getAnixartApiBaseUrl() {
if (process.env.ANIXART_BASE_URL) return process.env.ANIXART_BASE_URL;
logger.info("FINDING WORKING ANIXART API BASE URL...");
for (const url of _anixart_baseUrlList) {
try {
const res = await fetch(`${url}/config/toggles?version_code=25062213&is_beta=true&is_api_alt=false&token=`, { method: "GET" });
await res.json();
ANIXART_API = url;
logger.info(`FOUND WORKING ANIXART API BASE URL: ${url}`);
break;
} catch {
continue;
}
}
if (!ANIXART_API) {
logger.error("FAILED TO FIND WORKING ANIXART API BASE URL!");
process.exit(1);
}
}
export type ANIXART_HEADERST = {
"User-Agent": string;
"Content-Type": string;
"Api-Version"?: string;
};
export const ANIXART_HEADERS: ANIXART_HEADERST = {
"User-Agent": ANIXART_UA,
"Content-Type": "application/json; charset=UTF-8",
};
export interface GetHook {
match: (path: string) => boolean;
get: (data: any, url: URL) => any;

View file

@ -2,7 +2,7 @@ export const CURRENT_APP_VERSION = "3.7.0";
import { env } from "next-runtime-env";
const NEXT_PUBLIC_API_URL = env("NEXT_PUBLIC_API_URL") || null;
export const API_URL = NEXT_PUBLIC_API_URL ||"https://api.anixart.app";
export const API_URL = NEXT_PUBLIC_API_URL ||"https://api-s.anixsekai.com";
export const API_PREFIX = NEXT_PUBLIC_API_URL || "/api/proxy";
export const USER_AGENT =
"AnixartApp/9.0 BETA 5-25062213 (Android 9; SDK 28; arm64-v8a; samsung SM-G975N; en)";