Handle edge case when no chara chunk

This commit is contained in:
Cohee 2024-01-26 01:14:12 +02:00
parent 84a21fba27
commit 19c3b3016c

View File

@ -18,12 +18,17 @@ const parse = async (cardUrl, format) => {
});
if (textChunks.length === 0) {
console.error('PNG metadata does not contain any character data.');
console.error('PNG metadata does not contain any text chunks.');
throw new Error('No PNG metadata.');
}
let index = textChunks.findIndex((chunk) => chunk.keyword.toLowerCase() == 'chara');
if (index === -1) {
console.error('PNG metadata does not contain any character data.');
throw new Error('No PNG metadata.');
}
return Buffer.from(textChunks[index].text, 'base64').toString('utf8');
}
default: