added image feed deduplication based on src metadata

This commit is contained in:
cho
2024-03-10 00:55:53 -08:00
parent b4a9cebf24
commit e147bbab3a
+16
View File
@@ -208,6 +208,7 @@ app.registerExtension({
name: "pysssss.ImageFeed",
setup() {
let visible = true;
const seenImages = new Map();
const showButton = $el("button.comfy-settings-btn", {
textContent: "🖼️",
style: {
@@ -309,6 +310,13 @@ app.registerExtension({
},
});
const deduplicateFeed = app.ui.settings.addSetting({
id: "pysssss.ImageFeed.Deduplication",
name: "🐍 Image Feed Deduplication",
defaultValue: false,
type: "boolean"
});
const clearButton = $el("button.pysssss-image-feed-btn.clear-btn", {
textContent: "Clear",
onclick: () => imageList.replaceChildren(),
@@ -416,6 +424,14 @@ app.registerExtension({
}
for (const src of detail.output.images) {
if (deduplicateFeed.value) {
// deduplicate the feed by ignoring images with the same filename/type/subfolder
const fingerprint = JSON.stringify({filename: src.filename, type: src.type, subfolder: src.subfolder});
if (seenImages.has(fingerprint))
continue;
seenImages.set(fingerprint, true);
}
const href = `./view?filename=${encodeURIComponent(src.filename)}&type=${
src.type
}&subfolder=${encodeURIComponent(src.subfolder)}&t=${+new Date()}`;