fix(example-images): support importing for Other models and pending hashes

Two gaps kept 'import example images' from working on the Other page:

- import_images/delete_custom_image/set_example_image_nsfw_level only
  searched the lora/checkpoint/embedding scanners, so Other-category
  models were never found ('Model with hash ... not found in cache').
  All three now go through a shared scanner list that includes the
  Other scanner.
- Other models (and fresh checkpoints) carry hash_status=pending with
  an empty sha256, so the frontend sent an empty model_hash and the
  import was rejected with 'Missing model_hash parameter'. The modal
  now also sends the model's file path, and the import use case
  resolves the hash on demand via the scanner's lazy-hash calculation.
  The resolved hash is returned to the UI and persisted on the
  showcase element so follow-up operations target the same
  hash-keyed folder.
This commit is contained in:
Will Miao
2026-10-01 10:16:34 +08:00
parent eeb9270827
commit 2193ec8f38
5 changed files with 248 additions and 23 deletions
@@ -29,6 +29,7 @@ class ImportExampleImagesUseCase:
async def execute(self, request: web.Request) -> Dict[str, Any]:
model_hash: str | None = None
model_path: str | None = None
files_to_import: List[str] = []
temp_files: List[str] = []
@@ -40,6 +41,8 @@ class ImportExampleImagesUseCase:
first_field = cast(BodyPartReader, first_field_raw) if first_field_raw is not None else None
if first_field and first_field.name == "model_hash":
model_hash = await first_field.text()
elif first_field and first_field.name == "model_path":
model_path = await first_field.text()
else:
# Support clients that send files first and hash later
if first_field is not None:
@@ -49,13 +52,22 @@ class ImportExampleImagesUseCase:
field = cast(BodyPartReader, raw_field)
if field.name == "model_hash" and not model_hash:
model_hash = await field.text()
elif field.name == "model_path" and not model_path:
model_path = await field.text()
elif field.name == "files":
await self._collect_upload_file(field, files_to_import, temp_files)
else:
data = await request.json()
model_hash = data.get("model_hash")
model_path = data.get("model_path")
files_to_import = list(data.get("file_paths", []))
# Models with a deferred hash (checkpoints, Other) send an empty
# model_hash; locate them by file path and compute the hash on
# demand, since example-image folders are keyed by hash.
if not model_hash and model_path:
model_hash = await self._processor.resolve_hash_for_file_path(model_path)
if not model_hash:
raise ImportExampleImagesValidationError("Missing model_hash parameter")
result = await self._processor.import_images(model_hash, files_to_import)