Skip to content

Commit

Permalink
Bug fixes and optimizations
Browse files Browse the repository at this point in the history
  • Loading branch information
Eltik committed Aug 29, 2023
1 parent 0a4f3c5 commit 54e36a8
Show file tree
Hide file tree
Showing 18 changed files with 99 additions and 398 deletions.
25 changes: 25 additions & 0 deletions anify-auth/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# What port to listen to
PORT="3606"
# Public URL
PUBLIC_URL="http://localhost:3606"
FRONTEND_URL="http://localhost:3000"
# Backend URL
BACKEND_URL="http://localhost:3060"
# API Key
BACKEND_KEY=""
# SQLite database URL
DATABASE_URL="file:./db.sqlite"
# Redis URL
REDIS_URL="redis://localhost:6379"
# How long to cache redis data
REDIS_CACHE_TIME="18000"

# Provider API information
ANILIST_CLIENT_ID=""
ANILIST_CLIENT_SECRET=""

MAL_CLIENT_ID=""
MAL_CLIENT_SECRET=""

SIMKL_CLIENT_ID=""
SIMKL_CLIENT_SECRET=""
5 changes: 1 addition & 4 deletions anify-auth/src/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,7 @@ export const env = {
BACKEND_KEY: process.env.BACKEND_KEY ?? "",
DATABASE_URL: process.env.DATABASE_URL,
REDIS_URL: process.env.REDIS_URL,
REDIS_CACHE_TIME: Number(process.env.REDIS_CACHE_TIME) || 60 * 60 * 24 * 7,
USE_API_KEYS: process.env.USE_API_KEYS || "false",
MASTER_KEY: process.env.MASTER_KEY,
API_KEY_WHITELIST: process.env.API_KEY_WHITELIST?.split(",") || [],
REDIS_CACHE_TIME: Number(process.env.REDIS_CACHE_TIME) || 60 * 60 * 24 * 7
};

export const providerEnv = {
Expand Down
5 changes: 0 additions & 5 deletions anify-backend/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,6 @@ PORT="3060"
DATABASE_TYPE="postgres"
# PostgreSQL database URL
DATABASE_URL="postgresql://postgres:password@localhost:5432/?connection_limit=100"
# Whether to use Meilisearch
USE_MEILISEARCH="true"
# Meilisearch URL + Keys
MEILISEARCH_URL="http://localhost:7700"
MEILISEARCH_KEY="keylol"
# 9anime resolver URL
NINEANIME_RESOLVER="https://9anime.resolver.com"
# 9anime resolver API key
Expand Down
8 changes: 1 addition & 7 deletions anify-backend/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,13 @@ Robust JavaScript API server for scraping anime, manga, and light novel sites.
# Information

## Scraping
Anify scrapes numerous Japanese media sites from Zoro, to GogoAnime, to AnimePahe, and more. The API is built on top of [AniSync](https://github.com/Eltik/AniSync) to map AniList information accurately, allowing for multiple providers in case one ever goes down. To avoid rate limits, the API stores information in a database to ensure fast and accurate results. This is meant to be a robust web server, so there are a ton of features from Redis caching, PostgreSQL support, configurable `.env` options, etc.
Anify scrapes numerous Japanese media sites from Zoro, to MangaSee, to NovelUpdates, and more. The API is built on top of [AniSync](https://github.com/Eltik/AniSync) to map AniList information accurately, allowing for multiple providers in case one ever goes down. To avoid rate limits, the API stores information in a database to ensure fast and accurate results. This is meant to be a robust web server, so there are a ton of features from Redis caching, PostgreSQL support, configurable `.env` options, etc.
## Anime
The API supports the following anime sites:
- [x] [Zoro](https://aniwatch.to)
- [x] [GogoAnime](https://www1.gogoanime.bid/)
- [x] [AnimePahe](https://animepahe.com)
- [x] [9anime](https://9anime.pl)
- [x] [AnimeFlix](https://animeflix.live)

## Manga
The API supports the following manga sites:
Expand Down Expand Up @@ -54,11 +53,6 @@ You can configure the web server via a `.env` file (not included). Default value
PORT="3060"
# PostgreSQL database URL
DATABASE_URL="postgresql://postgres:password@localhost:5432/?connection_limit=100"
# Whether to use Meilisearch
USE_MEILISEARCH="true"
# Meilisearch URL + Keys
MEILISEARCH_URL="http://localhost:7700"
MEILISEARCH_KEY="keylol"
# 9anime resolver URL
NINEANIME_RESOLVER="https://9anime.resolver.com"
# 9anime resolver API key
Expand Down
9 changes: 0 additions & 9 deletions anify-backend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion anify-backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@
"express-rate-limit": "^6.7.0",
"form-data": "^4.0.0",
"ioredis": "^5.3.2",
"meilisearch": "^0.33.0",
"pdfkit": "^0.13.0",
"probe-image-size": "^7.2.3",
"rate-limit-redis": "^3.0.2"
Expand Down
35 changes: 9 additions & 26 deletions anify-backend/src/database/index.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
import { randomUUID } from "crypto";
import { Anime, Format, Genres, Manga, Type } from "../mapping";
import { prisma, search as searchPostgres, searchAdvanced as searchAdvancedPostgres, seasonal as seasonalPostgres, info as infoPostgres, media as mediaPostgres, recent } from "./postgresql";
import { createMeiliEntry, initializeMeilisearch } from "./meilisearch";
import { env } from "../env";
import cluster from "cluster";
import { info, media, prisma, recent, search, searchAdvanced, seasonal as seasonalPostgres, } from "./postgresql";

export default class Database {
private static type = "postgresql";
private static useMeilisearch = env.USE_MEILISEARCH;

static async initializeDatabase() {
if (this.type === "postgresql") {
Expand All @@ -20,23 +17,19 @@ export default class Database {
$$;`;
}
}

if (this.useMeilisearch && cluster.isPrimary) {
await initializeMeilisearch();
}
}

static async search(query: string, type: Type, formats: Format[], page: number, perPage: number): Promise<Anime[] | Manga[]> {
if (this.type === "postgresql") {
return await searchPostgres(query, type, formats, page, perPage);
return await search(query, type, formats, page, perPage);
} else {
return [];
}
}

static async searchAdvanced(query: string, type: Type, formats: Format[], page: number, perPage: number, genres: Genres[] = [], genresExcluded: Genres[] = [], year = 0, tags: string[] = [], tagsExcluded: string[] = []): Promise<Anime[] | Manga[]> {
if (this.type === "postgresql") {
return await searchAdvancedPostgres(query, type.toUpperCase() as Type, formats, page, 40, genres as Genres[], genresExcluded as Genres[], year, tags, tagsExcluded);
return await searchAdvanced(query, type.toUpperCase() as Type, formats, page, 40, genres as Genres[], genresExcluded as Genres[], year, tags, tagsExcluded);
} else {
return [];
}
Expand All @@ -57,15 +50,15 @@ export default class Database {

static async info(id: string): Promise<Anime | Manga | null> {
if (this.type === "postgresql") {
return (await infoPostgres(id)) as Anime | Manga;
return (await info(id)) as Anime | Manga;
} else {
return null;
}
}

static async media(providerId: string, id: string): Promise<Anime | Manga | null> {
if (this.type === "postgresql") {
return (await mediaPostgres(providerId, id)) as Anime | Manga;
return (await media(providerId, id)) as Anime | Manga;
} else {
return null;
}
Expand Down Expand Up @@ -125,17 +118,17 @@ export default class Database {

static async delete(id: string): Promise<void> {
if (this.type === "postgresql") {
const info = await infoPostgres(id);
if (info?.type === Type.ANIME) {
const data = await info(id);
if (data?.type === Type.ANIME) {
await prisma.anime.delete({
where: {
id: info?.id,
id: data?.id,
},
});
} else {
await prisma.manga.delete({
where: {
id: info?.id,
id: data?.id,
},
});
}
Expand All @@ -156,10 +149,6 @@ export default class Database {
});
}
}

if (this.useMeilisearch) {
await createMeiliEntry(media);
}
}

static async createEntrys(media: Anime[] | Manga[]): Promise<void> {
Expand All @@ -176,12 +165,6 @@ export default class Database {
});
}
}

if (this.useMeilisearch) {
for (const m of media) {
await createMeiliEntry(m);
}
}
}

static async findSkipTimes(id: string) {
Expand Down
64 changes: 0 additions & 64 deletions anify-backend/src/database/meilisearch.ts

This file was deleted.

3 changes: 0 additions & 3 deletions anify-backend/src/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@ export const env = {
PORT: Number(process.env.PORT) || 3000,
DATABASE_TYPE: process.env.DATABASE_TYPE || "postgres",
DATABASE_URL: process.env.DATABASE_URL,
USE_MEILISEARCH: process.env.USE_MEILISEARCH === "true" || false,
MEILISEARCH_URL: process.env.MEILISEARCH_URL,
MEILISEARCH_KEY: process.env.MEILISEARCH_KEY,
NINEANIME_RESOLVER: process.env.NINEANIME_RESOLVER,
NINEANIME_KEY: process.env.NINEANIME_KEY,
REDIS_URL: process.env.REDIS_URL,
Expand Down
55 changes: 0 additions & 55 deletions anify-backend/src/mapping/impl/anime/bilibili.ts

This file was deleted.

24 changes: 22 additions & 2 deletions anify-backend/src/mapping/impl/anime/nineanime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ export default class NineAnime extends AnimeProvider {
override formats: Format[] = [Format.MOVIE, Format.ONA, Format.OVA, Format.SPECIAL, Format.TV, Format.TV_SHORT];

private userAgent = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/113.0.0.0 Safari/537.36 Edg/113.0.1774.42";
private resolver: string = env.NINEANIME_RESOLVER || `https://9anime.resolver.com`;
private resolverKey: string = env.NINEANIME_KEY || `9anime`;
private resolver: string | undefined = env.NINEANIME_RESOLVER;
private resolverKey: string | undefined = env.NINEANIME_KEY || `9anime`;

override get subTypes(): SubType[] {
return [SubType.SUB, SubType.DUB];
Expand Down Expand Up @@ -207,18 +207,38 @@ export default class NineAnime extends AnimeProvider {
}

private async getVRF(query: string): Promise<VRF> {
if (!this.resolver) return {
url: query,
vrfQuery: "vrf",
}

return await (await this.request(`${this.resolver}/vrf?query=${encodeURIComponent(query)}&apikey=${this.resolverKey}`, {})).json();
}

public async getSearchVRF(query: string): Promise<VRF> {
if (!this.resolver) return {
url: query,
vrfQuery: "vrf",
}

return await (await this.request(`${this.resolver}/9anime-search?query=${encodeURIComponent(query)}&apikey=${this.resolverKey}`, {})).json();
}

private async getRawVRF(query: string): Promise<VRF> {
if (!this.resolver) return {
url: query,
vrfQuery: "vrf",
}

return await (await this.request(`${this.resolver}/rawVrf?query=${encodeURIComponent(query)}&apikey=${this.resolverKey}`, {})).json();
}

private async decodeURL(query: string): Promise<VRF> {
if (!this.resolver) return {
url: query,
vrfQuery: "vrf",
}

return await (await this.request(`${this.resolver}/decrypt?query=${encodeURIComponent(query)}&apikey=${this.resolverKey}`, {})).json();
}

Expand Down
Loading

0 comments on commit 54e36a8

Please sign in to comment.