Verify if passed a jimp instance to applyAvatarCropResize
| @@ -50,6 +50,7 @@ router.post('/upload', getFileNameValidationFunction('overwrite_name'), async (r | ||
| 50 | 50 | fs.unlinkSync(pathToUpload); |
| 51 | 51 | return response.send({ path: filename }); |
| 52 | 52 | } catch (err) { |
| 53 | + console.error('Error uploading user avatar:', err); | |
| 53 | 54 | return response.status(400).send('Is not a valid image'); |
| 54 | 55 | } |
| 55 | 56 | }); |
| @@ -277,7 +277,11 @@ async function writeCharacterData(inputFile, data, outputFile, request, crop = u | ||
| 277 | 277 | * @returns {Promise<Buffer>} Processed image buffer |
| 278 | 278 | */ |
| 279 | 279 | export async function applyAvatarCropResize(jimp, crop) { |
| 280 | - const image = /** @type {InstanceType<typeof import('../jimp.js').Jimp>} */ (jimp); | |
| 280 | + if (!(jimp instanceof Jimp)) { | |
| 281 | + throw new TypeError('Expected a Jimp instance'); | |
| 282 | + } | |
| 283 | + | |
| 284 | + const image = /** @type {InstanceType<typeof Jimp>} */ (jimp); | |
| 281 | 285 | let finalWidth = image.bitmap.width, finalHeight = image.bitmap.height; |
| 282 | 286 | |
| 283 | 287 | // Apply crop if defined |