Use default avatar if imported image is corrupted

65e32f720d2c341a70c0826a57a67d57a6d9b77c

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

1 files changed, +10 -5Ignore whitespace
src/endpoints/characters.js+10 -5
@@ -74,12 +74,17 @@ async function writeCharacterData(inputFile, data, outputFile, request, crop = u
74 * Read the image, resize, and save it as a PNG into the buffer.74 * Read the image, resize, and save it as a PNG into the buffer.
75 * @returns {Promise<Buffer>} Image buffer75 * @returns {Promise<Buffer>} Image buffer
76 */76 */
77 function getInputImage() {77 async function getInputImage() {
78 if (Buffer.isBuffer(inputFile)) {78 try {
79 return parseImageBuffer(inputFile, crop);79 if (Buffer.isBuffer(inputFile)) {
80 }80 return await parseImageBuffer(inputFile, crop);
81 }
8182
82 return tryReadImage(inputFile, crop);83 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 }
83 }88 }
8489
85 const inputImage = await getInputImage();90 const inputImage = await getInputImage();