reorder
This commit is contained in:
@@ -210,13 +210,21 @@ def _run_consistency_check():
|
||||
persons = database.list_persons(include_archived=True)
|
||||
missing_files = []
|
||||
archived_items = []
|
||||
missing_group = []
|
||||
for p in persons:
|
||||
filename = p[0]
|
||||
group_id = p[2]
|
||||
if not group_id:
|
||||
missing_group.append({
|
||||
"filename": filename,
|
||||
"name": p[1]
|
||||
})
|
||||
|
||||
is_archived = bool(p[14]) if p[14] else False
|
||||
if is_archived:
|
||||
archived_items.append({
|
||||
"filename": filename,
|
||||
"group_id": p[2],
|
||||
"group_id": group_id,
|
||||
"name": p[1]
|
||||
})
|
||||
|
||||
@@ -224,7 +232,7 @@ def _run_consistency_check():
|
||||
if not os.path.exists(fpath):
|
||||
missing_files.append({
|
||||
"filename": filename,
|
||||
"group_id": p[2],
|
||||
"group_id": group_id,
|
||||
"name": p[1]
|
||||
})
|
||||
|
||||
@@ -244,10 +252,11 @@ def _run_consistency_check():
|
||||
"timestamp": time.time(),
|
||||
"missing_files": missing_files,
|
||||
"untracked_files": untracked_files,
|
||||
"archived_items": archived_items
|
||||
"archived_items": archived_items,
|
||||
"missing_group": missing_group
|
||||
}
|
||||
_write_json(os.path.join(data_dir, "inconsistencies.json"), report)
|
||||
print(f"[consistency] check complete: {len(missing_files)} missing, {len(untracked_files)} untracked, {len(archived_items)} archived")
|
||||
print(f"[consistency] check complete: {len(missing_files)} missing, {len(untracked_files)} untracked, {len(archived_items)} archived, {len(missing_group)} missing group")
|
||||
return report
|
||||
except Exception as e:
|
||||
print(f"[consistency] check failed: {e}")
|
||||
@@ -1305,6 +1314,7 @@ def _write_all_static() -> None:
|
||||
"content_type": p[12] or "image",
|
||||
"faceswap_source_video": p[13],
|
||||
"archived": is_archived,
|
||||
"is_source": bool(p[15]) if p[15] else False,
|
||||
})
|
||||
print(f"[static] write_all: {len(db_images)} total images, {archived_count} archived")
|
||||
try:
|
||||
@@ -1674,8 +1684,9 @@ class GroupArchiveRequest(BaseModel):
|
||||
filenames: list[str]
|
||||
|
||||
class RepairRequest(BaseModel):
|
||||
action: str # "delete_record", "import_file", "restore", "delete_permanently"
|
||||
action: str # "delete_record", "import_file", "restore", "delete_permanently", "assign_group"
|
||||
filename: str
|
||||
group_id: str | None = None
|
||||
|
||||
class BatchRequest(BaseModel):
|
||||
filenames: list[str]
|
||||
@@ -2377,10 +2388,17 @@ def db_repair(req: RepairRequest):
|
||||
if not os.path.exists(fpath):
|
||||
raise HTTPException(404, "File not found on disk")
|
||||
# Basic import: just register it in DB
|
||||
database.upsert_person(req.filename, filepath=fpath, group_id=naming.get_base_name(req.filename))
|
||||
database.upsert_person(req.filename, filepath=fpath, group_id=naming.get_base_name(req.filename), is_source=True)
|
||||
_invalidate_static()
|
||||
_run_consistency_check()
|
||||
return {"status": "imported", "filename": req.filename}
|
||||
elif req.action == "assign_group":
|
||||
# Assign a group_id (default to base name if not provided)
|
||||
gid = req.group_id or naming.get_base_name(req.filename)
|
||||
database.upsert_person(req.filename, group_id=gid)
|
||||
_invalidate_static()
|
||||
_run_consistency_check()
|
||||
return {"status": "assigned", "filename": req.filename, "group_id": gid}
|
||||
elif req.action == "restore":
|
||||
database.set_archived(req.filename, False)
|
||||
_invalidate_static()
|
||||
@@ -2516,6 +2534,7 @@ def _process_upload(file_path: str, filename: str, prompts: list[str], name: str
|
||||
filename, filepath=file_path, name=auto_name,
|
||||
clip_description=clip_desc, tags=tags, embedding=embedding,
|
||||
group_id=group_id, sort_order=0, has_clothing=has_clothing,
|
||||
is_source=True,
|
||||
)
|
||||
# Surface the new group with its base image right away — the pose/base-prompt
|
||||
# generation below can take a while, and the user shouldn't wait for it to
|
||||
@@ -2549,6 +2568,7 @@ def _process_upload(file_path: str, filename: str, prompts: list[str], name: str
|
||||
clip_description=clip_desc, embedding=out_embedding,
|
||||
group_id=group_id, sort_order=next_order,
|
||||
prompt=prompt, pose=out_pose,
|
||||
source_refs=json.dumps([filename]),
|
||||
)
|
||||
except Exception as e:
|
||||
print(f"Error processing prompt '{prompt}' for {filename}: {e}")
|
||||
@@ -2590,7 +2610,7 @@ def upload_image(
|
||||
if group_id and skip_poses:
|
||||
sort_order = database.get_next_sort_order(group_id)
|
||||
database.upsert_person(filename, filepath=file_path, group_id=group_id,
|
||||
sort_order=sort_order)
|
||||
sort_order=sort_order, is_source=True)
|
||||
_invalidate_static()
|
||||
return {"status": "added", "filename": filename, "group_id": group_id}
|
||||
|
||||
@@ -2677,7 +2697,11 @@ def set_image_preferred(filename: str):
|
||||
raise HTTPException(404, "Image not found")
|
||||
group_id = person[1]
|
||||
if not group_id:
|
||||
raise HTTPException(400, "Image has no group assigned")
|
||||
# Auto-assign group_id if missing (legacy/orphan)
|
||||
group_id = naming.get_base_name(filename)
|
||||
database.upsert_person(filename, group_id=group_id)
|
||||
print(f"[fix] Auto-assigned group_id={group_id} to orphan {filename} during set-preferred")
|
||||
|
||||
rows = database.get_group_order(group_id)
|
||||
others = [r[0] for r in rows if r[0] != filename]
|
||||
database.set_group_order(group_id, [filename] + others)
|
||||
@@ -3440,7 +3464,8 @@ def remove_background_sam(filename: str):
|
||||
# Register sidecar in DB so it appears in the same group
|
||||
group_id = person[1]
|
||||
database.upsert_person(nobg_filename, filepath=nobg_path,
|
||||
group_id=group_id, has_background=False)
|
||||
group_id=group_id, has_background=False,
|
||||
source_refs=json.dumps([filename]))
|
||||
|
||||
used_sam2 = _sam2_predictor is not False and _sam2_predictor is not None
|
||||
return {
|
||||
|
||||
Reference in New Issue
Block a user