Verify if passed a jimp instance to applyAvatarCropResize

f8d7a3e853ac0d3ee92fa603a3bff80e797b5152

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

2 files changed, +6 -1Ignore whitespace
src/endpoints/avatars.js+1 -0
@@ -50,6 +50,7 @@ router.post('/upload', getFileNameValidationFunction('overwrite_name'), async (r
50 fs.unlinkSync(pathToUpload);50 fs.unlinkSync(pathToUpload);
51 return response.send({ path: filename });51 return response.send({ path: filename });
52 } catch (err) {52 } catch (err) {
53 console.error('Error uploading user avatar:', err);
53 return response.status(400).send('Is not a valid image');54 return response.status(400).send('Is not a valid image');
54 }55 }
55});56});
src/endpoints/characters.js+5 -1
@@ -277,7 +277,11 @@ async function writeCharacterData(inputFile, data, outputFile, request, crop = u
277 * @returns {Promise<Buffer>} Processed image buffer277 * @returns {Promise<Buffer>} Processed image buffer
278 */278 */
279export async function applyAvatarCropResize(jimp, crop) {279export 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 let finalWidth = image.bitmap.width, finalHeight = image.bitmap.height;285 let finalWidth = image.bitmap.width, finalHeight = image.bitmap.height;
282286
283 // Apply crop if defined287 // Apply crop if defined