From 7b8dca11fcf11c5ecb521819e5359496ad358237 Mon Sep 17 00:00:00 2001 From: capitanwesler Date: Mon, 15 Mar 2021 14:12:13 +0000 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=A8=20Fixing=20some=20of=20the=20respo?= =?UTF-8?q?nses=20with=20bad=20names?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/controllers/AnimeController.ts | 12 +-- src/controllers/DirectoryController.ts | 16 +-- src/controllers/UtilsController.ts | 135 +++++++++++++++---------- src/routes.ts | 2 +- src/utils/util.ts | 14 +-- 5 files changed, 107 insertions(+), 72 deletions(-) diff --git a/src/controllers/AnimeController.ts b/src/controllers/AnimeController.ts index 1faa6b1..0336648 100644 --- a/src/controllers/AnimeController.ts +++ b/src/controllers/AnimeController.ts @@ -87,7 +87,7 @@ export default class AnimeController { if (animeList.length > 0) { res.status(200).json({ - animeList, + day, }); } else { res.status(500).json({ message: 'Aruppi lost in the shell' }); @@ -120,9 +120,9 @@ export default class AnimeController { title: item.title, url: item.url, image_url: item.image_url, - type: item.type, - subtype: item.subtype, - page: item.page, + type: type, + subtype: subtype, + page: page, score: item.score, })); @@ -198,7 +198,7 @@ export default class AnimeController { const { type, page, url } = req.params; let data: any; - if (['movie', 'ova', 'tv', 'special'].indexOf(type) !== -1) { + if (['movie', 'ova', 'tv', 'special'].indexOf(url) > -1) { try { data = await requestGot( `${urls.BASE_ANIMEFLV_JELU}${ @@ -321,7 +321,7 @@ export default class AnimeController { if (animeResult) { res.set('Cache-Control', 'no-store'); - res.status(200).json({ animeResult }); + res.status(200).json(animeResult); } else { res.status(500).json({ message: 'Aruppi lost in the shell' }); } diff --git a/src/controllers/DirectoryController.ts b/src/controllers/DirectoryController.ts index 4c311a7..1409888 100644 --- a/src/controllers/DirectoryController.ts +++ b/src/controllers/DirectoryController.ts @@ -45,10 +45,10 @@ export default class DirectoryController { genres: { $nin: ['ecchi', 'Ecchi'] }, }, (err: any, docs: Anime[]) => { - let results: any[] = []; + let directory: any[] = []; for (const item of docs) { - results.push({ + directory.push({ id: item.id, title: item.title, mal_id: item.mal_id, @@ -62,8 +62,8 @@ export default class DirectoryController { }); } - if (results.length > 0) { - res.status(200).json({ results }); + if (directory.length > 0) { + res.status(200).json({ directory }); } else { res.status(500).json({ message: 'Aruppi lost in the shell' }); } @@ -71,10 +71,10 @@ export default class DirectoryController { ); } else { await AnimeModel.find((err: any, docs: Anime[]) => { - let results: any[] = []; + let directory: any[] = []; for (const item of docs) { - results.push({ + directory.push({ id: item.id, title: item.title, mal_id: item.mal_id, @@ -88,8 +88,8 @@ export default class DirectoryController { }); } - if (results.length > 0) { - res.status(200).json({ results }); + if (directory.length > 0) { + res.status(200).json({ directory }); } else { res.status(500).json({ message: 'Aruppi lost in the shell' }); } diff --git a/src/controllers/UtilsController.ts b/src/controllers/UtilsController.ts index d2ea2ab..d801be9 100644 --- a/src/controllers/UtilsController.ts +++ b/src/controllers/UtilsController.ts @@ -337,16 +337,16 @@ export default class UtilsController { async getOpAndEd(req: Request, res: Response, next: NextFunction) { const { title } = req.params; - let result: any; + let themes: any; try { - result = await structureThemes(await themeParser.serie(title), true); + themes = await structureThemes(await themeParser.serie(title), true); } catch (err) { return next(err); } - if (result) { - res.status(200).json({ result }); + if (themes) { + res.status(200).json({ themes }); } else { res.status(500).json({ message: 'Aruppi lost in the shell' }); } @@ -354,20 +354,20 @@ export default class UtilsController { async getThemesYear(req: Request, res: Response, next: NextFunction) { const { year } = req.params; - let data: any; + let themes: any; try { if (year === undefined) { - data = await themeParser.allYears(); + themes = await themeParser.allYears(); } else { - data = await structureThemes(await themeParser.year(year), false); + themes = await structureThemes(await themeParser.year(year), false); } } catch (err) { return next(err); } - if (data.length > 0) { - res.status(200).json({ data }); + if (themes.length > 0) { + res.status(200).json({ themes }); } else { res.status(500).json({ message: 'Aruppi lost in the shell' }); } @@ -385,11 +385,11 @@ export default class UtilsController { return next(err); } - const result: any[] = getThemes(data.themes); + const random: any[] = getThemes(data.themes); - if (result.length > 0) { + if (random.length > 0) { res.set('Cache-Control', 'no-store'); - res.status(200).json({ result }); + res.status(200).json({ random }); } else { res.status(500).json({ message: 'Aruppi lost in the shell' }); } @@ -397,20 +397,20 @@ export default class UtilsController { async getArtist(req: Request, res: Response, next: NextFunction) { const { id } = req.params; - let data: any; + let artists: any; try { if (id === undefined) { - data = await themeParser.artists(); + artists = await themeParser.artists(); } else { - data = await structureThemes(await themeParser.artist(id), false); + artists = await structureThemes(await themeParser.artist(id), false); } } catch (err) { return next(err); } - if (data.length > 0) { - res.status(200).json({ data }); + if (artists.length > 0) { + res.status(200).json({ artists }); } else { res.status(500).json({ message: 'Aruppi lost in the shell' }); } @@ -428,7 +428,7 @@ export default class UtilsController { return next(err); } - const result: any[] = data.map((item: any) => { + const destPlatforms: any[] = data.map((item: any) => { return { id: item.id, name: item.name, @@ -437,8 +437,8 @@ export default class UtilsController { }; }); - if (result.length > 0) { - res.status(200).json({ result }); + if (destPlatforms.length > 0) { + res.status(200).json({ destPlatforms }); } else { res.status(500).json({ message: 'Aruppi lost in the shell' }); } @@ -448,41 +448,74 @@ export default class UtilsController { const { id } = req.params; let data: any; - if (id === undefined) { - data = await requestGot( - `${urls.BASE_ARUPPI}res/documents/animelegal/type/platforms.json`, - { parse: true, scrapy: false }, - ); - } else if ( - id === 'producers' || - id === 'apps' || - id === 'publishers' || - 'events' - ) { - data = await requestGot( - `${urls.BASE_ARUPPI}res/documents/animelegal/type/${id}.json`, - { parse: true, scrapy: false }, - ); - } else { - data = await requestGot( - `${urls.BASE_ARUPPI}res/documents/animelegal/type/${id}.json`, - { parse: true, scrapy: false }, - ); + try { + if (id === undefined) { + data = await requestGot( + `${urls.BASE_ARUPPI}res/documents/animelegal/typeplatforms.json`, + { parse: true, scrapy: false }, + ); + } else if ( + id === 'producers' || + id === 'apps' || + id === 'publishers' || + 'events' + ) { + data = await requestGot( + `${urls.BASE_ARUPPI}res/documents/animelegal/type/${id}.json`, + { parse: true, scrapy: false }, + ); + } else { + data = await requestGot( + `${urls.BASE_ARUPPI}res/documents/animelegal/type/${id}.json`, + { parse: true, scrapy: false }, + ); + } + } catch (err) { + return next(err); } - const result: any[] = data.map((item: any) => { - return { - id: item.id, - name: item.name, - type: item.type, - logo: item.logo, - cover: item.cover, - webpage: item.webpage, - }; + const platforms: any[] = data.map((item: any) => { + if (id === undefined) { + return { + id: item.id, + name: item.name, + comming: item.comming || false, + cover: item.cover, + }; + } else if ( + id === 'producers' || + id === 'apps' || + id === 'publishers' || + 'events' + ) { + return { + id: item.id, + name: item.name, + logo: item.logo, + cover: item.cover, + description: item.description, + type: item.type, + moreInfo: item.moreInfo, + facebook: item.facebook, + twitter: item.twitter, + instagram: item.instagram, + webInfo: item.webInfo, + webpage: item.webpage, + }; + } else { + return { + id: item.id, + name: item.name, + type: item.type, + logo: item.logo, + cover: item.cover, + webpage: item.webpage, + }; + } }); - if (result.length > 0) { - res.status(200).json({ result }); + if (platforms.length > 0) { + res.status(200).json({ platforms }); } else { res.status(500).json({ message: 'Aruppi lost in the shell' }); } diff --git a/src/routes.ts b/src/routes.ts index 5ec3274..6f9bfd4 100644 --- a/src/routes.ts +++ b/src/routes.ts @@ -70,7 +70,7 @@ routes.get('/api/v4/', (req: Request, res: Response) => { /* Anime Controller */ routes.get('/api/v4/schedule/:day', animeController.schedule); -routes.get('/api/v4/top/:type/:page/:subtype?/', animeController.top); +routes.get('/api/v4/top/:type/:subtype?/:page', animeController.top); routes.get('/api/v4/allAnimes', animeController.getAllAnimes); routes.get('/api/v4/lastEpisodes', animeController.getLastEpisodes); routes.get('/api/v4/:url/:type/:page', animeController.getContent); diff --git a/src/utils/util.ts b/src/utils/util.ts index 6ecd1f6..50f2d61 100644 --- a/src/utils/util.ts +++ b/src/utils/util.ts @@ -29,6 +29,8 @@ interface RelatedAnime { export const animeExtraInfo = async (mal_id: number) => { let data: any; + let broadcast: any; + const airDay: any = { mondays: 'Lunes', monday: 'Lunes', @@ -52,14 +54,14 @@ export const animeExtraInfo = async (mal_id: number) => { parse: true, scrapy: false, }); + + broadcast = data.broadcast.split('at')[0].trim().toLowerCase() || null; } catch (err) { return err; } - if ( - airDay.hasOwnProperty(data.broadcast.split('at')[0].trim().toLowerCase()) - ) { - data.broadcast = airDay[data.broadcast.split('at')[0].trim().toLowerCase()]; + if (airDay.hasOwnProperty(broadcast)) { + data.broadcast = airDay[broadcast]; } else { data.broadcast = null; } @@ -451,7 +453,7 @@ function getThemesData(themes: any[]): any { export function getThemes(themes: any[]) { return themes.map((item: any) => ({ name: item.themeName, - type: item.themeType, - video: item.mirror.mirrorURL, + title: item.themeType, + link: item.mirror.mirrorURL, })); }