mirror of
https://github.com/Radiquum/AniX.git
synced 2025-09-05 22:15:36 +05:00
chore/api-prox: add README
This commit is contained in:
parent
dd4772c5cf
commit
d71ae186a2
7 changed files with 241 additions and 23 deletions
111
api-prox/README.RU.md
Normal file
111
api-prox/README.RU.md
Normal file
|
@ -0,0 +1,111 @@
|
||||||
|
# AniX - Api Proxy
|
||||||
|
|
||||||
|
Данный под-проект позволяет проксировать запросы к API Anixart и изменять их ответы с помощью хуков
|
||||||
|
|
||||||
|
Он может использоваться как для основного проекта AniX, так и как отдельный сервис для андроид приложения с изменённой ссылкой на API.
|
||||||
|
|
||||||
|
Лицензия: [MIT](../LICENSE)
|
||||||
|
|
||||||
|
## Доступные хуки
|
||||||
|
|
||||||
|
- release.ts: добавляет рейтинг с shikimori в строку доп. информации
|
||||||
|
- profile.example.ts: меняет ник официального аккаунта anixart (пример работы с хуком)
|
||||||
|
- profile.sponsor.ts: включает спонсорку (отключает рекламу) после входа в аккаунт в android приложении
|
||||||
|
- toggles.ts: заменяет ответ конфигурации, если присутствует переменная окружения `HOST_URL` заменяет ссылку веб плеера, на встроенную, при совместном использовании с переменной окружения `PLAYER_PARSER_URL`, включает собственный веб-плеер, как в веб клиенте AniX
|
||||||
|
- episode.disabled.ts: позволяет изменять/добавлять озвучки, источники и эпизоды с помощью файла json, в папке `episode`.
|
||||||
|
|
||||||
|
## Использование
|
||||||
|
|
||||||
|
В строке веб-браузера необходимо ввести:
|
||||||
|
|
||||||
|
`<http|https>://<ip|domain><:port>/<ENDPOINT>[?<QUERY_PARAMS>]`
|
||||||
|
|
||||||
|
Ответ:
|
||||||
|
|
||||||
|
- 500: произошла ошибка, подробнее в строке `reason` в теле ответа
|
||||||
|
- 200: запрос прошёл успешно (если произошла ошибка на стороне API Anixart, смотри строку `code`)
|
||||||
|
|
||||||
|
## Развёртывание
|
||||||
|
|
||||||
|
### Docker
|
||||||
|
|
||||||
|
Требования:
|
||||||
|
|
||||||
|
- [docker](https://docs.docker.com/engine/install/)
|
||||||
|
|
||||||
|
### Пре-билд
|
||||||
|
|
||||||
|
1. выполните команду:
|
||||||
|
|
||||||
|
`docker run -d --name anix-api -p 7001:7001 radiquum/anix-api-prox:latest`
|
||||||
|
|
||||||
|
для использования хуков необходимо создать папку `hooks` и добавить флаг `-v ./hooks:/app/hooks` перед флагом `-p`.
|
||||||
|
(так-же и для папки `episode`, если требуется)
|
||||||
|
|
||||||
|
### Ручной билд
|
||||||
|
|
||||||
|
Доп. Требования:
|
||||||
|
|
||||||
|
- [git](https://git-scm.com/)
|
||||||
|
|
||||||
|
1. Клонируйте репозиторий `git clone https://github.com/Radiquum/AniX`
|
||||||
|
2. Переместитесь в директорию репозитория `cd AniX`
|
||||||
|
3. Переместитесь в директорию сервиса `cd api-prox`
|
||||||
|
4. Выполните команду `docker build -t anix-api-prox .`
|
||||||
|
5. После окончания, выполните команду: `docker run -d --restart always --name anix-player -p 7001:7001 anix-api-prox`
|
||||||
|
|
||||||
|
для использования хуков необходимо добавить флаг `-v ./hooks:/app/hooks` перед флагом `-p`.
|
||||||
|
(так-же и для папки `episode`, если требуется)
|
||||||
|
|
||||||
|
### docker/Обозначения
|
||||||
|
|
||||||
|
- -d - запустить контейнер в фоне
|
||||||
|
- --restart always - всегда запускать после перезагрузки сервера
|
||||||
|
- --name - название контейнера
|
||||||
|
- -p - порт контейнера который будет доступен извне. ПОРТ:7000
|
||||||
|
- -v - добавить папку с хоста в контейнер
|
||||||
|
|
||||||
|
### docker/После развёртывания
|
||||||
|
|
||||||
|
Сервис будет доступен по адресу: `http://<ВАШ IP><:ВАШ ПОРТ>/`
|
||||||
|
|
||||||
|
### docker/Примечание
|
||||||
|
|
||||||
|
Для использования своего домена и поддержки протокола HTTPS, вы можете использовать Traefik или другой reverse-proxy, с сертификатом SSL.
|
||||||
|
|
||||||
|
Полезные ссылки:
|
||||||
|
|
||||||
|
- [Конвертер из команды docker run в синтакс для docker compose](https://it-tools.tech/docker-run-to-docker-compose-converter)
|
||||||
|
- [Как настроить Traefik + свой домен + SSL](https://letmegooglethat.com/?q=how+to+setup+traefik+with+custom+domain+and+ssl+certificate+from+lets+encrypt%3F)
|
||||||
|
|
||||||
|
### pm2
|
||||||
|
|
||||||
|
Требования:
|
||||||
|
|
||||||
|
- [git](https://git-scm.com/)
|
||||||
|
- [nodejs 23+ с npm](http://nodejs.org/)
|
||||||
|
- [pm2](https://pm2.keymetrics.io/)
|
||||||
|
|
||||||
|
Инструкция:
|
||||||
|
|
||||||
|
1. Клонируйте репозиторий `git clone https://github.com/Radiquum/AniX`
|
||||||
|
2. Переместитесь в директорию репозитория `cd AniX`
|
||||||
|
3. Переместитесь в директорию сервиса `cd api-prox`
|
||||||
|
4. Выполните команду `npm install`
|
||||||
|
5. После окончания и выполните команду `pm2 start index.ts -n anix-api-prox`
|
||||||
|
|
||||||
|
### pm2/Обозначения
|
||||||
|
|
||||||
|
- -n - название сервиса в pm2
|
||||||
|
|
||||||
|
### pm2/После развёртывания
|
||||||
|
|
||||||
|
Сервис будет доступен по адресу: `http://<ВАШ IP>:7001/`
|
||||||
|
|
||||||
|
### pm2/Примечание
|
||||||
|
|
||||||
|
Для автоматического запуска приложения, рекомендуется настроить pm2 на автозапуск, с помощью команды: `pm2 startup`
|
||||||
|
|
||||||
|
Полезные ссылки:
|
||||||
|
|
||||||
|
- [PM2: подходим к вопросу процесс-менеджмента с умом @ Habr](https://habr.com/ru/articles/480670/)
|
112
api-prox/README.md
Normal file
112
api-prox/README.md
Normal file
|
@ -0,0 +1,112 @@
|
||||||
|
|
||||||
|
# AniX - Api Proxy
|
||||||
|
|
||||||
|
This sub-project allows proxying requests to the Anixart API and modifying their responses using hooks.
|
||||||
|
|
||||||
|
It can be used both for the main AniX project and as a standalone service for the Android app with a modified API link.
|
||||||
|
|
||||||
|
License: [MIT](../LICENSE)
|
||||||
|
|
||||||
|
## Available Hooks
|
||||||
|
|
||||||
|
- release.ts: adds a rating from Shikimori to the additional info line
|
||||||
|
- profile.example.ts: changes the nickname of the official Anixart account (an example of using a hook)
|
||||||
|
- profile.sponsor.ts: enables sponsorship (disables ads) after logging into the account in the Android app
|
||||||
|
- toggles.ts: replaces the configuration response; if the `HOST_URL` environment variable is present, it replaces the web player link with an embedded one; when used together with the `PLAYER_PARSER_URL` variable, enables the custom web player, as in the AniX web client
|
||||||
|
- episode.disabled.ts: allows modifying/adding voiceovers, sources, and episodes using a JSON file in the `episode` folder.
|
||||||
|
|
||||||
|
## Usage
|
||||||
|
|
||||||
|
In the web browser address bar, enter:
|
||||||
|
|
||||||
|
`<http|https>://<ip|domain><:port>/<ENDPOINT>[?<QUERY_PARAMS>]`
|
||||||
|
|
||||||
|
Response:
|
||||||
|
|
||||||
|
- 500: an error occurred, see the `reason` field in the response body for more details
|
||||||
|
- 200: request was successful (if there was an error on the Anixart API side, see the `code` field)
|
||||||
|
|
||||||
|
## Deployment
|
||||||
|
|
||||||
|
### Docker
|
||||||
|
|
||||||
|
Requirements:
|
||||||
|
|
||||||
|
- [docker](https://docs.docker.com/engine/install/)
|
||||||
|
|
||||||
|
### Pre-built
|
||||||
|
|
||||||
|
1. Run the command:
|
||||||
|
|
||||||
|
`docker run -d --name anix-api -p 7001:7001 radiquum/anix-api-prox:latest`
|
||||||
|
|
||||||
|
To use hooks, create a `hooks` folder and add the flag `-v ./hooks:/app/hooks` before the `-p` flag.
|
||||||
|
(The same applies to the `episode` folder if needed)
|
||||||
|
|
||||||
|
### Manual Build
|
||||||
|
|
||||||
|
Additional Requirements:
|
||||||
|
|
||||||
|
- [git](https://git-scm.com/)
|
||||||
|
|
||||||
|
1. Clone the repository: `git clone https://github.com/Radiquum/AniX`
|
||||||
|
2. Navigate to the repository directory: `cd AniX`
|
||||||
|
3. Navigate to the service directory: `cd api-prox`
|
||||||
|
4. Run the command: `docker build -t anix-api-prox .`
|
||||||
|
5. After completion, run: `docker run -d --restart always --name anix-player -p 7001:7001 anix-api-prox`
|
||||||
|
|
||||||
|
To use hooks, add the flag `-v ./hooks:/app/hooks` before the `-p` flag.
|
||||||
|
(The same applies to the `episode` folder if needed)
|
||||||
|
|
||||||
|
### docker/Flags
|
||||||
|
|
||||||
|
- -d - run the container in background
|
||||||
|
- --restart always - always start after server reboot
|
||||||
|
- --name - container name
|
||||||
|
- -p - container port that will be accessible from outside. PORT:7000
|
||||||
|
- -v - mount a folder from host into the container
|
||||||
|
|
||||||
|
### docker/After Deployment
|
||||||
|
|
||||||
|
The service will be available at: `http://<YOUR IP><:YOUR PORT>/`
|
||||||
|
|
||||||
|
### docker/Note
|
||||||
|
|
||||||
|
To use your own domain and support HTTPS, you can use Traefik or another reverse proxy with an SSL certificate.
|
||||||
|
|
||||||
|
Useful links:
|
||||||
|
|
||||||
|
- [Converter from docker run command to docker compose syntax](https://it-tools.tech/docker-run-to-docker-compose-converter)
|
||||||
|
- [How to setup Traefik + custom domain + SSL](https://letmegooglethat.com/?q=how+to+setup+traefik+with+custom+domain+and+ssl+certificate+from+lets+encrypt%3F)
|
||||||
|
|
||||||
|
### pm2
|
||||||
|
|
||||||
|
Requirements:
|
||||||
|
|
||||||
|
- [git](https://git-scm.com/)
|
||||||
|
- [nodejs 23+ with npm](http://nodejs.org/)
|
||||||
|
- [pm2](https://pm2.keymetrics.io/)
|
||||||
|
|
||||||
|
Instructions:
|
||||||
|
|
||||||
|
1. Clone the repository: `git clone https://github.com/Radiquum/AniX`
|
||||||
|
2. Navigate to the repository directory: `cd AniX`
|
||||||
|
3. Navigate to the service directory: `cd api-prox`
|
||||||
|
4. Run: `npm install`
|
||||||
|
5. After completion, run: `pm2 start index.ts -n anix-api-prox`
|
||||||
|
|
||||||
|
### pm2/Flags
|
||||||
|
|
||||||
|
- -n - service name in pm2
|
||||||
|
|
||||||
|
### pm2/After Deployment
|
||||||
|
|
||||||
|
The service will be available at: `http://<YOUR IP>:7001/`
|
||||||
|
|
||||||
|
### pm2/Note
|
||||||
|
|
||||||
|
For automatic app startup, it is recommended to set up pm2 autostart using the command: `pm2 startup`
|
||||||
|
|
||||||
|
Useful links:
|
||||||
|
|
||||||
|
- [PM2: a smart approach to process management @ Habr](https://habr.com/ru/articles/480670/)
|
|
@ -1,8 +1,10 @@
|
||||||
// хук добавляет ссылки на кастомные источники
|
// хук добавляет ссылки на кастомные источники
|
||||||
// а так-же позволяет добавлять собственные озвучки через json (./episode/<id релиза>.json)
|
// а так-же позволяет добавлять собственные озвучки
|
||||||
|
// с помощью json (<api-prox>/episode/<id релиза>.json)
|
||||||
|
// пример находится в файле 841.example.json в папке episode
|
||||||
//
|
//
|
||||||
// сами файлы эпизодов необходимо хостить отдельно (например с помощью nginx),
|
// сами видео файлы эпизодов необходимо хостить отдельно (например с помощью nginx),
|
||||||
// а так-же поменять iframe url в хуке toggles.ts на url сервиса
|
// хуку требуется переменная среды HOST_URL, которая ведёт на сервис api-prox
|
||||||
|
|
||||||
import { logger } from "../shared";
|
import { logger } from "../shared";
|
||||||
import fs from "fs/promises";
|
import fs from "fs/promises";
|
||||||
|
@ -58,7 +60,6 @@ export interface EpisodeInfo {
|
||||||
export async function get(data: any, url: URL) {
|
export async function get(data: any, url: URL) {
|
||||||
const base = "./episode";
|
const base = "./episode";
|
||||||
|
|
||||||
// let isExists = false;
|
|
||||||
let releaseId = null;
|
let releaseId = null;
|
||||||
let voiceOverId = null;
|
let voiceOverId = null;
|
||||||
let sourceId = null;
|
let sourceId = null;
|
||||||
|
|
12
api-prox/hooks/profile.sponsor.ts
Normal file
12
api-prox/hooks/profile.sponsor.ts
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
// хук включает "вечную" спонсорку, отключая рекламу после входа в профиль, в официальном приложении
|
||||||
|
|
||||||
|
export function match(path: string): boolean {
|
||||||
|
if (path == "/profile/info") return true;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function get(data: any, url: URL) {
|
||||||
|
data["is_sponsor"] = true;
|
||||||
|
data["sponsorship_expires"] = 2147483647;
|
||||||
|
return data;
|
||||||
|
}
|
|
@ -1,18 +0,0 @@
|
||||||
// хук включает "вечную" спонсорку, отключая рекламу после входа в профиль, в официальном приложении
|
|
||||||
|
|
||||||
export function match(path: string): boolean {
|
|
||||||
const pathRe = /^\/profile\/\d+/;
|
|
||||||
if (pathRe.test(path) || path == "/profile/info") return true;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function get(data: any, url: URL) {
|
|
||||||
if (data.hasOwnProperty("profile")) {
|
|
||||||
data["profile"]["is_sponsor"] = true;
|
|
||||||
data["profile"]["sponsorshipExpires"] = 2147483647;
|
|
||||||
} else {
|
|
||||||
data["is_sponsor"] = true;
|
|
||||||
data["sponsorship_expires"] = 2147483647;
|
|
||||||
}
|
|
||||||
return data;
|
|
||||||
}
|
|
|
@ -56,7 +56,7 @@ export async function get(data: Toggles, url: URL) {
|
||||||
|
|
||||||
data.impMessageEnabled = true;
|
data.impMessageEnabled = true;
|
||||||
data.impMessageText = "разработчик AniX / Api-Prox-Svc";
|
data.impMessageText = "разработчик AniX / Api-Prox-Svc";
|
||||||
data.impMessageLink = "https://bento.me/radiquum";
|
data.impMessageLink = "https://wah.su/radiquum";
|
||||||
data.impMessageBackgroundColor = "ffb3d0";
|
data.impMessageBackgroundColor = "ffb3d0";
|
||||||
data.impMessageTextColor = "ffffff";
|
data.impMessageTextColor = "ffffff";
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue