From 97e908bb080672e962f19aea2d9ceac3bf3e568c Mon Sep 17 00:00:00 2001 From: sinkaroid Date: Sat, 4 Jun 2022 09:59:54 +0700 Subject: [PATCH] feat(scraper): append cover value on nhentai object --- src/scraper/nhentai/nhentaiSearchController.ts | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/scraper/nhentai/nhentaiSearchController.ts b/src/scraper/nhentai/nhentaiSearchController.ts index 10dda79..b1ebfc7 100644 --- a/src/scraper/nhentai/nhentaiSearchController.ts +++ b/src/scraper/nhentai/nhentaiSearchController.ts @@ -8,6 +8,12 @@ export async function scrapeContent(url: string) { const rawData: any = res.body; const content = []; + const GALLERY = "https://i.nhentai.net/galleries"; + const TYPE: any = { + j: "jpg", + p: "png", + g: "gif", + }; for (let i = 0; i < rawData.result.length; i++) { const time = new Date(rawData.result[i].upload_date * 1000); const objectData = { @@ -16,6 +22,7 @@ export async function scrapeContent(url: string) { language: rawData.result[i].tags.find((tag: any) => tag.type === "language") ? rawData.result[i].tags.find((tag: any) => tag.type === "language").name : null, upload_date: `${getDate(time)} (${timeAgo(time)})`, total: rawData.result[i].num_pages, + cover: `${GALLERY}/${rawData.result[i].media_id}/1.${TYPE[rawData.result[i].images.cover.t]}`, tags: rawData.result[i].tags.map((tag: any) => tag.name), };