Skip to content

Commit

Permalink
feat: fix outdated data & types improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
sinkaroid committed Aug 11, 2022
1 parent 2e5bb5b commit d527da4
Show file tree
Hide file tree
Showing 23 changed files with 150 additions and 109 deletions.
11 changes: 7 additions & 4 deletions src/controller/asmhentai/asmhentaiGet.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
import { scrapeContent } from "../../scraper/asmhentai/asmhentaiGetController";
import c from "../../utils/options";
import { logger } from "../../utils/logger";
import { isNumeric } from "../../utils/modifier";
import { Request, Response, NextFunction } from "express";

export async function getAsmhentai(req: any, res: any, next: any) {
export async function getAsmhentai(req: Request, res: Response, next: NextFunction) {
try {
const book = req.query.book || "";
const book = req.query.book as string;
if (!book) throw Error("Parameter book is required");
if (isNaN(book)) throw Error("Value must be number");
const url = `${c.ASMHENTAI}/g/${book}`;
if (!isNumeric(book)) throw Error("Value must be number");

const url = `${c.ASMHENTAI}/g/${book}/`;
const data = await scrapeContent(url);
logger.info({
path: req.path,
Expand Down
5 changes: 3 additions & 2 deletions src/controller/asmhentai/asmhentaiRandom.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { scrapeContent } from "../../scraper/asmhentai/asmhentaiGetController";
import c from "../../utils/options";
import { logger } from "../../utils/logger";
import { Request, Response, NextFunction } from "express";

export async function randomAsmhentai(req: any, res: any, next: any) {
export async function randomAsmhentai(req: Request, res: Response, next: NextFunction) {
try {
const url = `${c.ASMHENTAI}/random`;
const url = `${c.ASMHENTAI}/random/`;
const data = await scrapeContent(url);
logger.info({
path: req.path,
Expand Down
4 changes: 2 additions & 2 deletions src/controller/asmhentai/asmhentaiSearch.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { scrapeContent } from "../../scraper/asmhentai/asmhentaiSearchController";
import c from "../../utils/options";
import { logger } from "../../utils/logger";
import { Request, Response, NextFunction } from "express";


export async function searchAsmhentai(req: any, res: any, next: any) {
export async function searchAsmhentai(req: Request, res: Response, next: NextFunction) {
try {
const key = req.query.key || "";
const page = req.query.page || 1;
Expand Down
6 changes: 4 additions & 2 deletions src/controller/hentai2read/hentai2readGet.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import { scrapeContent } from "../../scraper/hentai2read/hentai2readGetController";
import c from "../../utils/options";
import { logger } from "../../utils/logger";
import { Request, Response } from "express";

export async function getHentai2read(req: any, res: any) {
export async function getHentai2read(req: Request, res: Response) {
try {
const book = req.query.book || "";
const book = req.query.book as string;
if (!book) throw Error("Parameter book is required");
if (book.split("/").length !== 2) throw Error("Book must be in format 'book_example/chapter'. Example: 'fate_lewd_summoning/1'");

const url = `${c.HENTAI2READ}/${book}/`;
const data = await scrapeContent(url);
logger.info({
Expand Down
4 changes: 3 additions & 1 deletion src/controller/hentai2read/hentai2readSearch.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import { scrapeContent } from "../../scraper/hentai2read/hentai2readSearchController";
import c from "../../utils/options";
import { logger } from "../../utils/logger";
import { Request, Response, NextFunction } from "express";

export async function searchHentai2read(req: any, res: any, next: any) {
export async function searchHentai2read(req: Request, res: Response, next: NextFunction) {
try {
const key = req.query.key || "";
if (!key) throw Error("Parameter book is required");

const url = `${c.HENTAI2READ}/hentai-list/search/${key}`;
const data = await scrapeContent(url);
logger.info({
Expand Down
9 changes: 6 additions & 3 deletions src/controller/hentaifox/hentaifoxGet.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
import { scrapeContent } from "../../scraper/hentaifox/hentaifoxGetController";
import c from "../../utils/options";
import { logger } from "../../utils/logger";
import { isNumeric } from "../../utils/modifier";
import { Request, Response, NextFunction } from "express";

export async function getHentaifox(req: any, res: any, next: any) {
export async function getHentaifox(req: Request, res: Response, next: NextFunction) {
try {
const book = req.query.book || "";
const book = req.query.book as string;
if (!book) throw Error("Parameter book is required");
if (isNaN(book)) throw Error("Value must be number");
if (!isNumeric(book)) throw Error("Parameter book must be number");

const url = `${c.HENTAIFOX}/gallery/${book}/`;
const data = await scrapeContent(url);
logger.info({
Expand Down
3 changes: 2 additions & 1 deletion src/controller/hentaifox/hentaifoxRandom.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { Request, Response, NextFunction } from "express";
import { scrapeContent } from "../../scraper/hentaifox/hentaifoxGetController";
import c from "../../utils/options";
import { logger } from "../../utils/logger";

export async function randomHentaifox(req: any, res: any, next: any) {
export async function randomHentaifox(req: Request, res: Response, next: NextFunction) {
try {
const url = `${c.HENTAIFOX}/random`;
const data = await scrapeContent(url);
Expand Down
9 changes: 5 additions & 4 deletions src/controller/hentaifox/hentaifoxSearch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@ import { scrapeContent } from "../../scraper/hentaifox/hentaifoxSearchController
import c from "../../utils/options";
import { logger } from "../../utils/logger";
const sorting = ["latest", "popular"];
import { Request, Response, NextFunction } from "express";

export async function searchHentaifox(req: any, res:any, next: any) {
export async function searchHentaifox(req: Request, res: Response, next: NextFunction) {
try {
const key = req.query.key || "";
const key = req.query.key as string;
const page = req.query.page || 1;
const sort = req.query.sort || sorting[0];
const sort = req.query.sort as string || sorting[0] as string;
if (!key) throw Error("Parameter key is required");
if (!sorting.includes(sort)) throw Error("Invalid short: " + sorting.join(", "));
if (!sorting.includes(sort)) throw Error("Invalid sort: " + sorting.join(", "));
const url = `${c.HENTAIFOX}/search/?q=${key}&sort=${sort}&page=${page}`;
const data = await scrapeContent(url);
logger.info({
Expand Down
10 changes: 5 additions & 5 deletions src/controller/nhentai/nhentaiGet.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
import { scrapeContent } from "../../scraper/nhentai/nhentaiGetController";
import c from "../../utils/options";
import { logger } from "../../utils/logger";
import { mock } from "../../utils/modifier";
import { mock, isNumeric } from "../../utils/modifier";
import { Request, Response } from "express";

export async function getNhentai(req: any, res: any) {
export async function getNhentai(req: Request, res: Response) {
try {
const book = req.query.book || "";
const book = req.query.book as string;
if (!book) throw Error("Parameter book is required");
if (isNaN(book)) throw Error("Value must be number");
if (!isNumeric(book)) throw Error("Parameter book must be number");

let actualAPI;
if (!await mock(c.NHENTAI)) actualAPI = c.NHENTAI_IP;
else actualAPI = c.NHENTAI;

const url = `${actualAPI}/api/gallery/${book}`;
console.log(url);
const data = await scrapeContent(url);
logger.info({
path: req.path,
Expand Down
3 changes: 2 additions & 1 deletion src/controller/nhentai/nhentaiRandom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ import c from "../../utils/options";
import { logger } from "../../utils/logger";
import { mock } from "../../utils/modifier";
import { getIdRandomNhentai } from "../../utils/modifier";
import { Request, Response, NextFunction } from "express";

export async function randomNhentai(req: any, res: any, next: any) {
export async function randomNhentai(req: Request, res: Response, next: NextFunction) {
try {
let actualAPI;
if (!await mock(c.NHENTAI)) actualAPI = c.NHENTAI_IP;
Expand Down
9 changes: 5 additions & 4 deletions src/controller/nhentai/nhentaiRelated.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import { scrapeContent } from "../../scraper/nhentai/nhentaiRelatedController";
import c from "../../utils/options";
import { logger } from "../../utils/logger";
import { mock } from "../../utils/modifier";
import { mock, isNumeric } from "../../utils/modifier";
import { Request, Response } from "express";

export async function relatedNhentai(req: any, res: any) {
export async function relatedNhentai(req: Request, res: Response) {
try {
const book = req.query.book || "";
const book = req.query.book as string;
if (!book) throw Error("Parameter book is required");
if (isNaN(book)) throw Error("Value must be number");
if (!isNumeric(book)) throw Error("Value must be number");

let actualAPI;
if (!await mock(c.NHENTAI)) actualAPI = c.NHENTAI_IP;
Expand Down
7 changes: 4 additions & 3 deletions src/controller/nhentai/nhentaiSearch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@ import c from "../../utils/options";
import { logger } from "../../utils/logger";
import { mock } from "../../utils/modifier";
const sorting = ["popular-today", "popular-week", "popular"];
import { Request, Response } from "express";

export async function searchNhentai(req: any, res: any) {
export async function searchNhentai(req: Request, res: Response) {
try {
const key = req.query.key || "";
const page = req.query.page || 1;
const sort = req.query.sort || sorting[0];
const sort = req.query.sort as string || sorting[0] as string;
if (!key) throw Error("Parameter key is required");
if (!sorting.includes(sort)) throw Error("Invalid short: " + sorting.join(", "));
if (!sorting.includes(sort)) throw Error("Invalid sort: " + sorting.join(", "));

let actualAPI;
if (!await mock(c.NHENTAI)) actualAPI = c.NHENTAI_IP;
Expand Down
9 changes: 6 additions & 3 deletions src/controller/pururin/pururinGet.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
import { scrapeContent } from "../../scraper/pururin/pururinGetController";
import c from "../../utils/options";
import { logger } from "../../utils/logger";
import { isNumeric } from "../../utils/modifier";
import { Request, Response, NextFunction } from "express";

export async function getPururin(req: any, res: any, next: any) {
export async function getPururin(req: Request, res: Response, next: NextFunction) {
try {
const book = req.query.book || "";
const book = req.query.book as string;
if (!book) throw Error("Parameter book is required");
if (isNaN(book)) throw Error("Value must be number");
if (!isNumeric(book)) throw Error("Parameter book must be number");

const url = `${c.PURURIN}/gallery/${book}/janda`;
const data = await scrapeContent(url);
logger.info({
Expand Down
3 changes: 2 additions & 1 deletion src/controller/pururin/pururinRandom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ import { scrapeContent } from "../../scraper/pururin/pururinGetController";
import c from "../../utils/options";
import { logger } from "../../utils/logger";
import { getIdRandomPururin } from "../../utils/modifier";
import { Request, Response, NextFunction } from "express";

export async function randomPururin(req: any, res: any, next: any) {
export async function randomPururin(req: Request, res: Response, next: NextFunction) {
try {
const id = await getIdRandomPururin();
const url = `${c.PURURIN}/gallery/${id}/janda`;
Expand Down
10 changes: 6 additions & 4 deletions src/controller/pururin/pururinSearch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,16 @@ import { scrapeContent } from "../../scraper/pururin/pururinSearchController";
import c from "../../utils/options";
import { logger } from "../../utils/logger";
const sorting = ["newest", "most-popular", "highest-rated", "most-viewed", "title", "random"];
import { Request, Response, NextFunction } from "express";

export async function searchPururin(req: any, res: any, next: any) {
export async function searchPururin(req: Request, res: Response, next: NextFunction) {
try {
const key = req.query.key || "";
const key = req.query.key as string;
const page = req.query.page || 1;
const sort = req.query.sort || sorting[0];
const sort = req.query.sort as string || sorting[0] as string;
if (!key) throw Error("Parameter key is required");
if (!sorting.includes(sort)) throw Error("Invalid short: " + sorting.join(", "));
if (!sorting.includes(sort)) throw Error("Invalid sort: " + sorting.join(", "));

const url = `${c.PURURIN}/search/${sort}?q=${key}&page=${page}`;
const data = await scrapeContent(url);
logger.info({
Expand Down
7 changes: 4 additions & 3 deletions src/controller/simply-hentai/simply-hentaiGet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ import { scrapeContent } from "../../scraper/simply-hentai/simply-hentaiGetContr
import c from "../../utils/options";
import { logger } from "../../utils/logger";
import { mock } from "../../utils/modifier";
import { Request, Response } from "express";

export async function getSimplyhentai(req: any, res: any) {
export async function getSimplyhentai(req: Request, res: Response) {
try {
const book = req.query.book || "";
if (!book) throw Error("Parameter book is required");
const book = req.query.book as string;
if (!book) throw Error("Parameter book is required, Example: idolmaster/from-fumika-fc8496c/all-pages");

let actualAPI;
if (!await mock(c.SIMPLY_HENTAI)) actualAPI = c.SIMPLY_HENTAI_PROXIFIED;
Expand Down
2 changes: 1 addition & 1 deletion src/scraper/asmhentai/asmhentaiGetController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export async function scrapeContent(url: string) {

const title: string = $("h1").text();
const id: number = parseInt($("link[rel='canonical']")?.attr("href")?.split("/")[4] || "0");
const tags: string[] = $("span.badge.tag").map((i, el) => $(el).text()).get();
const tags: string[] = $("span.badge.tag")?.map((i, el) => $(el).text()).get();
const tagsClean: string[] = tags.map((tag: string) => tag.replace(/[0-9]|[.,()]/g, "").trim());
const total: number = parseInt($("input[id='t_pages']")?.attr("value") || "0");
const img: string = $("img[data-src]")?.attr("data-src") || "";
Expand Down
13 changes: 3 additions & 10 deletions src/scraper/asmhentai/asmhentaiSearchController.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { load } from "cheerio";
import p from "phin";
import { removeNonNumeric } from "../../utils/modifier";

interface IAsmHentaiSearch {
title: string;
id: number;
language: string;
}

export async function scrapeContent(url: string) {
Expand All @@ -22,13 +22,7 @@ export async function scrapeContent(url: string) {
//get all href inside <div class="image">, get only number
const id = $("div.image").map((i, el) => {
const href = $(el).find("a");
return href.attr("href")?.split("/")[4];
}).get();

//get all href inside <div class="cl">
const lang = $("div.cl").map((i, el) => {
const a = $(el).find("a");
return a.attr("href")?.split("/")[4];
return href.attr("href");
}).get();


Expand All @@ -37,8 +31,7 @@ export async function scrapeContent(url: string) {

const objectData: IAsmHentaiSearch = {
title: abc.split("\n")[0],
id: parseInt(id[title.indexOf(abc)]),
language: lang[title.indexOf(abc)],
id: parseInt(removeNonNumeric(id[title.indexOf(abc)])),

};
content.push(objectData);
Expand Down
2 changes: 1 addition & 1 deletion src/scraper/hentai2read/hentai2readGetController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export async function scrapeContent(url: string) {
const gData = script.find(el => el.includes("var gData"));
const gDataClean: string = gData?.replace(/[\s\S]*var gData = /, "").replace(/;/g, "").replace(/'/g, "\"") || "";
const gDataJson = JSON.parse(gDataClean);
const images = gDataJson.images.map((el: any) => `https://cdn-ngocok-static.sinxdr.workers.dev/hentai${el}`);
const images = gDataJson.images.map((el: string) => `https://cdn-ngocok-static.sinxdr.workers.dev/hentai${el}`);

const objectData: IHentai2readGet = {
title: gDataJson.title,
Expand Down
Loading

0 comments on commit d527da4

Please sign in to comment.