Compare commits

...
1 Commits
Author SHA1 Message Date
ketle-manandClaude Sonnet 4.6 2b84c69ef9 feat: group stale-entry auto-cleanup + Gallery Shift+click range select (v0.3.45)
- Models tab: scan valid model files on group load, remove stale entries;
  move_models() also updates group membership for moved models
- Gallery tab (folder view): cleanup stale metadata entries after each
  folder scan, synced with 60s TTL + folder-mtime cache
- Gallery tab (group list): list_images_in_group() filters non-existent
  paths and removes them from the group in a single write
- Gallery tab: Shift+click range-selects from the last anchor item;
  works in both thumbnail and table views; anchor resets on folder
  change, reload, and Deselect All; help updated (EN/JA/ZH)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-21 17:16:45 +09:00
7 changed files with 197 additions and 10 deletions
+47
View File
@@ -1,5 +1,52 @@
# DEVLOG - ComfyUI-Workflow-Studio
## 2026-06-21: v0.3.45 — グループ孤立エントリ自動クリーンアップ・Galleryタブ Shift+クリック範囲選択
**変更ファイル**: `py/services/models_service.py`, `py/services/gallery_service.py`, `py/services/gallery_metadata.py`, `static/js/gallery-tab.js`, `static/js/i18n.js`
### グループ孤立エントリ自動クリーンアップ
ファイルをアプリ外(OS)で移動・削除した際にグループデータに残る孤立エントリを自動的に除去する仕組みを追加。
#### Modelsタブ
- `models_service.py` に `_scan_model_names(model_type)` を追加 — `_get_model_dirs` の全ディレクトリを `rglob` で走査し、有効なモデルファイル名のセットを返す(`.disabled` サフィックスを除いた相対パス)
- `get_model_groups(model_type)` に自動クリーンアップを追加 — タイプ指定時にファイルスキャンを実行し、存在しないモデル名をグループから除去;変更があった場合のみ保存
- `move_models()` でグループエントリを即時更新 — アプリ内での移動時に `renames` リストを収集し、`_groups[model_type]` 内の旧パスを新パスに一括書き換え
#### Galleryタブ(フォルダ表示)
- `gallery_metadata.py` に `cleanup_stale_images(folder_path, existing_paths)` を追加 — `folder_path` 配下のメタデータキーのうち `existing_paths` に含まれないものを削除して保存
- `gallery_service.py` の `list_images()` で `_scan_folder` 直後にクリーンアップを呼ぶ — スキャン結果の `abs_path` セットを渡すため、60秒 TTL キャッシュとフォルダ mtime 変化検知に連動して自動実行
#### Galleryタブ(グループ画像一覧)
- `gallery_metadata.py` に `remove_stale_paths_from_group(group_name, stale_paths)` を追加 — 孤立パスをグループから一括削除し1回の保存で完結
- `gallery_service.py` の `list_images_in_group()` で `Path.is_file()` チェックを追加 — FeederタブのGalleryモード(`GET /wfm/gallery/groups/{name}/images`)呼び出し時に孤立パスをグループから自動除去して既存ファイルのみ返す
#### 各タブのクリーンアップトリガー
| タブ | トリガー | 対象 |
|---|---|---|
| Modelsタブ | タブ切替・モデルタイプ変更時 | 全グループから存在しないモデル名を削除 |
| Modelsタブ(アプリ内移動) | `move_models` API 呼び出し時 | グループ内パスを即時更新 |
| Galleryタブ(フォルダUI) | フォルダ表示時(mtime 変化 or 60秒後) | フォルダ内の孤立メタデータエントリを削除 |
| Galleryタブ(Feederモード) | グループ画像一覧取得時 | グループから孤立パスを削除 |
### GalleryタブのShift+クリック範囲選択
- `state` に `lastSelectionIndex: -1` を追加(Shift 選択のアンカーインデックス)
- `createThumbCard()` / `createTable()` に `data-path` 属性を追加
- `_applySelectionToDOM()` ヘルパーを追加 — `state.selectedImages` を元に描画済み要素の `multi-selected` クラスを一括同期;ページング未描画の要素はスクロールで描画される際に `createThumbCard` が自動で反映
- サムネイルビュー・テーブルビューのクリックハンドラを更新:
- Shift+クリック: アンカーから現在位置まで `state.images` のインデックス範囲で一括追加
- Ctrl+クリック: 個別トグル(既存)+アンカー更新
- 通常クリック: 詳細表示(既存)+アンカー更新
- `lastSelectionIndex` リセット箇所: フォルダ切替時・`loadImages()` 完了時(ソート/フィルタ変更後も含む)・一括解除ボタン押下時
- `i18n.js` の `helpGallery6`(EN/JA/ZH)を更新して Shift+クリック範囲選択を追記
---
## 2026-06-21: v0.3.44 — Galleryタブ高速化・比較モード・バルク強化・バルクバーUI整理
**変更ファイル**: `py/services/gallery_service.py`, `py/routes/gallery_routes.py`, `static/js/gallery-tab.js`, `static/css/gallery-tab.css`, `templates/index.html`, `static/js/app.js`, `static/js/i18n.js`
+7 -1
View File
@@ -18,7 +18,7 @@ A comprehensive workflow, asset management, and generation UI plugin for [ComfyU
- Built-in AI tools (translation and more)
![Workflow Studio](https://img.shields.io/badge/ComfyUI-Custom_Node-blue)
![Version](https://img.shields.io/badge/version-0.3.44-green)
![Version](https://img.shields.io/badge/version-0.3.45-green)
## Screenshots
@@ -333,6 +333,12 @@ Click the **camera icon** (next to the W button) in ComfyUI's top bar to capture
## Changelog
### v0.3.45
- **Group auto-cleanup — Models tab** — stale group entries (models that no longer exist on disk) are automatically removed when the Models tab is loaded or the model type is switched; models moved within the app via "Move To..." also update their group membership immediately
- **Group auto-cleanup — Gallery tab (folder view)** — metadata entries for missing files are cleaned up each time a folder is scanned (`list_images`), synchronized with the 60s TTL + folder-mtime cache
- **Group auto-cleanup — Gallery tab (group image list)** — `list_images_in_group` (used by the Feeder tab Gallery mode) now filters out non-existent paths and removes them from the group in a single write operation
- **Gallery tab — Shift+click range selection** — Shift+click selects all images between the last clicked item (anchor) and the current item; works in both thumbnail and table views; anchor is updated on Ctrl+click and regular click; resets on folder change, image reload, and Deselect All; help text updated (EN/JA/ZH)
### v0.3.44
- **Gallery tab — server-side thumbnail generation** — `GET /wfm/gallery/image/thumb?path=...&w=256` endpoint generates 256px JPEG thumbnails via Pillow and caches them to `data/thumb_cache/` keyed by `md5(path:mtime:width)`; GIF served as-is to preserve animation; falls back to the original file if Pillow is unavailable; thumbnail view and table view both switched from `/image/serve` to `/image/thumb`
- **Gallery tab — infinite-scroll paging** — thumbnail view renders 50 images initially; an IntersectionObserver sentinel (rootMargin 300px) appends the next page on scroll; sentinel is disconnected and removed when all images are rendered; paging resets on every `renderImages()` call (folder change, filter, sort)
+31
View File
@@ -117,6 +117,18 @@ class GalleryMetadataStore:
result.append(key)
return result
def remove_stale_paths_from_group(self, group_name: str, stale_paths: list) -> int:
"""存在しないパスをグループから一括削除する(1回の保存で完結)"""
stale_set = {self._normalize_path(p) for p in stale_paths}
count = 0
for key, meta in self._data["images"].items():
if key in stale_set and group_name in meta.get("groups", []):
meta["groups"] = [g for g in meta["groups"] if g != group_name]
count += 1
if count:
self._save_to_disk()
return count
def get_group_member_set(self, group_name: str) -> set:
"""グループメンバーのパスをsetで返す(高速フィルタ用)"""
return {
@@ -153,3 +165,22 @@ class GalleryMetadataStore:
self._data["images"][new_key] = self._data["images"].pop(old_key)
return self._save_to_disk()
return True
def cleanup_stale_images(self, folder_path: str, existing_paths: set) -> int:
"""folder_path 配下の存在しないファイルのメタデータを削除する。
existing_paths: そのフォルダの現在のファイルパス集合(_normalize_path 済み)
"""
folder_key = self._normalize_path(folder_path)
if not folder_key.endswith("/"):
folder_key += "/"
stale = [
key for key in self._data["images"]
if key.startswith(folder_key) and key not in existing_paths
]
if not stale:
return 0
for key in stale:
del self._data["images"][key]
self._save_to_disk()
logger.info("Cleaned up %d stale metadata entries from %s", len(stale), folder_path)
return len(stale)
+11 -1
View File
@@ -188,6 +188,10 @@ class GalleryService:
# os.scandir() でファイル情報を一括取得(stat()の個別呼び出しを排除)
raw_entries = self._scan_folder(folder)
# 孤立メタデータを自動クリーンアップ(移動・削除されたファイルの残骸を除去)
existing_paths = {abs_path for _, abs_path, _, _ in raw_entries}
self.metadata_store.cleanup_stale_images(str(folder), existing_paths)
results = []
for name, abs_path, size, mtime in raw_entries:
# グループフィルタ(サーバーサイド)
@@ -464,7 +468,13 @@ class GalleryService:
return self.metadata_store.save(image_path, {"groups": groups})
def list_images_in_group(self, group_name: str) -> list[str]:
return self.metadata_store.list_images_in_group(group_name)
all_paths = self.metadata_store.list_images_in_group(group_name)
existing = [p for p in all_paths if Path(p).is_file()]
stale = [p for p in all_paths if not Path(p).is_file()]
if stale:
self.metadata_store.remove_stale_paths_from_group(group_name, stale)
logger.info("Cleaned up %d stale paths from group '%s'", len(stale), group_name)
return existing
def clear_group(self, group_name: str) -> bool:
return self.metadata_store.clear_group(group_name)
+54 -1
View File
@@ -110,6 +110,25 @@ class ModelsService:
self._save_metadata(data)
return entry
def _scan_model_names(self, model_type: str) -> set:
"""モデルタイプの全ファイル名をスキャンして返す(相対パス、/区切り、.disabled除く)"""
dirs = _get_model_dirs(model_type)
names = set()
for d in dirs:
if not d.is_dir():
continue
for f in d.rglob("*"):
if not f.is_file():
continue
try:
rel = str(f.relative_to(d)).replace("\\", "/")
if rel.endswith(_DISABLED_SUFFIX):
rel = rel[: -len(_DISABLED_SUFFIX)]
names.add(rel)
except ValueError:
pass
return names
def get_model_groups(self, model_type=None):
data = self._load_metadata()
raw = data.get("_groups", {})
@@ -123,7 +142,23 @@ class ModelsService:
raw = {}
if model_type:
return raw.get(model_type, {})
groups = raw.get(model_type, {})
valid_names = self._scan_model_names(model_type)
cleaned = {}
dirty = False
for g_name, members in groups.items():
filtered = [m for m in members if m in valid_names]
cleaned[g_name] = filtered
if len(filtered) != len(members):
dirty = True
if dirty:
removed = sum(len(groups[g]) - len(cleaned[g]) for g in groups)
logger.info("Cleaned up %d stale group entries for model_type=%s", removed, model_type)
if not isinstance(data.get("_groups"), dict):
data["_groups"] = {}
data["_groups"][model_type] = cleaned
self._save_metadata(data)
return cleaned
return raw
def save_model_groups(self, groups, model_type):
@@ -311,6 +346,7 @@ class ModelsService:
meta_data = self._load_metadata()
meta_changed = False
renames = [] # [(old_name, new_name)]
for model_name in model_names:
if ".." in model_name:
@@ -389,11 +425,28 @@ class ModelsService:
meta_changed = True
moved.append({"from": model_name, "to": new_rel})
renames.append((model_name, new_rel))
except Exception as e:
logger.error("Error moving model %s: %s", model_name, e)
errors.append({"model": model_name, "error": str(e)})
# Update group entries for renamed/moved models
if renames:
groups_for_type = meta_data.get("_groups", {}).get(model_type, {})
groups_dirty = False
for old_name, new_name in renames:
for members in groups_for_type.values():
for i, m in enumerate(members):
if m == old_name:
members[i] = new_name
groups_dirty = True
if groups_dirty:
if not isinstance(meta_data.get("_groups"), dict):
meta_data["_groups"] = {}
meta_data["_groups"][model_type] = groups_for_type
meta_changed = True
if meta_changed:
self._save_metadata(meta_data)
+44 -4
View File
@@ -61,6 +61,7 @@ const state = {
groups: [],
embeddedWorkflow: null, // 選択画像のworkflow JSON
selectedImages: new Set(), // 複数選択中のパス Set
lastSelectionIndex: -1, // Shift選択のアンカーインデックス
folderTree: null, // フォルダツリー全体(移動先選択に使用)
};
@@ -204,6 +205,7 @@ function renderTreeNode(node, container, depth, isRoot) {
item.classList.add("selected");
state.currentFolder = absPath;
state.selectedImages.clear();
state.lastSelectionIndex = -1;
updateBulkBar();
loadImages();
// Delete Folder ボタン: rootは削除不可
@@ -265,6 +267,7 @@ async function loadImages() {
try {
const images = (await apiFetch(API.images(params))).images || [];
state.images = images;
state.lastSelectionIndex = -1;
document.getElementById("wfm-gallery-count").textContent = `${state.images.length} images`;
renderImages();
updateTagFilter(state.images);
@@ -339,6 +342,7 @@ function createThumbCard(img) {
const card = document.createElement("div");
card.className = "wfm-gallery-thumb-card";
card.title = img.filename;
card.dataset.path = img.path;
if (state.selectedImages.has(img.path)) {
card.classList.add("multi-selected");
}
@@ -384,14 +388,24 @@ function createThumbCard(img) {
});
card.appendChild(feederBtn);
// クリック: 詳細表示 / Ctrl+クリック: 複数選択 / Alt+クリック: Metadataタブで開く
// クリック: 詳細表示 / Ctrl+クリック: 複数選択 / Shift+クリック: 範囲選択 / Alt+クリック: Metadataタブで開く
card.addEventListener("click", (e) => {
if (e.altKey) {
e.preventDefault();
openImageInMetadataTab(img);
return;
}
if (e.ctrlKey || e.metaKey) {
const idx = state.images.findIndex(i => i.path === img.path);
if (e.shiftKey && state.lastSelectionIndex !== -1) {
// 範囲選択: アンカーから現在位置まで一括追加
const from = Math.min(state.lastSelectionIndex, idx);
const to = Math.max(state.lastSelectionIndex, idx);
for (let i = from; i <= to; i++) {
state.selectedImages.add(state.images[i].path);
}
_applySelectionToDOM();
updateBulkBar();
} else if (e.ctrlKey || e.metaKey) {
// 複数選択トグル
if (state.selectedImages.has(img.path)) {
state.selectedImages.delete(img.path);
@@ -400,10 +414,12 @@ function createThumbCard(img) {
state.selectedImages.add(img.path);
card.classList.add("multi-selected");
}
state.lastSelectionIndex = idx;
updateBulkBar();
} else {
// 通常選択: 詳細表示
state.selectedImage = img;
state.lastSelectionIndex = idx;
document.querySelectorAll(".wfm-gallery-thumb-card.selected").forEach(el => el.classList.remove("selected"));
card.classList.add("selected");
loadImageDetail(img);
@@ -437,6 +453,7 @@ function createTable(images) {
const tbody = document.createElement("tbody");
images.forEach(img => {
const tr = document.createElement("tr");
tr.dataset.path = img.path;
if (state.selectedImages.has(img.path)) {
tr.classList.add("multi-selected");
}
@@ -481,14 +498,23 @@ function createTable(images) {
tr.appendChild(tdDate);
tr.appendChild(tdTags);
// クリック: 詳細表示 / Ctrl+クリック: 複数選択 / Alt+クリック: Metadataタブで開く
// クリック: 詳細表示 / Ctrl+クリック: 複数選択 / Shift+クリック: 範囲選択 / Alt+クリック: Metadataタブで開く
tr.addEventListener("click", (e) => {
if (e.altKey) {
e.preventDefault();
openImageInMetadataTab(img);
return;
}
if (e.ctrlKey || e.metaKey) {
const idx = state.images.findIndex(i => i.path === img.path);
if (e.shiftKey && state.lastSelectionIndex !== -1) {
const from = Math.min(state.lastSelectionIndex, idx);
const to = Math.max(state.lastSelectionIndex, idx);
for (let i = from; i <= to; i++) {
state.selectedImages.add(state.images[i].path);
}
_applySelectionToDOM();
updateBulkBar();
} else if (e.ctrlKey || e.metaKey) {
if (state.selectedImages.has(img.path)) {
state.selectedImages.delete(img.path);
tr.classList.remove("multi-selected");
@@ -496,9 +522,11 @@ function createTable(images) {
state.selectedImages.add(img.path);
tr.classList.add("multi-selected");
}
state.lastSelectionIndex = idx;
updateBulkBar();
} else {
state.selectedImage = img;
state.lastSelectionIndex = idx;
tbody.querySelectorAll("tr.selected").forEach(el => el.classList.remove("selected"));
tr.classList.add("selected");
loadImageDetail(img);
@@ -513,6 +541,17 @@ function createTable(images) {
return table;
}
// ── 複数選択ユーティリティ ────────────────────────────────────
/** state.selectedImages に基づき、描画済みの要素の multi-selected クラスを同期する */
function _applySelectionToDOM() {
const grid = document.getElementById("wfm-gallery-grid");
if (!grid) return;
grid.querySelectorAll("[data-path]").forEach(el => {
el.classList.toggle("multi-selected", state.selectedImages.has(el.dataset.path));
});
}
// ── 複数選択バー ──────────────────────────────────────────────
function updateBulkBar() {
@@ -1468,6 +1507,7 @@ function bindEvents() {
// 一括操作バー
document.getElementById("wfm-gallery-bulk-deselect")?.addEventListener("click", () => {
state.selectedImages.clear();
state.lastSelectionIndex = -1;
updateBulkBar();
// 選択状態をビューから除去
document.querySelectorAll(".multi-selected").forEach(el => el.classList.remove("multi-selected"));
+3 -3
View File
@@ -678,7 +678,7 @@ const LANGUAGES = {
helpGallery3: "Thumbnail and Table view modes; double-click any image to open fullscreen lightbox",
helpGallery4: "Toolbar filters: favorites (★), text search (filename / tag / prompt), tag filter, group filter, sort by date/name",
helpGallery5: "Folder tree: click to load images, expand with ▶; '+ New' creates a subfolder inside the selected folder, 'Del' deletes it with all contents",
helpGallery6: "Multi-select with Ctrl+click — bulk bar: select group → 'Add to Group' / 'Remove from Group'; 'Favorite All' / 'Unfavorite All'; 'Compare' (2–4 images); 'Move To...'; 'Delete File'",
helpGallery6: "Multi-select: Ctrl+click to toggle individual images; Shift+click to range-select from the last clicked item — bulk bar: select group → 'Add to Group' / 'Remove from Group'; 'Favorite All' / 'Unfavorite All'; 'Compare' (2–4 images); 'Move To...'; 'Delete File'",
helpGallery7: "Detail panel — Info tab: filename, size, date, tags (add/remove), memo; 'Move To...' moves the image to another folder, 'Delete File' removes it permanently",
helpGallery8: "Detail panel — JSON tab: displays workflow JSON from PNG embedded data (prompt / workflow keys) or from metadata saved by the Generate UI tab; 'Copy & Send Canvas' button copies to clipboard and sends the workflow directly to the ComfyUI canvas (requires Workflow Studio to be opened from the ComfyUI toolbar; UI-format only falls back to title drag if opened from a bookmark)",
helpGallery9: "Detail panel — Groups tab: create, assign, remove, rename, and delete groups per image",
@@ -1553,7 +1553,7 @@ const LANGUAGES = {
helpGallery3: "サムネイル・テーブル表示モード切替;ダブルクリックで全画面ライトボックス表示",
helpGallery4: "ツールバーフィルタ:お気に入り(★)、テキスト検索(ファイル名・タグ・プロンプト)、タグフィルタ、グループフィルタ、日付・名前ソート",
helpGallery5: "フォルダツリー:クリックで画像を読み込み;▶で展開;「+ New」で選択フォルダ内にサブフォルダを作成;「Del」でそのフォルダとすべての内容を削除",
helpGallery6: "Ctrl+クリックで複数選択 — 一括操作バー:グループを選択して「グループに追加」/「グループから削除」;「お気に入り追加(全件)」/「お気に入り解除(全件)」;「比較」(2〜4枚選択時);「移動先...」;「ファイル削除」",
helpGallery6: "複数選択:Ctrl+クリックで個別トグル;Shift+クリックで最後にクリックした位置から範囲選択 — 一括操作バー:グループを選択して「グループに追加」/「グループから削除」;「お気に入り追加(全件)」/「お気に入り解除(全件)」;「比較」(2〜4枚選択時);「移動先...」;「ファイル削除」",
helpGallery7: "詳細パネル — Infoタブ:ファイル名、サイズ、日付、タグ(追加/削除)、メモ;「Move To...」で他フォルダへ移動;「ファイル削除」で完全削除",
helpGallery8: "詳細パネル — JSONタブ:PNGの埋め込みデータ(prompt / workflow キー)またはGenerateUIタブで保存したメタデータからワークフローJSONを表示;「Copy & Send Canvas」ボタンでクリップボードにコピーしてComfyUIキャンバスへ直接送信(UI形式・API形式どちらも対応);ComfyUIツールバーから開いていない場合はUI形式のみタイトルドラッグのフォールバック",
helpGallery9: "詳細パネル — Groupsタブ:画像ごとのグループ作成、割り当て、解除、名前変更、削除",
@@ -2428,7 +2428,7 @@ const LANGUAGES = {
helpGallery3: "缩略图和表格视图模式;双击任何图像可在全屏灯箱中打开",
helpGallery4: "工具栏过滤器:收藏 (★)、文本搜索(文件名・标签・提示词)、标签过滤、分组过滤、按日期/名称排序",
helpGallery5: "文件夹树:点击加载图像,▶展开;'+ New'在选定文件夹内创建子文件夹;'Del'删除该文件夹及其所有内容",
helpGallery6: "使用Ctrl+点击多选 — 批量操作栏:选择分组 → 「添加到分组」/「从分组中删除」;全部收藏/取消收藏;「对比」(2–4张);移动到...;删除文件",
helpGallery6: "多选:Ctrl+点击切换单张图像;Shift+点击从上次点击位置进行范围选择 — 批量操作栏:选择分组 → 「添加到分组」/「从分组中删除」;全部收藏/取消收藏;「对比」(2–4张);移动到...;删除文件",
helpGallery7: "详情面板 — 信息(Info)标签:文件名、大小、日期、标签(添加/移除)、备注;'移动到...'将图像移至另一文件夹;'删除文件'永久删除",
helpGallery8: "详情面板 — JSON标签:显示来自PNG嵌入数据(prompt / workflow键)或Generate UI标签保存的工作流JSON;「Copy & Send Canvas」按钮将工作流复制到剪贴板并直接发送到ComfyUI画布(UI和API格式均支持);若Workflow Studio不是从ComfyUI工具栏打开,UI格式将回退到标题拖拽",
helpGallery9: "详情面板 — 分组(Groups)标签:对每个图像进行组的创建、分配、移除、重命名和删除",