Skip to content

Commit b21c19d

Browse files
authored
Merge pull request #47 from shimizudev/v2
fix: add routes to index.ts
2 parents 7e71bff + 2f5cf86 commit b21c19d

File tree

6 files changed

+34
-26
lines changed

6 files changed

+34
-26
lines changed

anify-backend/src/app/impl/routes/index.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,22 @@ import stats from "./impl/stats";
22
import seasonal from "./impl/seasonal";
33
import metadata from "./impl/metadata";
44
import info from "./impl/info";
5+
import episodes from "./impl/episodes";
6+
import media from "./impl/media";
7+
import relations from "./impl/relations";
8+
import search from "./impl/search";
9+
import similar from "./impl/similar";
10+
import searchAdvanced from "./impl/searchAdvanced";
511

612
export default {
713
stats,
814
seasonal,
915
metadata,
1016
info,
17+
episodes,
18+
media,
19+
relations,
20+
search,
21+
similar,
22+
searchAdvanced,
1123
};

anify-backend/src/app/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ const start = async () => {
2929
}
3030
}
3131

32-
console.log(colors.gray(`Loaded ${colors.yellow(Object.keys(routes).length + "")} routes`));
32+
console.log(colors.gray(`Loaded ${colors.yellow(`${Object.keys(routes).length}`)} routes`));
3333

3434
Bun.serve({
3535
port: env.PORT,

anify-backend/src/lib/impl/content/impl/episodes.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@ const loadEpisodes = async (media: IAnime): Promise<IEpisodeData[]> => {
1010
const episodes: IEpisodeData[] = [];
1111
const mappings = media.mappings ?? [];
1212

13+
// If the anime is finished and we already have episode data, return it
14+
if (media.status === "FINISHED" && media.episodes?.data?.length > 0) {
15+
return media.episodes.data;
16+
}
17+
1318
// 1. Fetch episodes from providers in parallel.
1419
await Promise.all(
1520
mappings.map(async (mapping) => {
Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
11
export const averageMetric = (object: Record<string, unknown>) => {
2-
let average = 0;
3-
let validCount = 0;
42
if (!object) return 0;
53

6-
for (const [, v] of Object.entries(object)) {
7-
if (v && typeof v === "number") {
8-
average += v;
9-
validCount++;
10-
}
11-
}
4+
// Filter valid numeric values and convert to array
5+
const validValues = Object.values(object).filter((v): v is number =>
6+
v !== null && typeof v === "number" && !Number.isNaN(v)
7+
);
128

13-
return validCount === 0 ? 0 : Number.parseFloat((average / validCount).toFixed(2));
9+
if (validValues.length === 0) return 0;
10+
11+
// Calculate sum using reduce for better performance
12+
const sum = validValues.reduce((acc, val) => acc + val, 0);
13+
14+
// Calculate average and round to 2 decimal places using math operations
15+
// This is more precise than string operations with toFixed()
16+
return Math.round((sum / validValues.length) * 100) / 100;
1417
};

anify-backend/src/lib/impl/mappings/impl/map.ts

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -56,20 +56,7 @@ export const map = async (type: MediaType, formats: MediaFormat[], baseData: Ani
5656
const match = findBestMatch(baseData, providerData);
5757
if (match) {
5858
if (match.similarity < 0.7) {
59-
console.log(
60-
colors.gray("Unable to match ") +
61-
colors.blue(title) +
62-
colors.gray(" for ") +
63-
colors.blue(suitableProviders[i].id) +
64-
colors.gray(".") +
65-
colors.gray(" Best match rating: ") +
66-
colors.blue(`${match.similarity}`) +
67-
colors.gray(". ID: ") +
68-
colors.blue(match.match.id) +
69-
colors.gray(". Title: ") +
70-
colors.blue(match.match.title) +
71-
colors.gray("."),
72-
);
59+
console.log(colors.gray(`Unable to match ${colors.blue(title)} for ${colors.blue(suitableProviders[i].id)}. Best match rating: ${colors.blue(match.similarity.toFixed(2))}. ID: ${colors.blue(match.match.id)}. Title: ${colors.blue(match.match.title)}.`));
7360
continue;
7461
}
7562

anify-backend/src/proxies/impl/request/customRequest.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,15 @@ export async function customRequest(url: string, options: IRequestConfig = {}):
1010
while (attempts < (isChecking ? 1 : maxRetries || 3)) {
1111
attempts++;
1212

13-
const proxyURL = isChecking ? proxy : useGoogleTranslate ? "http://translate.google.com/translate?sl=ja&tl=en&u=" + encodeURIComponent(url) : proxy && attempts === 1 ? proxy : providerType && providerId ? await getRandomProxy(providerType, providerId) : null;
13+
const proxyURL = isChecking ? proxy : useGoogleTranslate ? `http://translate.google.com/translate?sl=ja&tl=en&u=${encodeURIComponent(url)}` : proxy && attempts === 1 ? proxy : providerType && providerId ? await getRandomProxy(providerType, providerId) : null;
1414

1515
try {
1616
const dispatcher = new ProxyAgent(proxyURL || "");
1717

1818
const fetchOptions: RequestInit = {
1919
...options,
20-
dispatcher: dispatcher as any, // TODO: Fix this
20+
// @ts-expect-error: dispatcher is not a valid type for RequestInit
21+
dispatcher: dispatcher as RequestInit["dispatcher"],
2122
};
2223

2324
const timeoutPromise = new Promise<Response>((_, reject) => {

0 commit comments

Comments
 (0)