diff --git a/src/art/genAI/imageDB.js b/src/art/genAI/imageDB.js index 3c6e5973d0dae5433136fe4bb7bf3313da803027..612ee621154f157f05ba6380749e1e1fa058d624 100644 --- a/src/art/genAI/imageDB.js +++ b/src/art/genAI/imageDB.js @@ -68,7 +68,15 @@ App.Art.GenAI.imageDB = (function() { const request = objectStore.get(id); request.onsuccess = function() { - resolve(request.result); + if (request.result === undefined) { + reject(new Error(`Image with ID ${id} not found in the database.`)); + } else { + resolve(request.result); + } + }; + + request.onerror = function() { + reject(new Error(`Error fetching image with ID ${id}`)); }; }); } diff --git a/src/art/genAI/stableDiffusion.js b/src/art/genAI/stableDiffusion.js index 17f21fd98dca6dd79ed64e68c9f4ef9b5e423c49..70a48f888c22f692561c0273b5608fed47488e03 100644 --- a/src/art/genAI/stableDiffusion.js +++ b/src/art/genAI/stableDiffusion.js @@ -271,10 +271,14 @@ App.Art.GenAI.StableDiffusionClient = class { * @returns {Promise<number>} index of the image in aiImageIds or -1 */ async function compareExistingImages(slave, newImageData) { - const aiImages = await Promise.all(slave.custom.aiImageIds.map(id => { - return App.Art.GenAI.imageDB.getImage(id); - })); - return aiImages.findIndex(img => img.data === newImageData); + const aiImages = await Promise.all( + slave.custom.aiImageIds.map(id => + App.Art.GenAI.imageDB.getImage(id) + .catch(() => null) // Return null if the image is not found or there's an error + ) + ); + + return aiImages.findIndex(img => img && img.data === newImageData); } /**