mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-06-05 21:59:27 +02:00
Use default avatar if imported image is corrupted
This commit is contained in:
@ -74,12 +74,17 @@ async function writeCharacterData(inputFile, data, outputFile, request, crop = u
|
|||||||
* Read the image, resize, and save it as a PNG into the buffer.
|
* Read the image, resize, and save it as a PNG into the buffer.
|
||||||
* @returns {Promise<Buffer>} Image buffer
|
* @returns {Promise<Buffer>} Image buffer
|
||||||
*/
|
*/
|
||||||
function getInputImage() {
|
async function getInputImage() {
|
||||||
if (Buffer.isBuffer(inputFile)) {
|
try {
|
||||||
return parseImageBuffer(inputFile, crop);
|
if (Buffer.isBuffer(inputFile)) {
|
||||||
}
|
return await parseImageBuffer(inputFile, crop);
|
||||||
|
}
|
||||||
|
|
||||||
return tryReadImage(inputFile, crop);
|
return await tryReadImage(inputFile, crop);
|
||||||
|
} catch (error) {
|
||||||
|
console.log(`Failed to read image: ${inputFile}. Using a fallback image.`);
|
||||||
|
return await fs.promises.readFile(defaultAvatarPath);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const inputImage = await getInputImage();
|
const inputImage = await getInputImage();
|
||||||
|
Reference in New Issue
Block a user