diff --git a/src/modules/webtoon/image/image.controller.ts b/src/modules/webtoon/image/image.controller.ts index 148f04a..1c89b0b 100644 --- a/src/modules/webtoon/image/image.controller.ts +++ b/src/modules/webtoon/image/image.controller.ts @@ -1,4 +1,4 @@ -import {BadRequestException, Controller, Get, Header, Param, Req, Res} from "@nestjs/common"; +import {BadRequestException, Controller, Get, Header, Param} from "@nestjs/common"; import {ApiResponse, ApiTags} from "@nestjs/swagger"; import {WebtoonDatabaseService} from "../webtoon/webtoon-database.service"; import {HttpStatusCode} from "axios"; diff --git a/src/modules/webtoon/webtoon/models/responses/random-thumbnail.response.ts b/src/modules/webtoon/webtoon/models/responses/random-thumbnail.response.ts new file mode 100644 index 0000000..ac6f4e5 --- /dev/null +++ b/src/modules/webtoon/webtoon/models/responses/random-thumbnail.response.ts @@ -0,0 +1,12 @@ +import {ApiProperty} from "@nestjs/swagger"; + +export default class RandomThumbnailResponse{ + @ApiProperty() + thumbnail: string; + + constructor( + thumbnail: string, + ){ + this.thumbnail = thumbnail; + } +} diff --git a/src/modules/webtoon/webtoon/webtoon-database.service.ts b/src/modules/webtoon/webtoon/webtoon-database.service.ts index 50ea718..6425d59 100644 --- a/src/modules/webtoon/webtoon/webtoon-database.service.ts +++ b/src/modules/webtoon/webtoon/webtoon-database.service.ts @@ -579,17 +579,17 @@ export class WebtoonDatabaseService{ fs.rmSync(`./images/${folder}/${imageSum}.webp`); } - async getRandomThumbnails() { + async getRandomThumbnails(){ const webtoons: any[] = await this.prismaService.webtoons.findMany({ include: { thumbnail: true } }); if(!webtoons.length) - throw new NotFoundException(`No thumbnails found in database.`); + throw new NotFoundException("No thumbnails found in database."); const randomWebtoon: any = webtoons[Math.floor(Math.random() * webtoons.length)]; return { thumbnail: randomWebtoon.thumbnail.sum - } + }; } } diff --git a/src/modules/webtoon/webtoon/webtoon-downloader.service.ts b/src/modules/webtoon/webtoon/webtoon-downloader.service.ts index 0d8c0aa..001c3fa 100644 --- a/src/modules/webtoon/webtoon/webtoon-downloader.service.ts +++ b/src/modules/webtoon/webtoon/webtoon-downloader.service.ts @@ -4,7 +4,6 @@ import WebtoonDataModel from "./models/models/webtoon-data.model"; import WebtoonModel from "./models/models/webtoon.model"; import {Injectable, Logger} from "@nestjs/common"; import {MiscService} from "../../misc/misc.service"; -import * as sharp from "sharp"; @Injectable() export class WebtoonDownloaderService{ diff --git a/src/modules/webtoon/webtoon/webtoon.controller.ts b/src/modules/webtoon/webtoon/webtoon.controller.ts index 16204f0..541fa92 100644 --- a/src/modules/webtoon/webtoon/webtoon.controller.ts +++ b/src/modules/webtoon/webtoon/webtoon.controller.ts @@ -12,6 +12,7 @@ import {ChunkNumberDto} from "../../../common/models/dto/chunk-number.dto"; import ImagesChunkResponse from "./models/responses/images-chunk.response"; import EpisodeLineModel from "./models/models/episode-line.model"; import {HttpStatusCode} from "axios"; +import RandomThumbnailResponse from "./models/responses/random-thumbnail.response"; @Controller("webtoons") @ApiTags("Webtoon") @@ -85,9 +86,9 @@ export class WebtoonController{ } @Get("thumbnails/random") - @ApiResponse({status: HttpStatusCode.Ok, description: "Returns a list of random thumbnails"}) + @ApiResponse({status: HttpStatusCode.Ok, description: "Returns a random webtoon thumbnail sum", type: RandomThumbnailResponse}) @ApiResponse({status: HttpStatusCode.NotFound, description: "No thumbnails found"}) - async getRandomThumbnails(): Promise{ + async getRandomThumbnails(): Promise{ return this.webtoonDatabaseService.getRandomThumbnails(); } }