aboutsummaryrefslogtreecommitdiff
path: root/lib/anify
diff options
context:
space:
mode:
authorFactiven <[email protected]>2023-12-24 13:03:54 +0700
committerFactiven <[email protected]>2023-12-24 13:03:54 +0700
commit50a0f0240d7fef133eb5acc1bea2b1168b08e9db (patch)
tree307e09e505580415a58d64b5fc3580e9235869f1 /lib/anify
parentUpdate README.md (#104) (diff)
downloadmoopa-50a0f0240d7fef133eb5acc1bea2b1168b08e9db.tar.xz
moopa-50a0f0240d7fef133eb5acc1bea2b1168b08e9db.zip
migrate to typescript
Diffstat (limited to 'lib/anify')
-rw-r--r--lib/anify/getMangaId.ts (renamed from lib/anify/getMangaId.js)31
-rw-r--r--lib/anify/info.js24
2 files changed, 32 insertions, 23 deletions
diff --git a/lib/anify/getMangaId.js b/lib/anify/getMangaId.ts
index 6b1445f..bf7bb71 100644
--- a/lib/anify/getMangaId.js
+++ b/lib/anify/getMangaId.ts
@@ -1,8 +1,25 @@
-import axios from "axios";
+import axios, { AxiosResponse } from "axios";
-export async function fetchInfo(romaji, english, native) {
+interface Manga {
+ id: string;
+ title: {
+ romaji: string;
+ english: string;
+ native: string;
+ };
+}
+
+interface SearchResult {
+ results: Manga[];
+}
+
+export async function fetchInfo(
+ romaji: string,
+ english: string,
+ native: string
+): Promise<{ id: string } | null> {
try {
- const { data: getManga } = await axios.get(
+ const { data: getManga }: AxiosResponse<SearchResult> = await axios.get(
`https://api.anify.tv/search-advanced?query=${
english || romaji
}&type=manga`
@@ -26,10 +43,14 @@ export async function fetchInfo(romaji, english, native) {
}
}
-export default async function getMangaId(romaji, english, native) {
+export default async function getMangaId(
+ romaji: string,
+ english: string,
+ native: string
+): Promise<{ id: string } | { message: string } | { error: any }> {
try {
const data = await fetchInfo(romaji, english, native);
- if (data) {
+ if (data && "id" in data) {
return data;
} else {
return { message: "Schedule not found" };
diff --git a/lib/anify/info.js b/lib/anify/info.js
index 05159ce..8284e94 100644
--- a/lib/anify/info.js
+++ b/lib/anify/info.js
@@ -1,7 +1,6 @@
import axios from "axios";
-import { redis } from "../redis";
-export async function fetchInfo(id, key) {
+export async function fetchInfo(id) {
try {
const { data } = await axios.get(`https://api.anify.tv/info/${id}`);
return data;
@@ -11,24 +10,13 @@ export async function fetchInfo(id, key) {
}
}
-export default async function getAnifyInfo(id, key) {
+export default async function getAnifyInfo(id) {
try {
- let cached;
- if (redis) {
- cached = await redis.get(id);
- }
- if (cached) {
- return JSON.parse(cached);
+ const data = await fetchInfo(id);
+ if (data) {
+ return data;
} else {
- const data = await fetchInfo(id, key);
- if (data) {
- if (redis) {
- await redis.set(id, JSON.stringify(data), "EX", 60 * 10);
- }
- return data;
- } else {
- return { message: "Schedule not found" };
- }
+ return { message: "Anify Info Not Found!" };
}
} catch (error) {
return { error };