Skip to content

Commit

Permalink
✨ Add route for image recovery from sum
Browse files Browse the repository at this point in the history
  • Loading branch information
Xen0Xys committed Jun 8, 2024
1 parent e3edb2d commit 55802c1
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {APP_GUARD} from "@nestjs/core";
import {MigrationModule} from "./modules/webtoon/migration/migration.module";
import {ScheduleModule} from "@nestjs/schedule";
import {UpdateModule} from "./modules/webtoon/update/update.module";
import {ImageModule} from "./modules/webtoon/image/image.module";

@Module({
imports: [
Expand All @@ -22,6 +23,7 @@ import {UpdateModule} from "./modules/webtoon/update/update.module";
AdminModule,
MigrationModule,
UpdateModule,
ImageModule,
],
controllers: [],
providers: [
Expand Down
23 changes: 23 additions & 0 deletions src/modules/webtoon/image/image.controller.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import {Controller, Get, Header, Param} from "@nestjs/common";
import {ApiResponse, ApiTags} from "@nestjs/swagger";
import {WebtoonDatabaseService} from "../webtoon/webtoon-database.service";
import {HttpStatusCode} from "axios";
import {ImageSumDto} from "./models/dto/image-sum.dto";


@Controller("image")
@ApiTags("Image")
export class ImageController{

constructor(
private readonly webtoonDatabaseService: WebtoonDatabaseService,
){}

@Get(":sum")
@Header("Content-Type", "image/webp")
@ApiResponse({status: HttpStatusCode.Ok, description: "Get image"})
@ApiResponse({status: HttpStatusCode.NotFound, description: "Not found"})
getImage(@Param() imageSumDto: ImageSumDto){
return this.webtoonDatabaseService.loadImage(imageSumDto.sum);
}
}
10 changes: 10 additions & 0 deletions src/modules/webtoon/image/image.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import {Module} from "@nestjs/common";
import {ImageController} from "./image.controller";
import {WebtoonModule} from "../webtoon/webtoon.module";


@Module({
controllers: [ImageController],
imports: [WebtoonModule],
})
export class ImageModule{}
9 changes: 9 additions & 0 deletions src/modules/webtoon/image/models/dto/image-sum.dto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import {ApiProperty} from "@nestjs/swagger";
import {IsNotEmpty, IsString} from "class-validator";

export class ImageSumDto{
@ApiProperty()
@IsNotEmpty()
@IsString()
sum: string;
}
2 changes: 1 addition & 1 deletion src/modules/webtoon/webtoon/webtoon-database.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,7 @@ export class WebtoonDatabaseService{
return imageSum;
}

private loadImage(imageSum: string): Buffer{
loadImage(imageSum: string): Buffer{
const folder = imageSum.substring(0, 2);
return fs.readFileSync(`./images/${folder}/${imageSum}.webp`);

Check failure

Code scanning / CodeQL

Uncontrolled data used in path expression High

This path depends on a
user-provided value
.
}
Expand Down

0 comments on commit 55802c1

Please sign in to comment.