Add batch default flow and downloads

This commit is contained in:
admin
2026-06-10 17:50:42 +08:00
parent 6db15ebc3f
commit ec5b25d2d0
8 changed files with 187 additions and 6 deletions

View File

@@ -216,6 +216,43 @@ def get_results(filename: str) -> dict[str, Any]:
}
def collect_download_items(filenames: list[str] | None = None, include_original: bool = True) -> list[tuple[Path, str]]:
names = filenames or [item["name"] for item in list_images()]
items: list[tuple[Path, str]] = []
used_names: set[str] = set()
def add_file(path: Path, archive_name: str) -> None:
if not path.exists() or not path.is_file():
return
archive_name = archive_name.replace("\\", "/")
if archive_name in used_names:
stem = Path(archive_name).with_suffix("").as_posix()
suffix = Path(archive_name).suffix
index = 2
while f"{stem}_{index}{suffix}" in used_names:
index += 1
archive_name = f"{stem}_{index}{suffix}"
used_names.add(archive_name)
items.append((path, archive_name))
for filename in names:
source = source_image_path(filename)
folder = image_id(filename)
if include_original:
add_file(source, f"{folder}/original/{source.name}")
for method in DEHAZE_METHODS:
result = dehaze_result_path(filename, method)
add_file(result, f"{folder}/dehaze/{_safe_slug(method)}.png")
post_dir = image_result_dir(filename) / "postprocess"
if post_dir.exists():
for result in sorted(post_dir.glob("*.png"), key=lambda p: p.name.lower()):
add_file(result, f"{folder}/postprocess/{result.name}")
return items
def _reset_dir(path: Path) -> None:
if path.exists():
shutil.rmtree(path)