Files
1439a5ef19 feat(images): collect AVIF as a media type (#652) (#673)
* Fix DB threading, recent ordering, restore size, and scan timestamps

* Fix subfolders API missing include_ancestors param

* refactor: move api code into promptmanager_core package

* chore: ignore local config, tracking state, and db backups

* Fix: fall back to original source when thumbnail img fails to load

* fix(core): apply code review fixes, optimizations, and schema compliance

- Fix KeyError in image_monitor _get_fallback_prompt dictionary handling
- Add secondary LoRA hash stripping in image_monitor prompt lookup
- Protect dual PromptManager workflows from metadata overwrite in patched_save_images
- Support WebP, JPEG, and GIF metadata extraction via image.info
- Add default values for prepend_text and append_text in INPUT_TYPES
- Add **kwargs to encode_prompt, process_text, search, and IS_CHANGED
- Declare explicit RETURN_NAMES across PromptManager and PromptManagerText
- Add close() proxy to PromptDatabase and fix Windows SQLite connection locks
- Normalize database and subfolder paths for cross-platform consistency
- Update test suite teardown handlers and mock targets across 17 test modules
- Add comprehensive CHANGELOG.md and issue.txt tracking documentation

* Close test databases before unlinking temp files

The usage and image-linking tests unlinked their temp database while the
persistent SQLite connection was still open, so Windows raised WinError 32
from tearDown (POSIX allows unlinking an open file, so upstream CI never
saw it). Close the database first and ignore a transient lock, matching
tests/test_database.py.

* Ignore local tracking state and prebackfill database backup

* style: restore black formatting after 3.6.0 merge

The fork-only default:" additions to prepend_text/append_text dropped the
trailing commas, which black reformats. This is the entire cause of Tests #4
on main: black --check failed with 'would reformat prompt_manager.py'
while every other job (test matrix, coverage, comfyui, js-test) passed.

No behaviour change.

* feat(images): collect AVIF as a media type (#652)

The EXIF reader from #650 reads the prompt and workflow records ComfyUI's
SaveImageAdvanced writes into an AVIF, but no file-type list named .avif, so
neither the scan nor the monitor ever handed it one.

Every list now names .avif: the scan and its deletion allowlist, the monitor's
default and fallback, the gallery and thumbnail walks, serving and Inspect,
auto-tagging's listing and its path check, the capture store, the preview
source order and the diagnostics count.

Pillow's floor here is >= 10.1.0 (ComfyUI's) and Pillow opens AVIF only from
11.0, and only when built with an AVIF decoder. utils/media_formats.collectable
asks PIL.features.check("avif") at every collection point, so a Pillow without
AVIF skips the file quietly and behaves exactly as before #652; the tests pin
both answers on the gallery walk, the monitor, auto-tagging, the capture store
and the scan.

gallery.monitoring.extensions is saved per install and overrides the default,
so a list saved before #652 gains .avif last on load, keeping every entry the
install chose; an empty list stays empty, and a value that is not a list keeps
the current one.

The fixture is tests/fixtures/media/comfyui_avif.avif: a 1 KB still written by
ComfyUI's own _save_avif (tools/make_avif_fixture.py regenerates it) carrying a
PromptManager graph. The scan stores and links its prompt and pair; the monitor
links the same positive prompt from the file's own EXIF.

The local browser-only Inspect reader is unchanged: the bundled front-end
reader does not parse AVIF, so the chooser still offers what it can read.
Library Inspect reads an AVIF through the server, where Pillow answers.

* chore: drop two local ignore rules that are not part of AVIF support (#652)

---------

Co-authored-by: LacklusterOpsec <LacklusterOpsec@users.noreply.github.com>
Co-authored-by: Vito Sansevero <vito.sansevero@gmail.com>
2026-11-21 17:25:59 -08:00

44 lines
1.7 KiB
Python

"""Which still-image formats this install can collect (#652).
PNG, JPEG, WebP, GIF, BMP and TIFF are read by every Pillow PromptManager
supports. AVIF is not: Pillow's floor here is >= 10.1.0 (ComfyUI's), and
Pillow opens AVIF only from 11.0, and only when it was built with an AVIF
decoder. A file-type list that names ``.avif`` unconditionally would hand the
scan and the monitor files this install cannot open, so the lists name it (a
served or deletable file is a file, whatever this Pillow reads) and the
collection points ask :func:`collectable` before a file enters the library.
The scan (``py.api.admin``), the monitor (``utils.image_monitor``), the
gallery walk (``py.api.images``), auto-tagging's listing
(``py.api.autotag_routes``) and the capture store
(``utils.media_capture``) skip AVIF quietly when the answer is no, so a
Pillow without AVIF behaves exactly as it did before #652.
"""
AVIF_EXTENSION = ".avif"
def avif_supported() -> bool:
"""Whether this Pillow can decode AVIF (``PIL.features.check("avif")``).
Pillow answers False on every version before 11.0 and on a build without
an AVIF decoder, so it is the one answer the collection points need.
"""
try:
from PIL import features
except ImportError: # a partial install: no still image is read anyway
return False
try:
return bool(features.check("avif"))
except Exception:
return False
def collectable(extension: str) -> bool:
"""Whether a still image with *extension* may enter the library.
Every extension is collectable except ``.avif``, which needs
:func:`avif_supported`. The extension is compared case-insensitively.
"""
return str(extension).lower() != AVIF_EXTENSION or avif_supported()