Implemented automatic path remapping

This commit is contained in:
patben8 committed 2026-09-27 13:39:17 +02:00
1 parent eccd352ae5
commit 99d590a051
17 files changed
+1025 -10

No files matched your search

+56
View File
@@ -33,6 +33,11 @@ from .core.capabilities import Capabilities
from .jobs import JOBS
from .core.pathmap import PathMapping
from .schemas import (
Relocation,
RelocationApplied,
RelocationApply,
RelocationCandidate,
RelocationVolume,
AutoGridBatchRequest,
AutoGridRequest,
AutoCueOutcome,
@@ -265,6 +270,57 @@ def remap_paths(body: PathMappingInfo) -> RemapResult:
return RemapResult(rewritten=len(moved), commit=commit)
@app.get("/api/library/relocation", response_model=Relocation)
def get_relocation() -> Relocation:
"""The open-time missing-files check: every stored volume in which NO track
resolves, and where the search found its tracks. Empty once answered, so the
UI can refetch freely without re-asking.
Waits briefly for the search, then reports `scanning` so a slow drive
cannot hold a request open; the UI polls until it is done.
"""
require_adapter()
check = STATE.relocation
if check is None:
return Relocation()
if not check.wait(timeout=10):
return Relocation(scanning=True)
return Relocation(
volumes=[
RelocationVolume(
label=p.label,
root=p.root,
total=p.total,
status=p.status,
candidates=[
RelocationCandidate.model_validate(
{"from": c.mapping.from_prefix, "to": c.mapping.to_prefix, "found": c.found}
)
for c in p.candidates
],
)
for p in check.pending
]
)
@app.post("/api/library/relocation", response_model=RelocationApplied)
def answer_relocation(body: RelocationApply) -> RelocationApplied:
"""Answer the check: apply the chosen mappings for THIS SESSION only (no
mappings = "Not now"). Nothing is written to the library or to prefs, and a
reopen asks again."""
require_adapter()
check = STATE.relocation
if check is None:
raise HTTPException(409, "There is no missing-files check to answer")
mappings = [PathMapping.make(m.from_, m.to) for m in body.mappings]
try:
tracks = check.answer(mappings)
except ValueError as ex:
raise HTTPException(400, str(ex))
return RelocationApplied(mappings=len(mappings), tracks=tracks)
@app.get("/api/prefs")
def get_prefs() -> dict:
"""The full persisted user-preferences blob (UI layout, last collection…)."""