diff --git a/src/modules/misc/misc.service.ts b/src/modules/misc/misc.service.ts index d276134..c3f439a 100644 --- a/src/modules/misc/misc.service.ts +++ b/src/modules/misc/misc.service.ts @@ -97,7 +97,7 @@ export class MiscService{ return response.data as Buffer; } - async convertThumbnail(url: string){ + async convertWebtoonThumbnail(url: string){ const webpImage: Buffer = await this.downloadImage(url); return await sharp(webpImage).resize(240, 240, { fit: "cover", diff --git a/src/modules/webtoon/update/update.controller.ts b/src/modules/webtoon/update/update.controller.ts index 87439dc..e59fe3d 100644 --- a/src/modules/webtoon/update/update.controller.ts +++ b/src/modules/webtoon/update/update.controller.ts @@ -1,7 +1,8 @@ import {Controller, Logger, Post, UseGuards} from "@nestjs/common"; import {UpdateService} from "./update.service"; -import {ApiBearerAuth, ApiTags} from "@nestjs/swagger"; +import {ApiBearerAuth, ApiResponse, ApiTags} from "@nestjs/swagger"; import {AdminGuard} from "../admin/guard/admin.guard"; +import {HttpStatusCode} from "axios"; @Controller("update") @@ -17,6 +18,7 @@ export class UpdateController{ @Post("webtoons/thumbnails") @ApiBearerAuth() + @ApiResponse({status: HttpStatusCode.Created, description: "Thumbnails updated"}) async updateThumbnails(): Promise{ this.updateService.updateThumbnails().then(() => this.logger.log("Thumbnails updated")); } diff --git a/src/modules/webtoon/update/update.service.ts b/src/modules/webtoon/update/update.service.ts index f2c6cce..49df9da 100644 --- a/src/modules/webtoon/update/update.service.ts +++ b/src/modules/webtoon/update/update.service.ts @@ -45,7 +45,7 @@ export class UpdateService{ for(const webtoon of dbWebtoons){ this.logger.debug(`Updating thumbnail for webtoon ${webtoon.title} (${webtoon.language})`); const cachedWebtoon: CachedWebtoonModel = this.webtoonParser.findWebtoon(webtoon.title, webtoon.language); - const thumbnail: Buffer = await this.miscService.convertThumbnail(cachedWebtoon.thumbnail); + const thumbnail: Buffer = await this.miscService.convertWebtoonThumbnail(cachedWebtoon.thumbnail); const sum: string = this.webtoonDatabaseService.saveImage(thumbnail); // Check if thumbnail already exists let dbThumbnail = await tx.images.findFirst({ diff --git a/src/modules/webtoon/webtoon/webtoon-downloader.service.ts b/src/modules/webtoon/webtoon/webtoon-downloader.service.ts index 445b164..0d8c0aa 100644 --- a/src/modules/webtoon/webtoon/webtoon-downloader.service.ts +++ b/src/modules/webtoon/webtoon/webtoon-downloader.service.ts @@ -50,7 +50,7 @@ export class WebtoonDownloaderService{ async downloadWebtoon(webtoon: WebtoonModel): Promise{ const downloadPromises: Promise[] = []; - downloadPromises.push(this.miscService.convertThumbnail(webtoon.thumbnail)); + downloadPromises.push(this.miscService.convertWebtoonThumbnail(webtoon.thumbnail)); downloadPromises.push(this.miscService.downloadImage(webtoon.banner.background)); downloadPromises.push(this.miscService.downloadImage(webtoon.banner.top)); downloadPromises.push(this.miscService.downloadImage(webtoon.banner.mobile)); diff --git a/src/modules/webtoon/webtoon/webtoon-parser.service.ts b/src/modules/webtoon/webtoon/webtoon-parser.service.ts index 933db7c..88713cb 100644 --- a/src/modules/webtoon/webtoon/webtoon-parser.service.ts +++ b/src/modules/webtoon/webtoon/webtoon-parser.service.ts @@ -51,24 +51,17 @@ export class WebtoonParserService{ private async getWebtoonsFromLanguage(language: string): Promise{ const languageWebtoons: CachedWebtoonModel[] = []; - const promises: Promise[] = []; for (const genre of Object.values(WebtoonGenres)) promises.push(this.getWebtoonsFromGenre(language, genre)); const genreResults = await Promise.all(promises); for (const webtoons of genreResults) languageWebtoons.push(...webtoons); - - // for (const genre of Object.values(WebtoonGenres)) - // languageWebtoons.push(...await this.getWebtoonsFromGenre(language, genre)); - return this.removeDuplicateWebtoons(languageWebtoons); } private async getWebtoonsFromGenre(language: string, genre: string): Promise{ - // console.log(language, genre); const mobileThumbnails = await this.getWebtoonThumbnailFromGenre(language, genre); - // console.log(mobileThumbnails); const url = `https://www.webtoons.com/${language}/genres/${genre}`; const response = await this.miscService.getAxiosInstance().get(url); const document = new JSDOM(response.data).window.document; @@ -108,7 +101,6 @@ export class WebtoonParserService{ private async getWebtoonThumbnailFromGenre(language: string, genre: string): Promise[]>{ const mobileThumbnails: Record[] = []; const mobileUrl = `https://www.webtoons.com/${language}/genres/${genre}`.replace("www.webtoons", "m.webtoons") + "?webtoon-platform-redirect=true"; - // console.log(mobileUrl); const mobileResponse = await this.miscService.getAxiosInstance().get(mobileUrl, { headers: { "User-Agent": "Mozilla/5.0 (iPhone; CPU iPhone OS 15_0 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148" @@ -117,7 +109,6 @@ export class WebtoonParserService{ const mobileDocument = new JSDOM((mobileResponse).data).window.document; const className = `genre_${genre.toUpperCase()}_list`; const wList = mobileDocument.querySelector(`ul.${className}`)?.querySelectorAll("li"); - // console.log("wList", wList); if(!wList) return []; for(const li of wList){ const webtoonName = li.querySelector("a")?.querySelector("div.info")?.querySelector("p.subj span")?.textContent;