fix: pool profiles never auto-switch on connect; seed empty profile from current pool
Connecting a Pool Profile no longer overwrites the pool's pool_id. The pool is switched only when the user actively selects a profile in the dropdown; picking an empty profile while a pool with images is connected offers to copy those images into it (new seed_profile op + /grid_pool/profiles/seed route), so the current pool is never silently lost. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -114,6 +114,26 @@ def export_profile(base, pid, dest_zip):
|
||||
return dest_zip
|
||||
|
||||
|
||||
def seed_profile(base, from_id, profile_id):
|
||||
"""Copy a pool dir's files (images/masks/manifest) into a profile dir.
|
||||
|
||||
Used to save an Image Pool's current contents into a freshly-selected empty
|
||||
profile. Copies top-level files only (the pool layout is flat); returns the
|
||||
number of files copied. No-op (0) if the source dir is missing.
|
||||
"""
|
||||
src = Path(base) / from_id
|
||||
dst = Path(base) / profile_id
|
||||
if not src.exists():
|
||||
return 0
|
||||
dst.mkdir(parents=True, exist_ok=True)
|
||||
n = 0
|
||||
for f in src.iterdir():
|
||||
if f.is_file():
|
||||
shutil.copy2(f, dst / f.name)
|
||||
n += 1
|
||||
return n
|
||||
|
||||
|
||||
def import_profile(base, src_zip, new_id, name=None, ts=0):
|
||||
reg = read_registry(base)
|
||||
meta_name = None
|
||||
|
||||
@@ -47,6 +47,13 @@ async def _duplicate(request):
|
||||
return web.json_response(e)
|
||||
|
||||
|
||||
@routes.post("/grid_pool/profiles/seed")
|
||||
async def _seed(request):
|
||||
body = await request.json()
|
||||
n = profiles.seed_profile(_base(), body["from"], body["id"])
|
||||
return web.json_response({"copied": n})
|
||||
|
||||
|
||||
@routes.get("/grid_pool/profiles/export")
|
||||
async def _export(request):
|
||||
pid = request.query["id"]
|
||||
|
||||
Reference in New Issue
Block a user