@@ -19,6 +19,7 @@ import { ConfigService } from "@nestjs/config";
19
19
import { UploadedImageDto , UploadedImagePageDto } from "./storage.dto" ;
20
20
import { StorageMapper } from "./storage.mapper" ;
21
21
import { calculateHashForBuffer } from "../../utils/hashbuffer" ;
22
+ import { StorageService } from "./storage.service" ;
22
23
23
24
interface IFile {
24
25
fieldname : string ;
@@ -37,6 +38,7 @@ export class StorageController {
37
38
@InjectS3 ( ) private readonly s3 : S3 ,
38
39
private readonly config : ConfigService ,
39
40
private readonly mapper : StorageMapper ,
41
+ private readonly storageService : StorageService ,
40
42
) { }
41
43
42
44
@ApiBody ( {
@@ -56,17 +58,19 @@ export class StorageController {
56
58
@UseInterceptors ( FileInterceptor ( "file" ) )
57
59
@Post ( "upload" )
58
60
public async uploadImage (
61
+ // @Query ("width", NullableIntPipe) width: number,
59
62
@UploadedFile ( ) file : IFile ,
60
63
) : Promise < UploadedImageDto > {
61
64
const hash = await calculateHashForBuffer ( file . buffer ) ;
62
- const extension = file . originalname . split ( "." ) . pop ( ) ;
63
65
64
- const Key = this . config . get ( "s3.uploadPrefix" ) + `${ hash } .${ extension } ` ;
66
+ const newBody = await this . storageService . prepareImage ( file . buffer ) ;
67
+
68
+ const Key = this . config . get ( "s3.uploadPrefix" ) + `${ hash } .webp` ;
65
69
66
70
const putObjectCommandInput : PutObjectCommandInput = {
67
71
Bucket : this . config . get ( "s3.bucket" ) ,
68
72
Key,
69
- Body : file . buffer ,
73
+ Body : newBody ,
70
74
ContentType : file . mimetype ,
71
75
ACL : "public-read" ,
72
76
0 commit comments