Use default avatar if imported image is corrupted

65e32f720d2c341a70c0826a57a67d57a6d9b77c

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

1 files changed, +8 -3Showing whitespace changes
src/endpoints/characters.js+8 -3
@@ -74,12 +74,17 @@ async function writeCharacterData(inputFile, data, outputFile, request, crop = u
7474 * Read the image, resize, and save it as a PNG into the buffer.
7575 * @returns {Promise<Buffer>} Image buffer
7676 */
7777 async function getInputImage() {
78+ try {
7879 if (Buffer.isBuffer(inputFile)) {
7980 return await parseImageBuffer(inputFile, crop);
8081 }
8182
8283 return await tryReadImage(inputFile, crop);
84+ } catch (error) {
85+ console.log(`Failed to read image: ${inputFile}. Using a fallback image.`);
86+ return await fs.promises.readFile(defaultAvatarPath);
87+ }
8388 }
8489
8590 const inputImage = await getInputImage();