Verify if passed a jimp instance to applyAvatarCropResize

f8d7a3e853ac0d3ee92fa603a3bff80e797b5152

Cohee <18619528+Cohee1207@users.noreply.github.com>

2 files changed, +6 -1Showing whitespace changes
src/endpoints/avatars.js+1 -0
@@ -50,6 +50,7 @@ router.post('/upload', getFileNameValidationFunction('overwrite_name'), async (r
5050 fs.unlinkSync(pathToUpload);
5151 return response.send({ path: filename });
5252 } catch (err) {
53+ console.error('Error uploading user avatar:', err);
5354 return response.status(400).send('Is not a valid image');
5455 }
5556});
src/endpoints/characters.js+5 -1
@@ -277,7 +277,11 @@ async function writeCharacterData(inputFile, data, outputFile, request, crop = u
277277 * @returns {Promise<Buffer>} Processed image buffer
278278 */
279279export 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);
281285 let finalWidth = image.bitmap.width, finalHeight = image.bitmap.height;
282286
283287 // Apply crop if defined