feat(settings): filename templates for download and bulk rename (#1071)

Add per-model-type filename templates ({model_name}, {version_name},
{base_model}, {author}, {first_tag}, {hash_short}, {original_name}) so
downloaded files get informative names instead of e.g. V1.safetensors.
Empty template keeps the current filename (opt-in, off by default).

- apply template automatically after downloads; rename conflicts keep
  the original name and never fail the download
- record original_file_name in metadata on rename for traceability
- bulk apply via GET|POST /api/lm/{prefix}/apply-filename-template with
  WebSocket progress, sharing the auto-organize lock
- settings UI lives in the new Organization tab with validation, live
  preview, and per-type 'apply to library' actions
This commit is contained in:
Will Miao
2026-09-19 09:04:24 +08:00
parent 327da0465b
commit 2bc9860b24
38 changed files with 2239 additions and 7 deletions
@@ -424,6 +424,52 @@ async def test_rename_model_preserves_extension(tmp_path: Path):
assert payload["file_name"] == new_name
@pytest.mark.asyncio
async def test_rename_model_records_original_file_name(tmp_path: Path):
old_name = "V1"
new_name = "flux-my-model-v3"
model_path = tmp_path / f"{old_name}.safetensors"
model_path.write_bytes(b"model")
metadata_path = tmp_path / f"{old_name}.metadata.json"
metadata_payload = {
"file_name": old_name,
"file_path": model_path.as_posix(),
}
metadata_path.write_text(json.dumps(metadata_payload))
async def metadata_loader(path: str):
with open(path, "r", encoding="utf-8") as handle:
return json.load(handle)
service = ModelLifecycleService(
scanner=DummyScanner(),
metadata_manager=PassthroughMetadataManager(),
metadata_loader=metadata_loader,
)
await service.rename_model(
file_path=model_path.as_posix(),
new_file_name=new_name,
)
saved_metadata = json.loads((tmp_path / f"{new_name}.metadata.json").read_text())
assert saved_metadata["original_file_name"] == old_name
# A second rename keeps the very first recorded name.
second_name = "flux-my-model-v4"
await service.rename_model(
file_path=(tmp_path / f"{new_name}.safetensors").as_posix(),
new_file_name=second_name,
)
saved_metadata = json.loads(
(tmp_path / f"{second_name}.metadata.json").read_text()
)
assert saved_metadata["original_file_name"] == old_name
@pytest.mark.asyncio
async def test_rename_model_with_dotted_basename(tmp_path: Path):
old_name = "model.v1"