diff --git a/src/app.ts b/src/app.ts deleted file mode 100644 index 4ff358d..0000000 --- a/src/app.ts +++ /dev/null @@ -1,8 +0,0 @@ -import express from 'express'; -import cors from 'cors'; -// import morgan from 'morgan'; -import routes from './router.js'; -const app = express(); -// app.use(cors(), morgan('dev')); -app.use('/', routes); -export default app; diff --git a/src/config.ts b/src/config.ts deleted file mode 100644 index 781de9e..0000000 --- a/src/config.ts +++ /dev/null @@ -1,28 +0,0 @@ -import axios from 'axios'; - -export const maskScrapingHeaders = { - 'User-Agent': - 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.116 Safari/537.36', -}; - -const url = 'https://monoschinos2.com'; - -export const api = { - home: `${url}`, - all: (id) => `${url}/animes?p=${id}`, - emision: (id) => `${url}/emision?p=${id}`, - calendar: `${url}/calendario`, - search: (id, page) => `${url}/buscar?q=${id.replace(/\s/g, '+')}&p=${page}`, - anime: (id) => `${url}/anime/${id}`, - episode: (id) => `${url}/ver/${id}`, - gender: (id) => `${url}/genero/${id}`, - filter: ({ categoria, fecha, genero, letra, pagina }) => - `${url}/animes?categoria=${categoria}&genero=${genero}&fecha=${fecha}&letra=${letra}&p=${pagina}`, -}; -export function attr(html, selector, attribute = 'src') { - return html.querySelector(selector)?.attributes[attribute]; -} - -export function get(url) { - return axios.get(url, { headers: { ...maskScrapingHeaders } }); -} diff --git a/src/index.ts b/src/index.ts index e661d48..430caec 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,7 +1,13 @@ -import app from './app.js'; -const port = process.env.PORT || 5000; +import express from 'express' +import routes from './router' + +const app = express() + +app.use('/', routes) + +const port = process.env.PORT || 5000 app.listen(port, () => { - console.clear(); - console.info(`API Running on: ${port} ============================`); -}); + console.clear() + console.info(`API Running on: ${port} ============================`) +}) diff --git a/src/router.js b/src/router.js deleted file mode 100644 index ac18fed..0000000 --- a/src/router.js +++ /dev/null @@ -1,61 +0,0 @@ -import { Router } from 'express'; -const routes = Router(); - -import { - getEmision, - getLastest, - getCalendar, - getAnimes, - filterBy, - searchAnime, - getEpisode, - getAnime, -} from './controllers/index.js'; - -routes.get('/', (_, res) => { - res.json({ - message: 'API Works', - author: 'Carlos Burelo', - repository: 'https://github.com/carlos-burelo/monoschinos-api-v2', - endpoints: { - lastest: '/lastest', - emision: '/emision', - calendar: '/week', - getAnimeByID: '/anime/:id', - getAnimesByPage: '/all', - getEpisodeByID: '/ver/:id', - searchAnimeByID: '/search/:id', - filterBy: { - path: '/filterBy', - querys: ['categoria', 'fecha', 'genero', 'letra', 'pagina'], - }, - }, - }); -}); - -routes.get('/lastest', (req, res) => { - getLastest(req, res); -}); -routes.get('/emision', (req, res) => { - getEmision(req, res); -}); -routes.get('/week', (req, res) => { - getCalendar(req, res); -}); -routes.get('/all', (req, res) => { - getAnimes(req, res); -}); -routes.get('/filterBy', (req, res) => { - filterBy(req, res); -}); -routes.get('/search/:id', (req, res) => { - searchAnime(req, res); -}); -routes.get('/ver/:id', (req, res) => { - getEpisode(req, res); -}); -routes.get('/anime/:id', (req, res) => { - getAnime(req, res); -}); - -export default routes; diff --git a/src/router.ts b/src/router.ts new file mode 100644 index 0000000..fdedb9e --- /dev/null +++ b/src/router.ts @@ -0,0 +1,45 @@ +import { Router } from 'express' +import { + getAll, + getLastest, + getCalendar, + getEmision, + getAnime, + searchAnime, + getEpisode, + filterBy, +} from './controllers' + +const routes = Router() + +routes.get('/', (_, res) => { + res.json({ + message: 'API Works', + author: 'Carlos Burelo', + repository: 'https://github.com/carlos-burelo/monoschinos-api-v2', + endpoints: { + lastest: '/lastest', + emision: '/emision', + calendar: '/week', + getAnimeByID: '/anime/:id', + getAnimesByPage: '/all', + getEpisodeByID: '/ver/:id', + searchAnimeByID: '/search/:id', + filterBy: { + path: '/filterBy', + querys: ['categoria', 'fecha', 'genero', 'letra', 'pagina'], + }, + }, + }) +}) + +routes.get('/all', getAll) +routes.get('/lastest', getLastest) +routes.get('/week', getCalendar) +routes.get('/emision', getEmision) +routes.get('/anime/:id', getAnime) +routes.get('/search/:id', searchAnime) +routes.get('/ver/:id', getEpisode) +routes.get('/filterBy', filterBy) + +export default routes diff --git a/src/types.d.ts b/src/types.d.ts index ecbb53a..7b2ba8b 100644 --- a/src/types.d.ts +++ b/src/types.d.ts @@ -1,6 +1,6 @@ import { Request, Response } from 'express' -export type Controller = (req: Request, res: Response) => Promise +export type Controller = (req: Request, res: Response) => void export interface Lastest { id: string @@ -9,3 +9,28 @@ export interface Lastest { type: string no: number } +export interface API { + home: string + all: (id: any) => string + emision: (id: any) => string + calendar: string + search: (id: string, page: any) => string + anime: (id: string) => string + episode: (id: string) => string + gender: (id: string) => string + filter: ({ categoria, fecha, genero, letra, pagina }: Filters) => string +} + +export interface Filters { + categoria: string + fecha: string + genero: string + letra: string + pagina: string +} + +export interface AnimeBasicFields { + id: string + title: string + image: string +}