Skip to content

Commit

Permalink
🎨 Improve code quality
Browse files Browse the repository at this point in the history
  • Loading branch information
Xen0Xys committed Jun 17, 2024
1 parent 6e95038 commit 9ade209
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/modules/webtoon/image/image.controller.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import {ApiProperty} from "@nestjs/swagger";

export default class RandomThumbnailResponse{
@ApiProperty()
thumbnail: string;

constructor(
thumbnail: string,
){
this.thumbnail = thumbnail;
}
}
6 changes: 3 additions & 3 deletions src/modules/webtoon/webtoon/webtoon-database.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
};
}
}
1 change: 0 additions & 1 deletion src/modules/webtoon/webtoon/webtoon-downloader.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down
5 changes: 3 additions & 2 deletions src/modules/webtoon/webtoon/webtoon.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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<any>{
async getRandomThumbnails(): Promise<RandomThumbnailResponse>{
return this.webtoonDatabaseService.getRandomThumbnails();
}
}

0 comments on commit 9ade209

Please sign in to comment.