Skip to content

Commit cf290de

Browse files
fix: correct size validation and default values for image formats
1 parent bcf25ad commit cf290de

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

src/handler/avatar.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,33 +30,33 @@ export function avatarHandler(app: FastifyInstance, core: Core, style: any) {
3030
}
3131

3232
// Validate Size for JPEG Format
33-
if (request.params.format === 'jpg') {
33+
if (request.params.format === 'jpg' || request.params.format === 'jpeg') {
3434
options['size'] = options['size']
3535
? Math.min(
3636
Math.max(options['size'], config.jpeg.size.min),
3737
config.jpeg.size.max
3838
)
39-
: config.png.size.default;
39+
: config.jpeg.size.default;
4040
}
4141

4242
// Validate Size for WebP Format
4343
if (request.params.format === 'webp') {
4444
options['size'] = options['size']
4545
? Math.min(
4646
Math.max(options['size'], config.webp.size.min),
47-
config.jpeg.size.max
47+
config.webp.size.max
4848
)
49-
: config.png.size.default;
49+
: config.webp.size.default;
5050
}
5151

5252
// Validate Size for Avif Format
5353
if (request.params.format === 'avif') {
5454
options['size'] = options['size']
5555
? Math.min(
5656
Math.max(options['size'], config.avif.size.min),
57-
config.jpeg.size.max
57+
config.avif.size.max
5858
)
59-
: config.png.size.default;
59+
: config.avif.size.default;
6060
}
6161

6262
// Define default seed
@@ -105,7 +105,7 @@ export function avatarHandler(app: FastifyInstance, core: Core, style: any) {
105105
reply.header('Content-Type', 'image/webp');
106106

107107
const webp = await toWebp(avatar.toString(), {
108-
includeExif: config.png.exif,
108+
includeExif: config.webp.exif,
109109
fonts: getRequiredFonts(avatar.toString(), app.fonts),
110110
}).toArrayBuffer();
111111

@@ -115,7 +115,7 @@ export function avatarHandler(app: FastifyInstance, core: Core, style: any) {
115115
reply.header('Content-Type', 'image/avif');
116116

117117
const avif = await toAvif(avatar.toString(), {
118-
includeExif: config.png.exif,
118+
includeExif: config.avif.exif,
119119
fonts: getRequiredFonts(avatar.toString(), app.fonts),
120120
}).toArrayBuffer();
121121

0 commit comments

Comments
 (0)