Replace Comfy avatar placeholders with empty pixel if message fails to load

This commit is contained in:
Cohee 2024-04-21 21:13:50 +03:00
parent e832af9854
commit d5c0aed973
1 changed files with 6 additions and 0 deletions

View File

@ -37,6 +37,8 @@ const p = a => `<p>${a}</p>`;
const MODULE_NAME = 'sd';
const UPDATE_INTERVAL = 1000;
// This is a 1x1 transparent PNG
const PNG_PIXEL = 'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNkYAAAAAYAAjCB0C8AAAAASUVORK5CYII=';
const sources = {
extras: 'extras',
@ -2650,6 +2652,8 @@ async function generateComfyImage(prompt, negativePrompt) {
const avatarBlob = await response.blob();
const avatarBase64 = await getBase64Async(avatarBlob);
workflow = workflow.replace('"%user_avatar%"', JSON.stringify(avatarBase64));
} else {
workflow = workflow.replace('"%user_avatar%"', JSON.stringify(PNG_PIXEL));
}
}
if (/%char_avatar%/gi.test(workflow)) {
@ -2658,6 +2662,8 @@ async function generateComfyImage(prompt, negativePrompt) {
const avatarBlob = await response.blob();
const avatarBase64 = await getBase64Async(avatarBlob);
workflow = workflow.replace('"%char_avatar%"', JSON.stringify(avatarBase64));
} else {
workflow = workflow.replace('"%char_avatar%"', JSON.stringify(PNG_PIXEL));
}
}
console.log(`{