Merge pull request #4610 from awsr/gallery-folder-updates

Simplify gallery folder updating
pull/4612/head
Vladimir Mandic 2026-01-31 08:08:35 +01:00 committed by GitHub
commit 504e0cbbdd
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 4 additions and 16 deletions

View File

@ -1195,26 +1195,17 @@ async function fetchFilesWS(evt) { // fetch file-by-file list over websockets
ws.send(encodeURI(evt.target.name));
}
async function pruneImages() {
// TODO replace img.src with placeholder for images that are not visible
}
async function galleryVisible() {
async function updateFolders() {
// if (el.folders.children.length > 0) return;
const res = await authFetch(`${window.api}/browser/folders`);
if (!res || res.status !== 200) return;
el.folders.innerHTML = '';
url = res.url.split('/sdapi')[0].replace('http', 'ws'); // update global url as ws need fqdn
const folders = await res.json();
el.folders.innerHTML = '';
for (const folder of folders) {
const f = new GalleryFolder(folder);
el.folders.appendChild(f);
}
pruneImagesTimer = setInterval(pruneImages, 1000);
}
async function galleryHidden() {
if (pruneImagesTimer) clearInterval(pruneImagesTimer);
}
async function monitorGalleries() {
@ -1297,12 +1288,9 @@ async function initGallery() { // triggered on gradio change to monitor when ui
el.btnSend = gradioApp().getElementById('tab-gallery-send-image');
document.getElementById('tab-gallery-files').style.height = opts.logmonitor_show ? '75vh' : '85vh';
const intersectionObserver = new IntersectionObserver((entries) => {
if (entries[0].intersectionRatio <= 0) galleryHidden();
if (entries[0].intersectionRatio > 0) galleryVisible();
});
intersectionObserver.observe(el.folders);
monitorGalleries();
updateFolders();
monitorOption('browser_folders', updateFolders);
}
// register on startup