Merge pull request #1746 from Makosful/release

Iterate over textChunks to find character data
This commit is contained in:
Cohee 2024-01-26 01:22:09 +02:00 committed by GitHub
commit 5185752662
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 8 additions and 1 deletions

View File

@ -18,11 +18,18 @@ const parse = async (cardUrl, format) => {
});
if (textChunks.length === 0) {
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[0].text, 'base64').toString('utf8');
return Buffer.from(textChunks[index].text, 'base64').toString('utf8');
}
default:
break;