auto-save 2026-05-18 21:03 (+1, ~3)
This commit is contained in:
43
api/main.py
43
api/main.py
@@ -6056,6 +6056,49 @@ def save_subject_template(job_id: str, req: SaveSubjectTemplateReq) -> SubjectTe
|
||||
)
|
||||
items = [item] + [existing for existing in load_subject_template_items() if existing.id != item.id]
|
||||
save_subject_template_items(items)
|
||||
try:
|
||||
library_id = f"lib_subjects_{uuid.uuid4().hex[:12]}"
|
||||
library_dir = _asset_library_item_dir("subjects", library_id)
|
||||
library_images: list[AssetLibraryImage] = []
|
||||
for image in images:
|
||||
src = SUBJECT_TEMPLATE_IMAGE_DIR / image.filename
|
||||
if not src.exists():
|
||||
continue
|
||||
view = re.sub(r"[^a-zA-Z0-9_-]+", "_", image.view or image.id).strip("_") or image.id
|
||||
dst = library_dir / "images" / f"{view}.jpg"
|
||||
dst.parent.mkdir(parents=True, exist_ok=True)
|
||||
shutil.copy2(src, dst)
|
||||
width, height = _library_media_size(dst)
|
||||
library_images.append(AssetLibraryImage(
|
||||
id=view,
|
||||
view=image.view,
|
||||
label=image.label or image.view,
|
||||
filename=f"images/{view}.jpg",
|
||||
width=width or image.width,
|
||||
height=height or image.height,
|
||||
created_at=image.created_at or now,
|
||||
))
|
||||
if library_images:
|
||||
library_item = AssetLibraryItem(
|
||||
id=library_id,
|
||||
kind="subjects",
|
||||
name=name,
|
||||
name_zh=name,
|
||||
note=req.note.strip(),
|
||||
tags=["主体模板"],
|
||||
source_job_id=job_id,
|
||||
prompt_brief=prompt_brief,
|
||||
prompt_brief_zh=prompt_brief_zh,
|
||||
subject_style=req.subject_style,
|
||||
images=library_images,
|
||||
views=library_images,
|
||||
created_at=now,
|
||||
updated_at=now,
|
||||
)
|
||||
_hydrate_asset_library_urls(library_item)
|
||||
_write_asset_item(library_item)
|
||||
except Exception as e:
|
||||
print(f"[asset library] subject template mirror failed: {e}", flush=True)
|
||||
return item
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user