From 2c156127c870f9f6426077f4f96edffb1c7b6b1d Mon Sep 17 00:00:00 2001 From: carlos-burelo Date: Mon, 21 Mar 2022 13:11:02 -0600 Subject: [PATCH 01/19] :memo: add documentation folder --- docs/Endpoints.md | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 docs/Endpoints.md diff --git a/docs/Endpoints.md b/docs/Endpoints.md new file mode 100644 index 0000000..e69de29 From 5002d41d211ad8d481a0d9b761792e4a0585690d Mon Sep 17 00:00:00 2001 From: carlos-burelo Date: Mon, 21 Mar 2022 13:14:03 -0600 Subject: [PATCH 02/19] :blue_square: Migrating project to typescript --- package.json | 5 ++- yarn.lock | 101 +++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 105 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index a52a706..ead4d99 100644 --- a/package.json +++ b/package.json @@ -12,8 +12,11 @@ "author": "", "license": "ISC", "devDependencies": { + "@types/node": "^17.0.22", + "morgan": "^1.10.0", "nodemon": "^2.0.14", - "morgan": "^1.10.0" + "ts-node": "^10.7.0", + "typescript": "^4.6.2" }, "dependencies": { "axios": "^0.24.0", diff --git a/yarn.lock b/yarn.lock index 5ad1a7e..47a039e 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2,6 +2,18 @@ # yarn lockfile v1 +"@cspotcode/source-map-consumer@0.8.0": + version "0.8.0" + resolved "https://registry.yarnpkg.com/@cspotcode/source-map-consumer/-/source-map-consumer-0.8.0.tgz#33bf4b7b39c178821606f669bbc447a6a629786b" + integrity sha512-41qniHzTU8yAGbCp04ohlmSrZf8bkf/iJsl3V0dRGsQN/5GFfx+LbCSsCpp2gqrqjTVg/K6O8ycoV35JIwAzAg== + +"@cspotcode/source-map-support@0.7.0": + version "0.7.0" + resolved "https://registry.yarnpkg.com/@cspotcode/source-map-support/-/source-map-support-0.7.0.tgz#4789840aa859e46d2f3173727ab707c66bf344f5" + integrity sha512-X4xqRHqN8ACt2aHVe51OxeA2HjbcL4MqFqXkrmQszJ1NOUuUu5u6Vqx/0lZSVNku7velL5FC/s5uEAj1lsBMhA== + dependencies: + "@cspotcode/source-map-consumer" "0.8.0" + "@sindresorhus/is@^0.14.0": version "0.14.0" resolved "https://registry.yarnpkg.com/@sindresorhus/is/-/is-0.14.0.tgz#9fb3a3cf3132328151f353de4632e01e52102bea" @@ -14,6 +26,31 @@ dependencies: defer-to-connect "^1.0.1" +"@tsconfig/node10@^1.0.7": + version "1.0.8" + resolved "https://registry.yarnpkg.com/@tsconfig/node10/-/node10-1.0.8.tgz#c1e4e80d6f964fbecb3359c43bd48b40f7cadad9" + integrity sha512-6XFfSQmMgq0CFLY1MslA/CPUfhIL919M1rMsa5lP2P097N2Wd1sSX0tx1u4olM16fLNhtHZpRhedZJphNJqmZg== + +"@tsconfig/node12@^1.0.7": + version "1.0.9" + resolved "https://registry.yarnpkg.com/@tsconfig/node12/-/node12-1.0.9.tgz#62c1f6dee2ebd9aead80dc3afa56810e58e1a04c" + integrity sha512-/yBMcem+fbvhSREH+s14YJi18sp7J9jpuhYByADT2rypfajMZZN4WQ6zBGgBKp53NKmqI36wFYDb3yaMPurITw== + +"@tsconfig/node14@^1.0.0": + version "1.0.1" + resolved "https://registry.yarnpkg.com/@tsconfig/node14/-/node14-1.0.1.tgz#95f2d167ffb9b8d2068b0b235302fafd4df711f2" + integrity sha512-509r2+yARFfHHE7T6Puu2jjkoycftovhXRqW328PDXTVGKihlb1P8Z9mMZH04ebyajfRY7dedfGynlrFHJUQCg== + +"@tsconfig/node16@^1.0.2": + version "1.0.2" + resolved "https://registry.yarnpkg.com/@tsconfig/node16/-/node16-1.0.2.tgz#423c77877d0569db20e1fc80885ac4118314010e" + integrity sha512-eZxlbI8GZscaGS7kkc/trHTT5xgrjH3/1n2JDwusC9iahPKWMRvRjJSAN5mCXviuTGQ/lHnhvv8Q1YTpnfz9gA== + +"@types/node@^17.0.22": + version "17.0.22" + resolved "https://registry.yarnpkg.com/@types/node/-/node-17.0.22.tgz#38b6c4b9b2f3ed9f2e376cce42a298fb2375251e" + integrity sha512-8FwbVoG4fy+ykY86XCAclKZDORttqE5/s7dyWZKLXTdv3vRy5HozBEinG5IqhvPXXzIZEcTVbuHlQEI6iuwcmw== + abbrev@1: version "1.1.1" resolved "https://registry.yarnpkg.com/abbrev/-/abbrev-1.1.1.tgz#f8f2c887ad10bf67f634f005b6987fed3179aac8" @@ -27,6 +64,16 @@ accepts@~1.3.7: mime-types "~2.1.24" negotiator "0.6.2" +acorn-walk@^8.1.1: + version "8.2.0" + resolved "https://registry.yarnpkg.com/acorn-walk/-/acorn-walk-8.2.0.tgz#741210f2e2426454508853a2f44d0ab83b7f69c1" + integrity sha512-k+iyHEuPgSw6SbuDpGQM+06HQUa04DZ3o+F6CSzXMvvI5KMvnaEqXe+YVe555R9nn6GPt404fos4wcgpw12SDA== + +acorn@^8.4.1: + version "8.7.0" + resolved "https://registry.yarnpkg.com/acorn/-/acorn-8.7.0.tgz#90951fde0f8f09df93549481e5fc141445b791cf" + integrity sha512-V/LGr1APy+PXIwKebEWrkZPwoeoF+w1jiOBUmuxuiUIaOHtob8Qc9BTrYo7VuI5fR8tqsy+buA2WFooR5olqvQ== + ansi-align@^3.0.0: version "3.0.1" resolved "https://registry.yarnpkg.com/ansi-align/-/ansi-align-3.0.1.tgz#0cdf12e111ace773a86e9a1fad1225c43cb19a59" @@ -54,6 +101,11 @@ anymatch@~3.1.2: normalize-path "^3.0.0" picomatch "^2.0.4" +arg@^4.1.0: + version "4.1.3" + resolved "https://registry.yarnpkg.com/arg/-/arg-4.1.3.tgz#269fc7ad5b8e42cb63c896d5666017261c144089" + integrity sha512-58S9QDqG0Xx27YwPSt9fJxivjYl432YCwfDMfZ+71RAqUrZef7LrKQZ3LHLOwCS4FLNBplP533Zx895SeOCHvA== + array-flatten@1.1.1: version "1.1.1" resolved "https://registry.yarnpkg.com/array-flatten/-/array-flatten-1.1.1.tgz#9a5f699051b1e7073328f2a008968b64ea2955d2" @@ -255,6 +307,11 @@ cors@^2.8.5: object-assign "^4" vary "^1" +create-require@^1.1.0: + version "1.1.1" + resolved "https://registry.yarnpkg.com/create-require/-/create-require-1.1.1.tgz#c1d7e8f1e5f6cfc9ff65f9cd352d37348756c333" + integrity sha512-dcKFX3jn0MpIaXjisoRvexIJVEKzaq7z2rZKxf+MSr9TkdmHmsU4m2lcLojrj/FHl8mk5VxMmYA+ftRkP/3oKQ== + crypto-random-string@^2.0.0: version "2.0.0" resolved "https://registry.yarnpkg.com/crypto-random-string/-/crypto-random-string-2.0.0.tgz#ef2a7a966ec11083388369baa02ebead229b30d5" @@ -322,6 +379,11 @@ destroy@~1.0.4: resolved "https://registry.yarnpkg.com/destroy/-/destroy-1.0.4.tgz#978857442c44749e4206613e37946205826abd80" integrity sha1-l4hXRCxEdJ5CBmE+N5RiBYJqvYA= +diff@^4.0.1: + version "4.0.2" + resolved "https://registry.yarnpkg.com/diff/-/diff-4.0.2.tgz#60f3aecb89d5fae520c11aa19efc2bb982aade7d" + integrity sha512-58lmxKSA4BNyLz+HHMUzlOEpg09FV+ev6ZMe3vJihgdxzgcwZ8VoEEPmALCZG9LmqfVoNMMKpttIYTVG6uDY7A== + dom-serializer@^1.0.1: version "1.3.2" resolved "https://registry.yarnpkg.com/dom-serializer/-/dom-serializer-1.3.2.tgz#6206437d32ceefaec7161803230c7a20bc1b4d91" @@ -743,6 +805,11 @@ make-dir@^3.0.0: dependencies: semver "^6.0.0" +make-error@^1.1.1: + version "1.3.6" + resolved "https://registry.yarnpkg.com/make-error/-/make-error-1.3.6.tgz#2eb2e37ea9b67c4891f684a1394799af484cf7a2" + integrity sha512-s8UhlNe7vPKomQhC1qFelMokr/Sc3AgNbso3n74mVPA5LTZwkB9NlXf4XPamLxJE8h0gh73rM94xvwRT2CVInw== + media-typer@0.3.0: version "0.3.0" resolved "https://registry.yarnpkg.com/media-typer/-/media-typer-0.3.0.tgz#8710d7af0aa626f8fffa1ce00168545263255748" @@ -1153,6 +1220,25 @@ touch@^3.1.0: dependencies: nopt "~1.0.10" +ts-node@^10.7.0: + version "10.7.0" + resolved "https://registry.yarnpkg.com/ts-node/-/ts-node-10.7.0.tgz#35d503d0fab3e2baa672a0e94f4b40653c2463f5" + integrity sha512-TbIGS4xgJoX2i3do417KSaep1uRAW/Lu+WAL2doDHC0D6ummjirVOXU5/7aiZotbQ5p1Zp9tP7U6cYhA0O7M8A== + dependencies: + "@cspotcode/source-map-support" "0.7.0" + "@tsconfig/node10" "^1.0.7" + "@tsconfig/node12" "^1.0.7" + "@tsconfig/node14" "^1.0.0" + "@tsconfig/node16" "^1.0.2" + acorn "^8.4.1" + acorn-walk "^8.1.1" + arg "^4.1.0" + create-require "^1.1.0" + diff "^4.0.1" + make-error "^1.1.1" + v8-compile-cache-lib "^3.0.0" + yn "3.1.1" + type-fest@^0.20.2: version "0.20.2" resolved "https://registry.yarnpkg.com/type-fest/-/type-fest-0.20.2.tgz#1bf207f4b28f91583666cb5fbd327887301cd5f4" @@ -1173,6 +1259,11 @@ typedarray-to-buffer@^3.1.5: dependencies: is-typedarray "^1.0.0" +typescript@^4.6.2: + version "4.6.2" + resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.6.2.tgz#fe12d2727b708f4eef40f51598b3398baa9611d4" + integrity sha512-HM/hFigTBHZhLXshn9sN37H085+hQGeJHJ/X7LpBWLID/fbc2acUMfU+lGD98X81sKP+pFa9f0DZmCwB9GnbAg== + undefsafe@^2.0.3: version "2.0.3" resolved "https://registry.yarnpkg.com/undefsafe/-/undefsafe-2.0.3.tgz#6b166e7094ad46313b2202da7ecc2cd7cc6e7aae" @@ -1224,6 +1315,11 @@ utils-merge@1.0.1: resolved "https://registry.yarnpkg.com/utils-merge/-/utils-merge-1.0.1.tgz#9f95710f50a267947b2ccc124741c1028427e713" integrity sha1-n5VxD1CiZ5R7LMwSR0HBAoQn5xM= +v8-compile-cache-lib@^3.0.0: + version "3.0.0" + resolved "https://registry.yarnpkg.com/v8-compile-cache-lib/-/v8-compile-cache-lib-3.0.0.tgz#0582bcb1c74f3a2ee46487ceecf372e46bce53e8" + integrity sha512-mpSYqfsFvASnSn5qMiwrr4VKfumbPyONLCOPmsR3A6pTY/r0+tSaVbgPWSAIuzbk3lCTa+FForeTiO+wBQGkjA== + vary@^1, vary@~1.1.2: version "1.1.2" resolved "https://registry.yarnpkg.com/vary/-/vary-1.1.2.tgz#2299f02c6ded30d4a5961b0b9f74524a18f634fc" @@ -1269,3 +1365,8 @@ yallist@^4.0.0: version "4.0.0" resolved "https://registry.yarnpkg.com/yallist/-/yallist-4.0.0.tgz#9bb92790d9c0effec63be73519e11a35019a3a72" integrity sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A== + +yn@3.1.1: + version "3.1.1" + resolved "https://registry.yarnpkg.com/yn/-/yn-3.1.1.tgz#1e87401a09d767c1d5eab26a6e4c185182d2eb50" + integrity sha512-Ux4ygGWsu2c7isFWe8Yu1YluJmqVhxqK2cLXNQA5AcC3QfbGNpM7fu0Y8b/z16pXLnFxZYvWhd3fhBY9DLmC6Q== From febf8c7da5fad43bdd0f2039b5e6f547247e2a50 Mon Sep 17 00:00:00 2001 From: carlos-burelo Date: Mon, 21 Mar 2022 13:25:37 -0600 Subject: [PATCH 03/19] :blue_square: Add tsconfig for initialize ts project --- src/{index.js => index.ts} | 0 tsconfig.json | 100 +++++++++++++++++++++++++++++++++++++ 2 files changed, 100 insertions(+) rename src/{index.js => index.ts} (100%) create mode 100644 tsconfig.json diff --git a/src/index.js b/src/index.ts similarity index 100% rename from src/index.js rename to src/index.ts diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 0000000..55c1cb6 --- /dev/null +++ b/tsconfig.json @@ -0,0 +1,100 @@ +{ + "compilerOptions": { + /* Visit https://aka.ms/tsconfig.json to read more about this file */ + + /* Projects */ + // "incremental": true, /* Enable incremental compilation */ + // "composite": true, /* Enable constraints that allow a TypeScript project to be used with project references. */ + // "tsBuildInfoFile": "./", /* Specify the folder for .tsbuildinfo incremental compilation files. */ + // "disableSourceOfProjectReferenceRedirect": true, /* Disable preferring source files instead of declaration files when referencing composite projects */ + // "disableSolutionSearching": true, /* Opt a project out of multi-project reference checking when editing. */ + // "disableReferencedProjectLoad": true, /* Reduce the number of projects loaded automatically by TypeScript. */ + + /* Language and Environment */ + "target": "es5" /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */, + // "lib": [], /* Specify a set of bundled library declaration files that describe the target runtime environment. */ + // "jsx": "preserve", /* Specify what JSX code is generated. */ + // "experimentalDecorators": true, /* Enable experimental support for TC39 stage 2 draft decorators. */ + // "emitDecoratorMetadata": true, /* Emit design-type metadata for decorated declarations in source files. */ + // "jsxFactory": "", /* Specify the JSX factory function used when targeting React JSX emit, e.g. 'React.createElement' or 'h' */ + // "jsxFragmentFactory": "", /* Specify the JSX Fragment reference used for fragments when targeting React JSX emit e.g. 'React.Fragment' or 'Fragment'. */ + // "jsxImportSource": "", /* Specify module specifier used to import the JSX factory functions when using `jsx: react-jsx*`.` */ + // "reactNamespace": "", /* Specify the object invoked for `createElement`. This only applies when targeting `react` JSX emit. */ + // "noLib": true, /* Disable including any library files, including the default lib.d.ts. */ + // "useDefineForClassFields": true, /* Emit ECMAScript-standard-compliant class fields. */ + + /* Modules */ + "module": "commonjs" /* Specify what module code is generated. */, + "rootDir": "./src" /* Specify the root folder within your source files. */, + // "moduleResolution": "node", /* Specify how TypeScript looks up a file from a given module specifier. */ + // "baseUrl": "./", /* Specify the base directory to resolve non-relative module names. */ + // "paths": {}, /* Specify a set of entries that re-map imports to additional lookup locations. */ + // "rootDirs": [], /* Allow multiple folders to be treated as one when resolving modules. */ + // "typeRoots": [], /* Specify multiple folders that act like `./node_modules/@types`. */ + // "types": [], /* Specify type package names to be included without being referenced in a source file. */ + // "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */ + // "resolveJsonModule": true, /* Enable importing .json files */ + // "noResolve": true, /* Disallow `import`s, `require`s or ``s from expanding the number of files TypeScript should add to a project. */ + + /* JavaScript Support */ + // "allowJs": true, /* Allow JavaScript files to be a part of your program. Use the `checkJS` option to get errors from these files. */ + // "checkJs": true, /* Enable error reporting in type-checked JavaScript files. */ + // "maxNodeModuleJsDepth": 1, /* Specify the maximum folder depth used for checking JavaScript files from `node_modules`. Only applicable with `allowJs`. */ + + /* Emit */ + // "declaration": true, /* Generate .d.ts files from TypeScript and JavaScript files in your project. */ + // "declarationMap": true, /* Create sourcemaps for d.ts files. */ + // "emitDeclarationOnly": true, /* Only output d.ts files and not JavaScript files. */ + // "sourceMap": true, /* Create source map files for emitted JavaScript files. */ + // "outFile": "./", /* Specify a file that bundles all outputs into one JavaScript file. If `declaration` is true, also designates a file that bundles all .d.ts output. */ + "outDir": "./dist" /* Specify an output folder for all emitted files. */, + // "removeComments": true, /* Disable emitting comments. */ + // "noEmit": true, /* Disable emitting files from a compilation. */ + // "importHelpers": true, /* Allow importing helper functions from tslib once per project, instead of including them per-file. */ + // "importsNotUsedAsValues": "remove", /* Specify emit/checking behavior for imports that are only used for types */ + // "downlevelIteration": true, /* Emit more compliant, but verbose and less performant JavaScript for iteration. */ + // "sourceRoot": "", /* Specify the root path for debuggers to find the reference source code. */ + // "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */ + // "inlineSourceMap": true, /* Include sourcemap files inside the emitted JavaScript. */ + // "inlineSources": true, /* Include source code in the sourcemaps inside the emitted JavaScript. */ + // "emitBOM": true, /* Emit a UTF-8 Byte Order Mark (BOM) in the beginning of output files. */ + // "newLine": "crlf", /* Set the newline character for emitting files. */ + // "stripInternal": true, /* Disable emitting declarations that have `@internal` in their JSDoc comments. */ + // "noEmitHelpers": true, /* Disable generating custom helper functions like `__extends` in compiled output. */ + // "noEmitOnError": true, /* Disable emitting files if any type checking errors are reported. */ + // "preserveConstEnums": true, /* Disable erasing `const enum` declarations in generated code. */ + // "declarationDir": "./", /* Specify the output directory for generated declaration files. */ + + /* Interop Constraints */ + // "isolatedModules": true, /* Ensure that each file can be safely transpiled without relying on other imports. */ + // "allowSyntheticDefaultImports": true, /* Allow 'import x from y' when a module doesn't have a default export. */ + "esModuleInterop": true /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables `allowSyntheticDefaultImports` for type compatibility. */, + // "preserveSymlinks": true, /* Disable resolving symlinks to their realpath. This correlates to the same flag in node. */ + "forceConsistentCasingInFileNames": true /* Ensure that casing is correct in imports. */, + + /* Type Checking */ + "strict": true /* Enable all strict type-checking options. */, + // "noImplicitAny": true, /* Enable error reporting for expressions and declarations with an implied `any` type.. */ + // "strictNullChecks": true, /* When type checking, take into account `null` and `undefined`. */ + // "strictFunctionTypes": true, /* When assigning functions, check to ensure parameters and the return values are subtype-compatible. */ + // "strictBindCallApply": true, /* Check that the arguments for `bind`, `call`, and `apply` methods match the original function. */ + // "strictPropertyInitialization": true, /* Check for class properties that are declared but not set in the constructor. */ + // "noImplicitThis": true, /* Enable error reporting when `this` is given the type `any`. */ + // "useUnknownInCatchVariables": true, /* Type catch clause variables as 'unknown' instead of 'any'. */ + // "alwaysStrict": true, /* Ensure 'use strict' is always emitted. */ + // "noUnusedLocals": true, /* Enable error reporting when a local variables aren't read. */ + // "noUnusedParameters": true, /* Raise an error when a function parameter isn't read */ + // "exactOptionalPropertyTypes": true, /* Interpret optional property types as written, rather than adding 'undefined'. */ + // "noImplicitReturns": true, /* Enable error reporting for codepaths that do not explicitly return in a function. */ + // "noFallthroughCasesInSwitch": true, /* Enable error reporting for fallthrough cases in switch statements. */ + // "noUncheckedIndexedAccess": true, /* Include 'undefined' in index signature results */ + // "noImplicitOverride": true, /* Ensure overriding members in derived classes are marked with an override modifier. */ + // "noPropertyAccessFromIndexSignature": true, /* Enforces using indexed accessors for keys declared using an indexed type */ + // "allowUnusedLabels": true, /* Disable error reporting for unused labels. */ + // "allowUnreachableCode": true, /* Disable error reporting for unreachable code. */ + + /* Completeness */ + // "skipDefaultLibCheck": true, /* Skip type checking .d.ts files that are included with TypeScript. */ + "skipLibCheck": true /* Skip type checking all .d.ts files. */ + } +} From eac48ecef0bb7d8602e5a7129f51ce1165475921 Mon Sep 17 00:00:00 2001 From: carlos-burelo Date: Mon, 21 Mar 2022 13:55:33 -0600 Subject: [PATCH 04/19] :pencil2: initialize types for api docs --- src/types.d.ts | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 src/types.d.ts diff --git a/src/types.d.ts b/src/types.d.ts new file mode 100644 index 0000000..ecbb53a --- /dev/null +++ b/src/types.d.ts @@ -0,0 +1,11 @@ +import { Request, Response } from 'express' + +export type Controller = (req: Request, res: Response) => Promise + +export interface Lastest { + id: string + title: string + image: string + type: string + no: number +} From 82fa9a9ccf27bedbdd6e7f438dbb23ec00bb8944 Mon Sep 17 00:00:00 2001 From: carlos-burelo Date: Mon, 21 Mar 2022 14:58:27 -0600 Subject: [PATCH 05/19] :paintbrush: update preferences in .prettierrc [semicolons] --- .prettierrc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.prettierrc b/.prettierrc index ada6095..17c3d4c 100644 --- a/.prettierrc +++ b/.prettierrc @@ -1,7 +1,7 @@ { "tabWidth": 2, "useTabs": false, - "semi": true, + "semi": false, "singleQuote": true, "printWidth": 100 } From 6d4a8f0d9b454350a9d6e748ca834428c5a82486 Mon Sep 17 00:00:00 2001 From: carlos-burelo Date: Mon, 21 Mar 2022 14:59:58 -0600 Subject: [PATCH 06/19] :label: added types for express --- package.json | 1 + 1 file changed, 1 insertion(+) diff --git a/package.json b/package.json index ead4d99..7eb455c 100644 --- a/package.json +++ b/package.json @@ -12,6 +12,7 @@ "author": "", "license": "ISC", "devDependencies": { + "@types/express": "^4.17.13", "@types/node": "^17.0.22", "morgan": "^1.10.0", "nodemon": "^2.0.14", From f377ba000cf3dd863729bd1fcb5c212b23981771 Mon Sep 17 00:00:00 2001 From: carlos-burelo Date: Mon, 21 Mar 2022 15:00:25 -0600 Subject: [PATCH 07/19] :label: added types for express --- yarn.lock | 59 ++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 58 insertions(+), 1 deletion(-) diff --git a/yarn.lock b/yarn.lock index 47a039e..551ee6d 100644 --- a/yarn.lock +++ b/yarn.lock @@ -46,11 +46,68 @@ resolved "https://registry.yarnpkg.com/@tsconfig/node16/-/node16-1.0.2.tgz#423c77877d0569db20e1fc80885ac4118314010e" integrity sha512-eZxlbI8GZscaGS7kkc/trHTT5xgrjH3/1n2JDwusC9iahPKWMRvRjJSAN5mCXviuTGQ/lHnhvv8Q1YTpnfz9gA== -"@types/node@^17.0.22": +"@types/body-parser@*": + version "1.19.2" + resolved "https://registry.yarnpkg.com/@types/body-parser/-/body-parser-1.19.2.tgz#aea2059e28b7658639081347ac4fab3de166e6f0" + integrity sha512-ALYone6pm6QmwZoAgeyNksccT9Q4AWZQ6PvfwR37GT6r6FWUPguq6sUmNGSMV2Wr761oQoBxwGGa6DR5o1DC9g== + dependencies: + "@types/connect" "*" + "@types/node" "*" + +"@types/connect@*": + version "3.4.35" + resolved "https://registry.yarnpkg.com/@types/connect/-/connect-3.4.35.tgz#5fcf6ae445e4021d1fc2219a4873cc73a3bb2ad1" + integrity sha512-cdeYyv4KWoEgpBISTxWvqYsVy444DOqehiF3fM3ne10AmJ62RSyNkUnxMJXHQWRQQX2eR94m5y1IZyDwBjV9FQ== + dependencies: + "@types/node" "*" + +"@types/express-serve-static-core@^4.17.18": + version "4.17.28" + resolved "https://registry.yarnpkg.com/@types/express-serve-static-core/-/express-serve-static-core-4.17.28.tgz#c47def9f34ec81dc6328d0b1b5303d1ec98d86b8" + integrity sha512-P1BJAEAW3E2DJUlkgq4tOL3RyMunoWXqbSCygWo5ZIWTjUgN1YnaXWW4VWl/oc8vs/XoYibEGBKP0uZyF4AHig== + dependencies: + "@types/node" "*" + "@types/qs" "*" + "@types/range-parser" "*" + +"@types/express@^4.17.13": + version "4.17.13" + resolved "https://registry.yarnpkg.com/@types/express/-/express-4.17.13.tgz#a76e2995728999bab51a33fabce1d705a3709034" + integrity sha512-6bSZTPaTIACxn48l50SR+axgrqm6qXFIxrdAKaG6PaJk3+zuUr35hBlgT7vOmJcum+OEaIBLtHV/qloEAFITeA== + dependencies: + "@types/body-parser" "*" + "@types/express-serve-static-core" "^4.17.18" + "@types/qs" "*" + "@types/serve-static" "*" + +"@types/mime@^1": + version "1.3.2" + resolved "https://registry.yarnpkg.com/@types/mime/-/mime-1.3.2.tgz#93e25bf9ee75fe0fd80b594bc4feb0e862111b5a" + integrity sha512-YATxVxgRqNH6nHEIsvg6k2Boc1JHI9ZbH5iWFFv/MTkchz3b1ieGDa5T0a9RznNdI0KhVbdbWSN+KWWrQZRxTw== + +"@types/node@*", "@types/node@^17.0.22": version "17.0.22" resolved "https://registry.yarnpkg.com/@types/node/-/node-17.0.22.tgz#38b6c4b9b2f3ed9f2e376cce42a298fb2375251e" integrity sha512-8FwbVoG4fy+ykY86XCAclKZDORttqE5/s7dyWZKLXTdv3vRy5HozBEinG5IqhvPXXzIZEcTVbuHlQEI6iuwcmw== +"@types/qs@*": + version "6.9.7" + resolved "https://registry.yarnpkg.com/@types/qs/-/qs-6.9.7.tgz#63bb7d067db107cc1e457c303bc25d511febf6cb" + integrity sha512-FGa1F62FT09qcrueBA6qYTrJPVDzah9a+493+o2PCXsesWHIn27G98TsSMs3WPNbZIEj4+VJf6saSFpvD+3Zsw== + +"@types/range-parser@*": + version "1.2.4" + resolved "https://registry.yarnpkg.com/@types/range-parser/-/range-parser-1.2.4.tgz#cd667bcfdd025213aafb7ca5915a932590acdcdc" + integrity sha512-EEhsLsD6UsDM1yFhAvy0Cjr6VwmpMWqFBCb9w07wVugF7w9nfajxLuVmngTIpgS6svCnm6Vaw+MZhoDCKnOfsw== + +"@types/serve-static@*": + version "1.13.10" + resolved "https://registry.yarnpkg.com/@types/serve-static/-/serve-static-1.13.10.tgz#f5e0ce8797d2d7cc5ebeda48a52c96c4fa47a8d9" + integrity sha512-nCkHGI4w7ZgAdNkrEu0bv+4xNV/XDqW+DydknebMOQwkpDGx8G+HTlj7R7ABI8i8nKxVw0wtKPi1D+lPOkh4YQ== + dependencies: + "@types/mime" "^1" + "@types/node" "*" + abbrev@1: version "1.1.1" resolved "https://registry.yarnpkg.com/abbrev/-/abbrev-1.1.1.tgz#f8f2c887ad10bf67f634f005b6987fed3179aac8" From f04d83a53edaa18413910951f02f732d8e1ac84e Mon Sep 17 00:00:00 2001 From: carlos-burelo Date: Mon, 21 Mar 2022 15:01:17 -0600 Subject: [PATCH 08/19] :blue_square: migrate some js files to ts files --- src/{app.js => app.ts} | 0 src/{config.js => config.ts} | 0 src/controllers/all.ts | 0 3 files changed, 0 insertions(+), 0 deletions(-) rename src/{app.js => app.ts} (100%) rename src/{config.js => config.ts} (100%) create mode 100644 src/controllers/all.ts diff --git a/src/app.js b/src/app.ts similarity index 100% rename from src/app.js rename to src/app.ts diff --git a/src/config.js b/src/config.ts similarity index 100% rename from src/config.js rename to src/config.ts diff --git a/src/controllers/all.ts b/src/controllers/all.ts new file mode 100644 index 0000000..e69de29 From e30432147040153734aa653b0948f49e38824bbf Mon Sep 17 00:00:00 2001 From: carlos-burelo Date: Mon, 21 Mar 2022 17:03:36 -0600 Subject: [PATCH 09/19] :yellow_square: => :blue_square: migrating all controllers from js to ts --- src/controllers/all.js | 23 ------------- src/controllers/all.ts | 21 ++++++++++++ src/controllers/anime.js | 41 ----------------------- src/controllers/anime.ts | 39 ++++++++++++++++++++++ src/controllers/calendar.js | 26 --------------- src/controllers/calendar.ts | 30 +++++++++++++++++ src/controllers/emision.js | 21 ------------ src/controllers/emision.ts | 21 ++++++++++++ src/controllers/episode.js | 65 ------------------------------------- src/controllers/episode.ts | 62 +++++++++++++++++++++++++++++++++++ src/controllers/filterBy.js | 29 ----------------- src/controllers/filterBy.ts | 27 +++++++++++++++ src/controllers/index.js | 8 ----- src/controllers/index.ts | 8 +++++ src/controllers/lastest.js | 23 ------------- src/controllers/lastest.ts | 23 +++++++++++++ src/controllers/search.js | 24 -------------- src/controllers/search.ts | 22 +++++++++++++ 18 files changed, 253 insertions(+), 260 deletions(-) delete mode 100644 src/controllers/all.js delete mode 100644 src/controllers/anime.js create mode 100644 src/controllers/anime.ts delete mode 100644 src/controllers/calendar.js create mode 100644 src/controllers/calendar.ts delete mode 100644 src/controllers/emision.js create mode 100644 src/controllers/emision.ts delete mode 100644 src/controllers/episode.js create mode 100644 src/controllers/episode.ts delete mode 100644 src/controllers/filterBy.js create mode 100644 src/controllers/filterBy.ts delete mode 100644 src/controllers/index.js create mode 100644 src/controllers/index.ts delete mode 100644 src/controllers/lastest.js create mode 100644 src/controllers/lastest.ts delete mode 100644 src/controllers/search.js create mode 100644 src/controllers/search.ts diff --git a/src/controllers/all.js b/src/controllers/all.js deleted file mode 100644 index 3c5e232..0000000 --- a/src/controllers/all.js +++ /dev/null @@ -1,23 +0,0 @@ -import { parse } from 'node-html-parser'; -import { attr, api, get } from '../config.js'; - -export async function getAnimes(req, res) { - try { - let { page = '1' } = req.params; - const { data } = await get(`${api.all(page)}`); - const html = parse(data); - res.status(200).json( - html.querySelectorAll('.heromain .row .col-md-4.col-lg-2.col-6').map((i) => { - return { - id: attr(i, 'a', 'href').split('/').pop() || null, - title: i.querySelector('.seristitles').text.trim() || null, - image: attr(i, '.animemainimg', 'src') || null, - }; - }) - ); - } catch (err) { - res.status(500).json({ - message: err.message, - }); - } -} diff --git a/src/controllers/all.ts b/src/controllers/all.ts index e69de29..db04312 100644 --- a/src/controllers/all.ts +++ b/src/controllers/all.ts @@ -0,0 +1,21 @@ +import { Controller } from '../types' +import { get, parse, attr, api } from '../api' + +export const getAll: Controller = async (req, res) => { + try { + const { page = '1' } = req.query + const { data } = await get(api.all(page)) + const html = parse(data) + res.status(200).json( + html.querySelectorAll('.heromain .row .col-md-4.col-lg-2.col-6').map(i => { + return { + id: attr(i, 'a', 'href').split('/').pop() || null, + title: i.querySelector('.seristitles')?.text.trim() || null, + image: attr(i, '.animemainimg', 'src') || null, + } + }) + ) + } catch (error) { + res.status(500).json({ error }) + } +} diff --git a/src/controllers/anime.js b/src/controllers/anime.js deleted file mode 100644 index 0ea47f1..0000000 --- a/src/controllers/anime.js +++ /dev/null @@ -1,41 +0,0 @@ -import { attr, api, get } from '../config.js'; -import { parse } from 'node-html-parser'; - -export async function getAnime(req, res) { - try { - const url = 'https://monoschinos2.com/'; - const { id } = req.params; - const { data } = await get(api.anime(id)); - const html = parse(data); - const date = html.querySelectorAll('.breadcrumb')[1].querySelector('.breadcrumb-item').text; - res.status(200).json({ - banner: attr(html, '.herobg img', 'src'), - image: attr(html, '.chapterpic img', 'src'), - title: - html - .querySelector('.chapterdetails h1') - .text.replace(/Sub Español/gi, '') - .trim() || null, - titleAlt: html.querySelector('.alterno').text || null, - sinopsis: html.querySelector('.textComplete').text.replace('Ver menos', '') || null, - status: html.querySelector('#btninfo').text.trim() || null, - rating: html.querySelector('.chapterpic p').text || null, - genders: html.querySelectorAll('.breadcrumb .breadcrumb-item a').map((g) => g.text) || null, - date: date || null, - episodes: - html.querySelectorAll('.row.jpage.row-cols-md-6 .col-item a').map((cap) => { - const epId = cap.attributes['href'].replace(`${url}ver/`, ''); - return { - image: attr(cap, '.animeimghv', 'data-src'), - no: parseInt(epId.split('-').pop()), - id: epId, - }; - }) || null, - }); - } catch (error) { - res.status(500).json({ - id: 'intertal-server-error', - message: error.message, - }); - } -} diff --git a/src/controllers/anime.ts b/src/controllers/anime.ts new file mode 100644 index 0000000..4e599fd --- /dev/null +++ b/src/controllers/anime.ts @@ -0,0 +1,39 @@ +import { attr, api, get, parse } from '../api' + +import { Controller } from '../types.js' + +export const getAnime: Controller = async (req, res) => { + try { + const url = 'https://monoschinos2.com/' + const { id } = req.params + const { data } = await get(api.anime(id)) + const html = parse(data) + const date = html.querySelectorAll('.breadcrumb')[1].querySelector('.breadcrumb-item')?.text + res.status(200).json({ + banner: attr(html, '.herobg img', 'src'), + image: attr(html, '.chapterpic img', 'src'), + title: + html + .querySelector('.chapterdetails h1') + ?.text.replace(/Sub Español/gi, '') + .trim() || null, + titleAlt: html.querySelector('.alterno')?.text || null, + sinopsis: html.querySelector('.textComplete')?.text.replace('Ver menos', '') || null, + status: html.querySelector('#btninfo')?.text.trim() || null, + rating: html.querySelector('.chapterpic p')?.text || null, + genders: html.querySelectorAll('.breadcrumb .breadcrumb-item a').map(g => g.text) || null, + date: date || null, + episodes: + html.querySelectorAll('.row.jpage.row-cols-md-6 .col-item a').map(cap => { + const epId = cap.attributes['href'].replace(`${url}ver/`, '') + return { + image: attr(cap, '.animeimghv', 'data-src'), + no: parseInt(epId.split('-').pop() as string), + id: epId, + } + }) || null, + }) + } catch (error) { + res.status(500).json({ error }) + } +} diff --git a/src/controllers/calendar.js b/src/controllers/calendar.js deleted file mode 100644 index a6fa2a7..0000000 --- a/src/controllers/calendar.js +++ /dev/null @@ -1,26 +0,0 @@ -import { parse } from 'node-html-parser'; -import { attr, api, get } from '../config.js'; - -export async function getCalendar(req, res) { - try { - const { data } = await get(api.calendar); - const html = parse(data); - res.status(200).json( - html.querySelectorAll('.heromain [data-dia]').map((i) => { - const day = i.getAttribute('data-dia'); - return { - day, - animes: i.querySelectorAll('.col-md-6.col-lg-4.col-sm-12.for768').map((i) => { - return { - id: attr(i, 'a', 'href').split('/').pop() || null, - title: i.querySelector('.serisdtls a h3').text.trim() || null, - image: attr(i, '.seriesimg a img') || null, - }; - }), - }; - }) - ); - } catch (error) { - res.status(500).json({ message: error.message }); - } -} diff --git a/src/controllers/calendar.ts b/src/controllers/calendar.ts new file mode 100644 index 0000000..6fe01da --- /dev/null +++ b/src/controllers/calendar.ts @@ -0,0 +1,30 @@ +import { attr, api, get, parse } from '../api' +import { Controller } from '../types' + +export const getCalendar: Controller = async (req, res) => { + try { + const { data } = await get(api.calendar) + const html = parse(data) + res.status(200).json( + html.querySelectorAll('.heromain [data-dia]').map(i => { + const day = i.getAttribute('data-dia') + return { + day, + animes: i.querySelectorAll('.col-md-6.col-lg-4.col-sm-12.for768').map(i => { + const no = i.querySelector('.serisdtls a h4')?.text.trim() + const tags = i.querySelectorAll('.serisdtls .seriesbtns a') + return { + id: attr(i, 'a', 'href').split('/').pop() || null, + title: i.querySelector('.serisdtls a h3')?.text.trim() || null, + image: attr(i, '.seriesimg a img') || null, + tags: tags.map(i => i.querySelector('button')?.text.trim() || null), + no: parseInt(no?.replace(/\w+\s/, '') as string) || null, + } + }), + } + }) + ) + } catch (error) { + res.status(500).json({ error }) + } +} diff --git a/src/controllers/emision.js b/src/controllers/emision.js deleted file mode 100644 index 687cfc9..0000000 --- a/src/controllers/emision.js +++ /dev/null @@ -1,21 +0,0 @@ -import { attr, api, get } from '../config.js'; -import { parse } from 'node-html-parser'; - -export async function getEmision(req, res) { - try { - let { page = '1' } = req.query; - const { data } = await get(api.emision(page)); - const html = parse(data); - res.status(200).json( - html.querySelectorAll('.heromain .row .col-md-4.col-lg-2.col-6').map((i) => { - return { - id: attr(i, 'a', 'href').split('/').pop() || null, - title: i.querySelector('.seristitles').text.trim() || null, - image: attr(i, '.animemainimg') || null, - }; - }) - ); - } catch (error) { - res.status(500).json({ message: error.message }); - } -} diff --git a/src/controllers/emision.ts b/src/controllers/emision.ts new file mode 100644 index 0000000..c9523b7 --- /dev/null +++ b/src/controllers/emision.ts @@ -0,0 +1,21 @@ +import { attr, api, get, parse } from '../api' +import { Controller } from '../types' + +export const getEmision: Controller = async (req, res) => { + try { + const { page = '1' } = req.query + const { data } = await get(api.emision(page)) + const html = parse(data) + res.status(200).json( + html.querySelectorAll('.heromain .row .col-md-4.col-lg-2.col-6').map(i => { + return { + id: attr(i, 'a', 'href').split('/').pop() || null, + title: i.querySelector('.seristitles')?.text.trim() || null, + image: attr(i, '.animemainimg') || null, + } + }) + ) + } catch (error) { + res.status(500).json({ error }) + } +} diff --git a/src/controllers/episode.js b/src/controllers/episode.js deleted file mode 100644 index 43e194f..0000000 --- a/src/controllers/episode.js +++ /dev/null @@ -1,65 +0,0 @@ -import { attr, api, get } from '../config.js'; -import { parse } from 'node-html-parser'; - -export async function getEpisode(req, res) { - try { - const { id } = req.params; - const { data } = await get(api.episode(id)); - const html = parse(data); - const ctrls = html.querySelectorAll('.controldiv2 a'); - - let nav = {}; - let mapc = ctrls.map((e, i) => { - let elem = e.querySelector('img').classList; - return !elem.contains('playlist'); - }); - if (mapc.length == 3) { - nav = { next: true, prev: true }; - } else { - if (mapc[1] == true) nav = { next: true, prev: false }; - if (mapc[1] == false) nav = { next: false, prev: true }; - } - const nextEpisodes = html.querySelectorAll('.nextplay:nth-child(1) .nextplays a').map((i) => { - return { - image: attr(i, '.nxtmainimg', 'src'), - date: i.querySelector('.nxtplaybtn p').text, - title: i.querySelector('.nxtplaybtn h5').text, - no: i.querySelector('.nxtplaybtn span').text, - }; - }); - const imgNotFound = - 'https://konachan.com/image/bbb46f65d3130526c20fcd781d6800cf/Konachan.com%20-%2041974%20fuura_kafuka%20itoshiki_nozomu%20sayonara_zetsubou_sensei%20white.png'; - res.json({ - title: html.querySelector('.heromain_h1').text.replace(/Sub\sEspañol/gi, ''), - nextEpisodes: nextEpisodes.length == 0 ? null : nextEpisodes, - ctrs: nav, - sugestions: html.querySelectorAll('.nextplay:nth-child(3) .nextplays a').map((i) => { - const image = attr(i, '.nxtmainimg', 'src'); - return { - image: image.length == 0 || !image ? imgNotFound : image, - date: i.querySelector('.nxtplaybtn p').text, - title: i.querySelector('.nxtplaybtn h5').text, - no: i.querySelector('.nxtplaybtn span').text, - }; - }), - videos: html.querySelectorAll('.dropcaps .play-video').map((i) => { - const base64 = i.attrs['data-player']; - const title = i.rawText; - return { - title, - url: Buffer.from(base64, 'base64').toString('ascii'), - }; - }), - downloads: html.querySelectorAll('.downbtns a').map((i) => { - return { - title: i.text, - url: i.attrs['href'], - }; - }), - }); - } catch (err) { - res.status(500).json({ - message: err.message, - }); - } -} diff --git a/src/controllers/episode.ts b/src/controllers/episode.ts new file mode 100644 index 0000000..e429b39 --- /dev/null +++ b/src/controllers/episode.ts @@ -0,0 +1,62 @@ +import { attr, api, get, parse } from '../api' +import { Controller } from '../types' + +export const getEpisode: Controller = async (req, res) => { + try { + const { id } = req.params + const { data } = await get(api.episode(id)) + const html = parse(data) + const ctrls = html.querySelectorAll('.controldiv2 a') + let nav = {} + let mapc = ctrls.map((e, i) => { + let elem = e.querySelector('img')?.classList + return !elem?.contains('playlist') + }) + if (mapc.length == 3) { + nav = { next: true, prev: true } + } else { + if (mapc[1] == true) nav = { next: true, prev: false } + if (mapc[1] == false) nav = { next: false, prev: true } + } + const nextEpisodes = html.querySelectorAll('.nextplay:nth-child(1) .nextplays a').map(i => { + return { + image: attr(i, '.nxtmainimg', 'src'), + date: i.querySelector('.nxtplaybtn p')?.text, + title: i.querySelector('.nxtplaybtn h5')?.text, + no: i.querySelector('.nxtplaybtn span')?.text, + } + }) + const imgNotFound = + 'https://konachan.com/image/bbb46f65d3130526c20fcd781d6800cf/Konachan.com%20-%2041974%20fuura_kafuka%20itoshiki_nozomu%20sayonara_zetsubou_sensei%20white.png' + res.json({ + title: html.querySelector('.heromain_h1')?.text.replace(/Sub\sEspañol/gi, ''), + nextEpisodes: nextEpisodes.length == 0 ? null : nextEpisodes, + ctrs: nav, + sugestions: html.querySelectorAll('.nextplay:nth-child(3) .nextplays a').map(i => { + const image = attr(i, '.nxtmainimg', 'src') + return { + image: image.length == 0 || !image ? imgNotFound : image, + date: i.querySelector('.nxtplaybtn p')?.text, + title: i.querySelector('.nxtplaybtn h5')?.text, + no: i.querySelector('.nxtplaybtn span')?.text, + } + }), + videos: html.querySelectorAll('.dropcaps .play-video').map(i => { + const base64 = i.attrs['data-player'] + const title = i.rawText + return { + title, + url: Buffer.from(base64, 'base64').toString('ascii'), + } + }), + downloads: html.querySelectorAll('.downbtns a').map(i => { + return { + title: i.text, + url: i.attrs['href'], + } + }), + }) + } catch (error) { + res.status(500).json({ error }) + } +} diff --git a/src/controllers/filterBy.js b/src/controllers/filterBy.js deleted file mode 100644 index c796159..0000000 --- a/src/controllers/filterBy.js +++ /dev/null @@ -1,29 +0,0 @@ -import { parse } from 'node-html-parser'; -import { api, attr, get } from '../config.js'; - -export async function filterBy(req, res) { - try { - let { - categoria = 'false', - fecha = 'false', - genero = 'false', - letra = 'false', - pagina = '1', - } = req.query; - const { data } = await get(`${api.filter({ categoria, fecha, genero, letra, pagina })}`); - const html = parse(data); - res.status(200).json( - html.querySelectorAll('.heromain .row .col-md-4.col-lg-2.col-6').map((i) => { - return { - id: attr(i, 'a', 'href').split('/').pop() || null, - title: i.querySelector('.seristitles').text.trim() || null, - image: attr(i, '.animemainimg', 'src') || null, - }; - }) - ); - } catch (err) { - res.status(500).json({ - message: err.message, - }); - } -} diff --git a/src/controllers/filterBy.ts b/src/controllers/filterBy.ts new file mode 100644 index 0000000..b84e2c2 --- /dev/null +++ b/src/controllers/filterBy.ts @@ -0,0 +1,27 @@ +import { api, attr, get, parse } from '../api' +import { Controller } from '../types' + +export const filterBy: Controller = async (req, res) => { + try { + const { + categoria = 'false', + fecha = 'false', + genero = 'false', + letra = 'false', + pagina = '1', + }: { [key: string]: any } = req.query + const { data } = await get(api.filter({ categoria, fecha, genero, letra, pagina })) + const html = parse(data) + res.status(200).json( + html.querySelectorAll('.heromain .row .col-md-4.col-lg-2.col-6').map(i => { + return { + id: attr(i, 'a', 'href').split('/').pop() || null, + title: i.querySelector('.seristitles')?.text.trim() || null, + image: attr(i, '.animemainimg', 'src') || null, + } + }) + ) + } catch (error) { + res.status(500).json({ error }) + } +} diff --git a/src/controllers/index.js b/src/controllers/index.js deleted file mode 100644 index d6f74a3..0000000 --- a/src/controllers/index.js +++ /dev/null @@ -1,8 +0,0 @@ -export * from './all.js'; -export * from './calendar.js'; -export * from './emision.js'; -export * from './episode.js'; -export * from './filterBy.js'; -export * from './lastest.js'; -export * from './search.js'; -export * from './anime.js'; diff --git a/src/controllers/index.ts b/src/controllers/index.ts new file mode 100644 index 0000000..3d912f2 --- /dev/null +++ b/src/controllers/index.ts @@ -0,0 +1,8 @@ +export * from './all' +export * from './anime' +export * from './lastest' +export * from './calendar' +export * from './emision' +export * from './search' +export * from './episode' +export * from './filterBy' diff --git a/src/controllers/lastest.js b/src/controllers/lastest.js deleted file mode 100644 index 4e9d453..0000000 --- a/src/controllers/lastest.js +++ /dev/null @@ -1,23 +0,0 @@ -import { attr, api, get } from '../config.js'; -import { parse } from 'node-html-parser'; - -export async function getLastest(req, res) { - try { - const { data } = await get(api.home); - const html = parse(data); - res.json( - html.querySelectorAll('.row.row-cols-5 .col.col-md-6.col-lg-2.col-6').map((i) => { - const id = attr(i, 'a', 'href').split('/').pop(); - return { - id: id || null, - title: i.querySelector('.animetitles')?.text || null, - image: attr(i, '.animeimgdiv img', 'data-src') || null, - type: i.querySelector('.positioning button').text.trim() || null, - no: parseInt(i.querySelector('.positioning h5').text.trim() || '0') || null, - }; - }) - ); - } catch (error) { - res.status(500).json({ message: error.message }); - } -} diff --git a/src/controllers/lastest.ts b/src/controllers/lastest.ts new file mode 100644 index 0000000..5684d7f --- /dev/null +++ b/src/controllers/lastest.ts @@ -0,0 +1,23 @@ +import { Controller } from '../types' +import { get, parse, attr, url } from '../api' + +export const getLastest: Controller = async (req, res) => { + try { + const { data } = await get(url) + const html = parse(data) + res.json( + html.querySelectorAll('.row.row-cols-5 .col.col-md-6.col-lg-2.col-6').map(i => { + const id = attr(i, 'a', 'href').split('/').pop() + return { + id: id || null, + title: i.querySelector('.animetitles')?.text || null, + image: attr(i, '.animeimgdiv img', 'data-src') || null, + type: i.querySelector('.positioning button')?.text.trim() || null, + no: parseInt(i.querySelector('.positioning h5')?.text.trim() || '0') || null, + } + }) + ) + } catch (error) { + res.status(500).json({ error }) + } +} diff --git a/src/controllers/search.js b/src/controllers/search.js deleted file mode 100644 index 52487dc..0000000 --- a/src/controllers/search.js +++ /dev/null @@ -1,24 +0,0 @@ -import { parse } from 'node-html-parser'; -import { api, attr, get } from '../config.js'; - -export async function searchAnime(req, res) { - try { - let { id } = req.params; - let { page = '1' } = req.query; - const { data } = await get(api.search(id, page)); - const html = parse(data); - res.json( - html.querySelectorAll('.heromain .row .col-md-4.col-lg-2.col-6').map((i) => { - return { - id: attr(i, 'a', 'href').split('/').pop() || null, - title: i.querySelector('.seristitles ').text || null, - image: attr(i, '.seriesimg .animemainimg', 'src') || null, - }; - }) - ); - } catch (error) { - res.status(500).json({ - message: error.message, - }); - } -} diff --git a/src/controllers/search.ts b/src/controllers/search.ts new file mode 100644 index 0000000..197df7f --- /dev/null +++ b/src/controllers/search.ts @@ -0,0 +1,22 @@ +import { api, attr, get, parse } from '../api' +import { Controller } from '../types' + +export const searchAnime: Controller = async (req, res) => { + try { + const { id } = req.params + const { page = '1' } = req.query + const { data } = await get(api.search(id, page)) + const html = parse(data) + res.json( + html.querySelectorAll('.heromain .row .col-md-4.col-lg-2.col-6').map(i => { + return { + id: attr(i, 'a', 'href').split('/').pop() || null, + title: i.querySelector('.seristitles ')?.text || null, + image: attr(i, '.seriesimg .animemainimg', 'src') || null, + } + }) + ) + } catch (error) { + res.status(500).json({ error }) + } +} From eee3600940d86f7d27bc481e61b7e37d60af0b19 Mon Sep 17 00:00:00 2001 From: carlos-burelo Date: Mon, 21 Mar 2022 17:05:49 -0600 Subject: [PATCH 10/19] :zap: reduce partials utilities to one file --- src/api.ts | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 src/api.ts diff --git a/src/api.ts b/src/api.ts new file mode 100644 index 0000000..8540fde --- /dev/null +++ b/src/api.ts @@ -0,0 +1,37 @@ +import axios from 'axios' +import { parse } from 'node-html-parser' + +import { API } from './types' + +export const headers = { + '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', +} + +export const url = 'https://monoschinos2.com' + +export const api: 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 get(url: string) { + return axios.get(url, { headers }) +} + +export function attr( + html: HTMLElement | any, + selector: string, + attribute: string | undefined = 'src' +) { + return html.querySelector(selector)?.attributes[attribute as any] as unknown as string +} +export { parse } From a77af3d32fff0cd73c8f2234365220b049c22397 Mon Sep 17 00:00:00 2001 From: carlos-burelo Date: Mon, 21 Mar 2022 17:06:40 -0600 Subject: [PATCH 11/19] :arrow_up: update some preferences and remove unnecesary files --- src/app.ts | 8 ------- src/config.ts | 28 ----------------------- src/index.ts | 16 ++++++++----- src/router.js | 61 -------------------------------------------------- src/router.ts | 45 +++++++++++++++++++++++++++++++++++++ src/types.d.ts | 27 +++++++++++++++++++++- 6 files changed, 82 insertions(+), 103 deletions(-) delete mode 100644 src/app.ts delete mode 100644 src/config.ts delete mode 100644 src/router.js create mode 100644 src/router.ts 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 +} From 972b6e31751200fc204e75b8a2f116d3a4c21b2b Mon Sep 17 00:00:00 2001 From: carlos-burelo Date: Mon, 21 Mar 2022 17:07:37 -0600 Subject: [PATCH 12/19] :paintbrush: update code style prefs --- .prettierrc | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.prettierrc b/.prettierrc index 17c3d4c..87618fb 100644 --- a/.prettierrc +++ b/.prettierrc @@ -3,5 +3,8 @@ "useTabs": false, "semi": false, "singleQuote": true, - "printWidth": 100 + "printWidth": 100, + "bracketSpacing": true, + "arrowParens": "avoid", + "endOfLine": "lf" } From 0875346c3dc9379e339b1a4e238486e63425687a Mon Sep 17 00:00:00 2001 From: carlos-burelo Date: Mon, 21 Mar 2022 17:09:33 -0600 Subject: [PATCH 13/19] :memo: update api documentation (provisiona) --- README.md | 238 +--------------------------------------------- docs/Endpoints.md | 230 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 234 insertions(+), 234 deletions(-) diff --git a/README.md b/README.md index 7c0ffb9..d5c78ab 100644 --- a/README.md +++ b/README.md @@ -1,237 +1,7 @@ -# Monoschinos API REST V2 +# Monoschinos API +![Banner](https://media.graphcms.com/ZcGixDrxSQmSJHBlB8sK) -## Endpoints - -> PATH: /lastest - -|Querys|Params| -|-|-| -|none|none| - -```js -[ - { - "id": "kimetsu-no-yaiba-yuukaku-hen-episodio-1", - "title": "Kimetsu no Yaiba: Yuukaku-hen", - "image": "https://monoschinos2.com/assets/img/serie/episodio/kimetsu-no-yaiba-yuukaku-hen-1-1638722630.jpg", - "type": "Anime", - "no": 1 - }, - { - "id": "mushoku-tensei-isekai-ittara-honki-dasu-2nd-season-episodio-10", - "title": "Mushoku Tensei: Isekai Ittara Honki Dasu 2nd Season", - "image": "https://monoschinos2.com/assets/img/serie/episodio/mushoku-tensei-isekai-ittara-honki-dasu-2nd-season-10-1638721531.jpg", - "type": "Anime", - "no": 10 - }, - ... -] -``` - - -> PATH: /emision - -|Querys|Params| -|-|-| -|`page`|none| - -```js -[ - { - "id": "jojos-bizarre-adventure-stone-ocean-sub-espanol", - "title": "JoJo's Bizarre Adventure: Stone Ocean", - "image": "https://monoschinos2.com/thumbs/imagen/jojos-bizarre-adventure-stone-ocean-1638350799.jpg?v=1" - }, - { - "id": "kimetsu-no-yaiba-yuukaku-hen-sub-espanol", - "title": "Kimetsu no Yaiba: Yuukaku-hen", - "image": "https://monoschinos2.com/thumbs/imagen/kimetsu-distrito-rojo.jpg?v=1" - }, - ... -] -``` - - -> PATH: /week - -|Querys|Params| -|-|-| -|none|none| - -```js -[ - { - "day": "lunes", - "animes": [ - { - "id": "shinka-no-mi-shiranai-uchi-ni-kachigumi-jinsei-sub-espanol", - "title": "Shinka no Mi: Shiranai Uchi ni Kachigumi Jinsei", - "image": "https://monoschinos2.com/thumbs/imagen/shinka-no-mi-shiranai-uchi-ni-kachigumi-jinsei-1637559521.jpg?v=1" - }, - ... - ] - }, - ... -] -``` - - -> PATH: /all - -|Querys|Params| -|-|-| -|`page`|none| - -```js -[ - { - "id": "mai-otome-zwei-sub-espanol", - "title": "Mai-Otome Zwei", - "image": "https://monoschinos2.com/thumbs/imagen/mai-otome-zwei-1638649807.jpg?v=1" - }, - { - "id": "mai-hime-sub-espanol", - "title": "Mai-HiME", - "image": "https://monoschinos2.com/thumbs/imagen/mai-hime-1638591018.jpg?v=1" - }, - ... -] -``` - - -> PATH: /search/:id - -|Querys|Params| -|-|-| -|none|`id`| - -```js -[ - { - "id": "mai-otome-zwei-sub-espanol", - "title": "Mai-Otome Zwei", - "image": "https://monoschinos2.com/thumbs/imagen/mai-otome-zwei-1638649807.jpg?v=1" - }, - { - "id": "mai-hime-sub-espanol", - "title": "Mai-HiME", - "image": "https://monoschinos2.com/thumbs/imagen/mai-hime-1638591018.jpg?v=1" - }, - ... -] -``` - - - - -> PATH: /filterBy - -|Querys|Params| -|-|-| -|`pagina` , `categoria`, `fecha` ,`genero`, `letra`|none| - -```js -[ - { - "id": "mai-otome-zwei-sub-espanol", - "title": "Mai-Otome Zwei", - "image": "https://monoschinos2.com/thumbs/imagen/mai-otome-zwei-1638649807.jpg?v=1" - }, - { - "id": "mai-hime-sub-espanol", - "title": "Mai-HiME", - "image": "https://monoschinos2.com/thumbs/imagen/mai-hime-1638591018.jpg?v=1" - }, - ... -] -``` - - -> PATH: /ver/:id - -|Querys|Params| -|-|-| -|none|`id`| - -```js -{ - "title": "Kaifuku Jutsushi no Yarinaoshi. 2 ", - "nextEpisodes": [ - { - "image": "https://monoschinos2.com/assets/img/serie/episodio/kaifuku-jutsushi-no-yarinaoshi-3.png", - "date": "27 Ene 2021", - "title": "Kaifuku Jutsushi no Yarinaoshi", - "no": "Capitulo 3" - } - ], - "ctrs": { - "next": true, - "prev": true - }, - "sugestions": [ - { - "image": "https://monoschinos2.com/thumbs/portada/gundamhathawayvisual-e1621256405818.jpg?v=1.1", - "date": "08 Jul 2021", - "title": "Mobile Suit Gundam: Hathaway's Flash", - "no": "Capitulo 1" - }, - ... - ], - "videos": [ - { - "title": "cloud", - "url": "https://monoschinos2.com/reproductor?url=https://repro.monoschinos2.com/aqua/cl?url=redo02.mp4" - }, - ... - ], - "downloads": [ - { - "title": "1fichier ", - "url": "https://1fichier.com/?yssqgolputegizq4xkhb" - }, - ... - ] -} -``` - - - -> PATH: /anime/:id - -|Querys|Params| -|-|-| -|none|`id`| - -```js -{ - "banner": "https://monoschinos2.com/assets/img/serie/portada/portada_kimetsu-37.jpg", - "image": "https://monoschinos2.com/thumbs/imagen/crunchyroll-Demon-Slayer-Kimetsu-no-Yaiba-Mugen-Train-Arc.jpg?v=1", - "title": "Kimetsu no Yaiba: Mugen Ressha-hen (TV)", - "sinopsis": "Versión para televisión de la película Mugen Train que conecta el arco de Tanjiro Kamado, Resolve inquebrantable con el arco del distrito de entretenimiento , que presenta un episodio original de televisión nunca antes visto de Kyojuro Rengoku asumiendo una nueva misión en el camino hacia el tren Mugen.\nAdemás del episodio completamente nuevo, la serie también incluirá 70 escenas nuevas, nuevas pistas musicales, avances de episodios y nuevos temas musicales.\n", - "status": "Finalizado", - "date": 2021, - "rating": "4.8", - "genders": [ - "Acción", - "Aventura", - "Gore", - "Shonen", - "Histórico" - ], - "episodes": [ - { - "image": "https://monoschinos2.com/thumbs/portada/portada_kimetsu-37.jpg?v=1.1", - "no": 1, - "id": "kimetsu-no-yaiba-mugen-ressha-hen-tv-episodio-1" - }, - ... - ] -} -``` - - - -### Author: Carlos Burelo - +## Docs +### [Endpoints](./docs/Endpoints.md) diff --git a/docs/Endpoints.md b/docs/Endpoints.md index e69de29..3fcc796 100644 --- a/docs/Endpoints.md +++ b/docs/Endpoints.md @@ -0,0 +1,230 @@ +## Endpoints + +> PATH: /lastest + +|Querys|Params| +|-|-| +|none|none| + +```js +[ + { + "id": "kimetsu-no-yaiba-yuukaku-hen-episodio-1", + "title": "Kimetsu no Yaiba: Yuukaku-hen", + "image": "https://monoschinos2.com/assets/img/serie/episodio/kimetsu-no-yaiba-yuukaku-hen-1-1638722630.jpg", + "type": "Anime", + "no": 1 + }, + { + "id": "mushoku-tensei-isekai-ittara-honki-dasu-2nd-season-episodio-10", + "title": "Mushoku Tensei: Isekai Ittara Honki Dasu 2nd Season", + "image": "https://monoschinos2.com/assets/img/serie/episodio/mushoku-tensei-isekai-ittara-honki-dasu-2nd-season-10-1638721531.jpg", + "type": "Anime", + "no": 10 + }, + ... +] +``` + + +> PATH: /emision + +|Querys|Params| +|-|-| +|`page`|none| + +```js +[ + { + "id": "jojos-bizarre-adventure-stone-ocean-sub-espanol", + "title": "JoJo's Bizarre Adventure: Stone Ocean", + "image": "https://monoschinos2.com/thumbs/imagen/jojos-bizarre-adventure-stone-ocean-1638350799.jpg?v=1" + }, + { + "id": "kimetsu-no-yaiba-yuukaku-hen-sub-espanol", + "title": "Kimetsu no Yaiba: Yuukaku-hen", + "image": "https://monoschinos2.com/thumbs/imagen/kimetsu-distrito-rojo.jpg?v=1" + }, + ... +] +``` + + +> PATH: /week + +|Querys|Params| +|-|-| +|none|none| + +```js +[ + { + "day": "lunes", + "animes": [ + { + "id": "shinka-no-mi-shiranai-uchi-ni-kachigumi-jinsei-sub-espanol", + "title": "Shinka no Mi: Shiranai Uchi ni Kachigumi Jinsei", + "image": "https://monoschinos2.com/thumbs/imagen/shinka-no-mi-shiranai-uchi-ni-kachigumi-jinsei-1637559521.jpg?v=1" + }, + ... + ] + }, + ... +] +``` + + +> PATH: /all + +|Querys|Params| +|-|-| +|`page`|none| + +```js +[ + { + "id": "mai-otome-zwei-sub-espanol", + "title": "Mai-Otome Zwei", + "image": "https://monoschinos2.com/thumbs/imagen/mai-otome-zwei-1638649807.jpg?v=1" + }, + { + "id": "mai-hime-sub-espanol", + "title": "Mai-HiME", + "image": "https://monoschinos2.com/thumbs/imagen/mai-hime-1638591018.jpg?v=1" + }, + ... +] +``` + + +> PATH: /search/:id + +|Querys|Params| +|-|-| +|none|`id`| + +```js +[ + { + "id": "mai-otome-zwei-sub-espanol", + "title": "Mai-Otome Zwei", + "image": "https://monoschinos2.com/thumbs/imagen/mai-otome-zwei-1638649807.jpg?v=1" + }, + { + "id": "mai-hime-sub-espanol", + "title": "Mai-HiME", + "image": "https://monoschinos2.com/thumbs/imagen/mai-hime-1638591018.jpg?v=1" + }, + ... +] +``` + + + + +> PATH: /filterBy + +|Querys|Params| +|-|-| +|`pagina` , `categoria`, `fecha` ,`genero`, `letra`|none| + +```js +[ + { + "id": "mai-otome-zwei-sub-espanol", + "title": "Mai-Otome Zwei", + "image": "https://monoschinos2.com/thumbs/imagen/mai-otome-zwei-1638649807.jpg?v=1" + }, + { + "id": "mai-hime-sub-espanol", + "title": "Mai-HiME", + "image": "https://monoschinos2.com/thumbs/imagen/mai-hime-1638591018.jpg?v=1" + }, + ... +] +``` + + +> PATH: /ver/:id + +|Querys|Params| +|-|-| +|none|`id`| + +```js +{ + "title": "Kaifuku Jutsushi no Yarinaoshi. 2 ", + "nextEpisodes": [ + { + "image": "https://monoschinos2.com/assets/img/serie/episodio/kaifuku-jutsushi-no-yarinaoshi-3.png", + "date": "27 Ene 2021", + "title": "Kaifuku Jutsushi no Yarinaoshi", + "no": "Capitulo 3" + } + ], + "ctrs": { + "next": true, + "prev": true + }, + "sugestions": [ + { + "image": "https://monoschinos2.com/thumbs/portada/gundamhathawayvisual-e1621256405818.jpg?v=1.1", + "date": "08 Jul 2021", + "title": "Mobile Suit Gundam: Hathaway's Flash", + "no": "Capitulo 1" + }, + ... + ], + "videos": [ + { + "title": "cloud", + "url": "https://monoschinos2.com/reproductor?url=https://repro.monoschinos2.com/aqua/cl?url=redo02.mp4" + }, + ... + ], + "downloads": [ + { + "title": "1fichier ", + "url": "https://1fichier.com/?yssqgolputegizq4xkhb" + }, + ... + ] +} +``` + + + +> PATH: /anime/:id + +|Querys|Params| +|-|-| +|none|`id`| + +```js +{ + "banner": "https://monoschinos2.com/assets/img/serie/portada/portada_kimetsu-37.jpg", + "image": "https://monoschinos2.com/thumbs/imagen/crunchyroll-Demon-Slayer-Kimetsu-no-Yaiba-Mugen-Train-Arc.jpg?v=1", + "title": "Kimetsu no Yaiba: Mugen Ressha-hen (TV)", + "sinopsis": "Versión para televisión de la película Mugen Train que conecta el arco de Tanjiro Kamado, Resolve inquebrantable con el arco del distrito de entretenimiento , que presenta un episodio original de televisión nunca antes visto de Kyojuro Rengoku asumiendo una nueva misión en el camino hacia el tren Mugen.\nAdemás del episodio completamente nuevo, la serie también incluirá 70 escenas nuevas, nuevas pistas musicales, avances de episodios y nuevos temas musicales.\n", + "status": "Finalizado", + "date": 2021, + "rating": "4.8", + "genders": [ + "Acción", + "Aventura", + "Gore", + "Shonen", + "Histórico" + ], + "episodes": [ + { + "image": "https://monoschinos2.com/thumbs/portada/portada_kimetsu-37.jpg?v=1.1", + "no": 1, + "id": "kimetsu-no-yaiba-mugen-ressha-hen-tv-episodio-1" + }, + ... + ] +} +``` + + From e7d1bbaec10232d43719ce3333e3db0ed207eb69 Mon Sep 17 00:00:00 2001 From: carlos-burelo Date: Mon, 21 Mar 2022 17:10:46 -0600 Subject: [PATCH 14/19] :gear: update some project settings --- nodemon.json | 5 +++++ package.json | 4 ++-- yarn.lock | 5 +++++ 3 files changed, 12 insertions(+), 2 deletions(-) create mode 100644 nodemon.json diff --git a/nodemon.json b/nodemon.json new file mode 100644 index 0000000..b639a49 --- /dev/null +++ b/nodemon.json @@ -0,0 +1,5 @@ +{ + "ext": "ts", + "exec": "ts-node -r dotenv/config src/index.ts", + "ignore": ["node_modules/*"] +} diff --git a/package.json b/package.json index 7eb455c..b5c2920 100644 --- a/package.json +++ b/package.json @@ -5,13 +5,13 @@ "main": "index.js", "scripts": { "start": "node src/index.js", - "dev": "nodemon dotenv/config src/index.js" + "dev": "nodemon" }, - "type": "module", "keywords": [], "author": "", "license": "ISC", "devDependencies": { + "@types/cors": "^2.8.12", "@types/express": "^4.17.13", "@types/node": "^17.0.22", "morgan": "^1.10.0", diff --git a/yarn.lock b/yarn.lock index 551ee6d..c87a371 100644 --- a/yarn.lock +++ b/yarn.lock @@ -61,6 +61,11 @@ dependencies: "@types/node" "*" +"@types/cors@^2.8.12": + version "2.8.12" + resolved "https://registry.yarnpkg.com/@types/cors/-/cors-2.8.12.tgz#6b2c510a7ad7039e98e7b8d3d6598f4359e5c080" + integrity sha512-vt+kDhq/M2ayberEtJcIN/hxXy1Pk+59g2FV/ZQceeaTyCtCucjL2Q7FXlFjtWn4n15KCr1NE2lNNFhp0lEThw== + "@types/express-serve-static-core@^4.17.18": version "4.17.28" resolved "https://registry.yarnpkg.com/@types/express-serve-static-core/-/express-serve-static-core-4.17.28.tgz#c47def9f34ec81dc6328d0b1b5303d1ec98d86b8" From 09b117b7913f7c1bee2a2eb2072ca1caa3c8868f Mon Sep 17 00:00:00 2001 From: carlos-burelo Date: Mon, 21 Mar 2022 17:13:27 -0600 Subject: [PATCH 15/19] :wastebasket: removing morgan and cors, and moving dotenv to devDependencies --- package.json | 5 +---- yarn.lock | 48 +----------------------------------------------- 2 files changed, 2 insertions(+), 51 deletions(-) diff --git a/package.json b/package.json index b5c2920..53870f6 100644 --- a/package.json +++ b/package.json @@ -11,18 +11,15 @@ "author": "", "license": "ISC", "devDependencies": { - "@types/cors": "^2.8.12", "@types/express": "^4.17.13", "@types/node": "^17.0.22", - "morgan": "^1.10.0", "nodemon": "^2.0.14", "ts-node": "^10.7.0", + "dotenv": "^8.2.0", "typescript": "^4.6.2" }, "dependencies": { "axios": "^0.24.0", - "cors": "^2.8.5", - "dotenv": "^8.2.0", "express": "^4.17.1", "node-html-parser": "^5.1.0" } diff --git a/yarn.lock b/yarn.lock index c87a371..e379df1 100644 --- a/yarn.lock +++ b/yarn.lock @@ -61,11 +61,6 @@ dependencies: "@types/node" "*" -"@types/cors@^2.8.12": - version "2.8.12" - resolved "https://registry.yarnpkg.com/@types/cors/-/cors-2.8.12.tgz#6b2c510a7ad7039e98e7b8d3d6598f4359e5c080" - integrity sha512-vt+kDhq/M2ayberEtJcIN/hxXy1Pk+59g2FV/ZQceeaTyCtCucjL2Q7FXlFjtWn4n15KCr1NE2lNNFhp0lEThw== - "@types/express-serve-static-core@^4.17.18": version "4.17.28" resolved "https://registry.yarnpkg.com/@types/express-serve-static-core/-/express-serve-static-core-4.17.28.tgz#c47def9f34ec81dc6328d0b1b5303d1ec98d86b8" @@ -185,13 +180,6 @@ balanced-match@^1.0.0: resolved "https://registry.yarnpkg.com/balanced-match/-/balanced-match-1.0.2.tgz#e83e3a7e3f300b34cb9d87f615fa0cbf357690ee" integrity sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw== -basic-auth@~2.0.1: - version "2.0.1" - resolved "https://registry.yarnpkg.com/basic-auth/-/basic-auth-2.0.1.tgz#b998279bf47ce38344b4f3cf916d4679bbf51e3a" - integrity sha512-NF+epuEdnUYVlGuhaxbbq+dvJttwLnGY+YixlXlME5KpQ5W3CnXA5cVTneY3SPbPDRkcjMbifrwmFYcClgOZeg== - dependencies: - safe-buffer "5.1.2" - binary-extensions@^2.0.0: version "2.2.0" resolved "https://registry.yarnpkg.com/binary-extensions/-/binary-extensions-2.2.0.tgz#75f502eeaf9ffde42fc98829645be4ea76bd9e2d" @@ -361,14 +349,6 @@ cookie@0.4.0: resolved "https://registry.yarnpkg.com/cookie/-/cookie-0.4.0.tgz#beb437e7022b3b6d49019d088665303ebe9c14ba" integrity sha512-+Hp8fLp57wnUSt0tY0tHEXh4voZRDnoIrZPqlo3DPiI4y9lwg/jqx+1Om94/W6ZaPDOUbnjOt/99w66zk+l1Xg== -cors@^2.8.5: - version "2.8.5" - resolved "https://registry.yarnpkg.com/cors/-/cors-2.8.5.tgz#eac11da51592dd86b9f06f6e7ac293b3df875d29" - integrity sha512-KIHbLJqu73RGr/hnbrO9uBeixNGuvSQjul/jdFvS/KFSIH1hWVd1ng7zOHx+YrEfInLG7q4n6GHQ9cDtxv/P6g== - dependencies: - object-assign "^4" - vary "^1" - create-require@^1.1.0: version "1.1.1" resolved "https://registry.yarnpkg.com/create-require/-/create-require-1.1.1.tgz#c1d7e8f1e5f6cfc9ff65f9cd352d37348756c333" @@ -431,11 +411,6 @@ depd@~1.1.2: resolved "https://registry.yarnpkg.com/depd/-/depd-1.1.2.tgz#9bcd52e14c097763e749b274c4346ed2e560b5a9" integrity sha1-m81S4UwJd2PnSbJ0xDRu0uVgtak= -depd@~2.0.0: - version "2.0.0" - resolved "https://registry.yarnpkg.com/depd/-/depd-2.0.0.tgz#b696163cc757560d09cf22cc8fad1571b79e76df" - integrity sha512-g7nH6P6dyDioJogAAGprGpCtVImJhpPk/roCzdb3fIh61/s/nPsfR6onyMwkCAR/OlC3yBC0lESvUoQEAssIrw== - destroy@~1.0.4: version "1.0.4" resolved "https://registry.yarnpkg.com/destroy/-/destroy-1.0.4.tgz#978857442c44749e4206613e37946205826abd80" @@ -921,17 +896,6 @@ minimist@^1.2.0: resolved "https://registry.yarnpkg.com/minimist/-/minimist-1.2.5.tgz#67d66014b66a6a8aaa0c083c5fd58df4e4e97602" integrity sha512-FM9nNUYrRBAELZQT3xeZQ7fmMOBg6nWNmJKTcgsJeaLstP/UODVpGsr5OhXhhXg6f+qtJ8uiZ+PUxkDWcgIXLw== -morgan@^1.10.0: - version "1.10.0" - resolved "https://registry.yarnpkg.com/morgan/-/morgan-1.10.0.tgz#091778abc1fc47cd3509824653dae1faab6b17d7" - integrity sha512-AbegBVI4sh6El+1gNwvD5YIck7nSA36weD7xvIxG4in80j/UoK8AEGaWnnz8v1GxonMCltmlNs5ZKbGvl9b1XQ== - dependencies: - basic-auth "~2.0.1" - debug "2.6.9" - depd "~2.0.0" - on-finished "~2.3.0" - on-headers "~1.0.2" - ms@2.0.0: version "2.0.0" resolved "https://registry.yarnpkg.com/ms/-/ms-2.0.0.tgz#5608aeadfc00be6c2901df5f9861788de0d597c8" @@ -1000,11 +964,6 @@ nth-check@^2.0.0: dependencies: boolbase "^1.0.0" -object-assign@^4: - version "4.1.1" - resolved "https://registry.yarnpkg.com/object-assign/-/object-assign-4.1.1.tgz#2109adc7965887cfc05cbbd442cac8bfbb360863" - integrity sha1-IQmtx5ZYh8/AXLvUQsrIv7s2CGM= - on-finished@~2.3.0: version "2.3.0" resolved "https://registry.yarnpkg.com/on-finished/-/on-finished-2.3.0.tgz#20f1336481b083cd75337992a16971aa2d906947" @@ -1012,11 +971,6 @@ on-finished@~2.3.0: dependencies: ee-first "1.1.1" -on-headers@~1.0.2: - version "1.0.2" - resolved "https://registry.yarnpkg.com/on-headers/-/on-headers-1.0.2.tgz#772b0ae6aaa525c399e489adfad90c403eb3c28f" - integrity sha512-pZAE+FJLoyITytdqK0U5s+FIpjN0JP3OzFi/u8Rx+EV5/W+JTWGXG8xFzevE7AjBfDqHv/8vL8qQsIhHnqRkrA== - once@^1.3.1, once@^1.4.0: version "1.4.0" resolved "https://registry.yarnpkg.com/once/-/once-1.4.0.tgz#583b1aa775961d4b113ac17d9c50baef9dd76bd1" @@ -1382,7 +1336,7 @@ v8-compile-cache-lib@^3.0.0: resolved "https://registry.yarnpkg.com/v8-compile-cache-lib/-/v8-compile-cache-lib-3.0.0.tgz#0582bcb1c74f3a2ee46487ceecf372e46bce53e8" integrity sha512-mpSYqfsFvASnSn5qMiwrr4VKfumbPyONLCOPmsR3A6pTY/r0+tSaVbgPWSAIuzbk3lCTa+FForeTiO+wBQGkjA== -vary@^1, vary@~1.1.2: +vary@~1.1.2: version "1.1.2" resolved "https://registry.yarnpkg.com/vary/-/vary-1.1.2.tgz#2299f02c6ded30d4a5961b0b9f74524a18f634fc" integrity sha1-IpnwLG3tMNSllhsLn3RSShj2NPw= From 5e45b9409e2283709e3ae1286bf22792b7544ab5 Mon Sep 17 00:00:00 2001 From: carlos-burelo Date: Mon, 21 Mar 2022 17:14:31 -0600 Subject: [PATCH 16/19] :pencil2: added project description --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 53870f6..f0459fd 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "monoschinos-api-ts", "version": "2.0.0", - "description": "", + "description": "REST API written in Typescript and Node JS under the concept of Web Scraping, to extract data from the Monoschinos2.com page", "main": "index.js", "scripts": { "start": "node src/index.js", From afb2e2632ce21cf69a6de003bf3fc3ce11d52366 Mon Sep 17 00:00:00 2001 From: carlos-burelo Date: Mon, 21 Mar 2022 17:18:38 -0600 Subject: [PATCH 17/19] :toolbox: :checkered_flag: adding build command and update start command --- package.json | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index f0459fd..e6ed04c 100644 --- a/package.json +++ b/package.json @@ -4,8 +4,9 @@ "description": "REST API written in Typescript and Node JS under the concept of Web Scraping, to extract data from the Monoschinos2.com page", "main": "index.js", "scripts": { - "start": "node src/index.js", - "dev": "nodemon" + "start": "node dist/index.js", + "dev": "nodemon", + "build": "tsc" }, "keywords": [], "author": "", From 591ab524abfc0242be0197062b3e0d3d1d2ef1a9 Mon Sep 17 00:00:00 2001 From: carlos-burelo Date: Mon, 21 Mar 2022 17:21:43 -0600 Subject: [PATCH 18/19] :checkered_flag: update worker command --- Procfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Procfile b/Procfile index 52b25b1..5197153 100644 --- a/Procfile +++ b/Procfile @@ -1 +1 @@ -worker: node src/index.js \ No newline at end of file +worker: node dist/index.js \ No newline at end of file From fbfd99dced058cf73b7409fd2b473312d87b41cf Mon Sep 17 00:00:00 2001 From: carlos-burelo Date: Mon, 21 Mar 2022 18:51:57 -0600 Subject: [PATCH 19/19] :floppy_disk: implement cache storage in all paths --- src/api.ts | 8 +++++++- src/index.ts | 2 ++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/api.ts b/src/api.ts index 8540fde..5f18494 100644 --- a/src/api.ts +++ b/src/api.ts @@ -1,6 +1,6 @@ import axios from 'axios' +import { NextFunction, Request, Response } from 'express' import { parse } from 'node-html-parser' - import { API } from './types' export const headers = { @@ -34,4 +34,10 @@ export function attr( ) { return html.querySelector(selector)?.attributes[attribute as any] as unknown as string } +export const cache = (req: Request, res: Response, next: NextFunction) => { + const period = 60 * 5 + res.set('Cache-control', `public, max-age=${period}`) + next() +} + export { parse } diff --git a/src/index.ts b/src/index.ts index 430caec..3f0a9d0 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,8 +1,10 @@ import express from 'express' import routes from './router' +import { cache } from './api' const app = express() +app.use(cache) app.use('/', routes) const port = process.env.PORT || 5000