Skip to content

Commit

Permalink
fix(api): strong typing and error catch for image compression
Browse files Browse the repository at this point in the history
  • Loading branch information
finxol committed Jul 26, 2023
1 parent ee537b3 commit e7574fa
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion api/util/image.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,15 @@ interface DecodedImage {
* @returns The compressed image.
*/
export async function compress(image: Buffer): Promise<Buffer> {
return await sharp(image)
let compressed: Buffer | void = await sharp(image)
.resize(600, 600, { fit: 'inside' })
.toBuffer()
.catch(err => {
logger.error('Error while compressing image', err)
})
if (!compressed)
throw new Error('Error while compressing image')
return compressed as Buffer
}


Expand Down

0 comments on commit e7574fa

Please sign in to comment.