Merge pull request #3361 from SillyTavern/write-fallback-img Use default avatar if imported image is corrupted

6d43eea1bd0d3470d41bcb97bbe21fb7d0338136

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

Signed
1 files changed, +9 -3Showing whitespace changes
src/endpoints/characters.js+9 -3
@@ -74,12 +74,18 @@ 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 try {
78 if (Buffer.isBuffer(inputFile)) {79 if (Buffer.isBuffer(inputFile)) {
79 return parseImageBuffer(inputFile, crop);80 return await parseImageBuffer(inputFile, crop);
80 }81 }
8182
82 return tryReadImage(inputFile, crop);83 return await tryReadImage(inputFile, crop);
84 } catch (error) {
85 const message = Buffer.isBuffer(inputFile) ? 'Failed to read image buffer.' : `Failed to read image: ${inputFile}.`;
86 console.warn(message, 'Using a fallback image.', error);
87 return await fs.promises.readFile(defaultAvatarPath);
88 }
83 }89 }
8490
85 const inputImage = await getInputImage();91 const inputImage = await getInputImage();