Fix for show all images

This commit is contained in:
Haka 2022-09-28 00:05:34 +03:00
parent c1dea44fa6
commit 10c4bee1e5

View File

@ -255,13 +255,13 @@ function showImages(req, res, livePreview) {
res.output.forEach((result, index) => { res.output.forEach((result, index) => {
if(typeof res != 'object') return; if(typeof res != 'object') return;
const imageData = result?.data || result?.path, const imageData = result?.data || result?.path + '?t=' + new Date().getTime(),
imageSeed = req.seed + index, imageSeed = req.seed,
imageWidth = req.width, imageWidth = req.width,
imageHeight = req.height, imageHeight = req.height,
imageIdentifier = 'IMG_' + (imageSeed + '').replace(/\d/g, c => 'SUOMIPERKL'[c]); imageIdentifier = 'IMG_ID_' + (imageSeed + '').replace(/\d/g, c => 'SUOMIPERKL'[c]) + 'X'.repeat(index);
if (!imageData) { if (!imageData.includes('/')) {
// res contained no data for the image, stop execution // res contained no data for the image, stop execution
setStatus('request', 'invalid image', 'error'); setStatus('request', 'invalid image', 'error');
@ -285,12 +285,14 @@ function showImages(req, res, livePreview) {
</div> </div>
`; `;
const useAsInputBtn = imageItemElem.querySelector('.imgUseBtn'); const useAsInputBtn = imageItemElem.querySelector('.imgUseBtn'),
const saveImageBtn = imageItemElem.querySelector('.imgSaveBtn'); saveImageBtn = imageItemElem.querySelector('.imgSaveBtn');
useAsInputBtn.addEventListener('click', e => {
const imgData = e.path.find(x => x == imageItemElem).querySelector('img').src;
useAsInputBtn.addEventListener('click', () => {
initImageSelector.value = null; initImageSelector.value = null;
initImagePreview.src = imageData; initImagePreview.src = imgData;
initImagePreviewContainer.style.display = 'block'; initImagePreviewContainer.style.display = 'block';
inpaintingEditorContainer.style.display = 'none'; inpaintingEditorContainer.style.display = 'none';
@ -303,23 +305,23 @@ function showImages(req, res, livePreview) {
seedField.value = imageSeed; seedField.value = imageSeed;
seedField.disabled = false; seedField.disabled = false;
}); });
saveImageBtn.addEventListener('click', () => { saveImageBtn.addEventListener('click', e => {
const imgData = e.path.find(x => x == imageItemElem).querySelector('img').src;
const imgDownload = document.createElement('a'); const imgDownload = document.createElement('a');
imgDownload.download = createFileName(imageSeed); imgDownload.download = createFileName(imageSeed);
imgDownload.href = imageData; imgDownload.href = imgData;
imgDownload.click(); imgDownload.click();
}); });
imagesContainer.appendChild(imageItemElem); imagesContainer.appendChild(imageItemElem);
} }
const imageElem = imageItemElem.querySelector('img'); const imageElem = imageItemElem.querySelector('img'),
const imageSeedLabel = imageItemElem.querySelector('.imgSeedLabel'); imageSeedLabel = imageItemElem.querySelector('.imgSeedLabel');
imageElem.src = livePreview imageElem.src = imageData;
? imageData + '?t=' + new Date().getTime()
: imageData;
imageElem.width = parseInt(imageWidth); imageElem.width = parseInt(imageWidth);
imageElem.height = parseInt(imageHeight); imageElem.height = parseInt(imageHeight);