8000 fix(iiif): keep each namespace's copy of imported IIIF media apart by adeelahmad · Pull Request #201 · adeelahmad/lense · GitHub
[go: up one dir, main page]

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion fastapi_backend/app/domain/iiif.py
Original file line number Diff line number Diff line change
Expand Up @@ -1049,7 +1049,7 @@ def import_manifest(db, cfg, url, ns, keep_transcripts=True, user=None, log=prin
or pathlib.PurePosixPath(urllib.parse.urlsplit(c["audio"]["id"]).path).suffix
or ".bin"
)
local = pathlib.Path(cfg["data_dir"]) / "iiif-import" / f"{fp}{ext}"
local = pathlib.Path(cfg["data_dir"]) / "iiif-import" / str(sid) / f"{fp}{ext}" # per namespace: its own key
local.parent.mkdir(parents=True, exist_ok=True)
local.write_bytes(_get(c["audio"]["id"], MAX_MEDIA))
keyring.protect(db, cfg, sid, local)
Expand Down
6 changes: 6 additions & 0 deletions fastapi_backend/tests/api/test_iiif.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,12 @@ def test_import_from_iiif(env):
assert meta["related"][0]["id"] == f"{base}/manifest.json"
again = c.post("/api/v1/import/iiif", headers=h, json={"url": f"{base}/manifest.json", "namespace": "oral", "wait": True})
assert again.json()["recordings"] == [] # no duplicates
# the same manifest in another namespace gets its own copy of the media: each is sealed with its namespace's key
other = c.post("/api/v1/import/iiif", headers=h, json={"url": f"{base}/manifest.json", "namespace": "oral3", "wait": True})
rid3 = other.json()["recordings"][0]
paths = [env.db.one("SELECT VALUE path FROM $r", r=iiif.R("recording", x)) for x in (rid, rid3)]
assert paths[0] != paths[1], paths
assert c.get(f"/api/v1/recordings/{rid}/audio", headers=h).status_code in (200, 206)
# a Collection's Manifests are found in the Collections inside it too (Lens nests its own), referenced or embedded
talks = {"@context": iiif.P3, "id": f"{base}/talks.json", "type": "Collection", "label": {"en": ["Talks"]}}
talks["items"] = [{"id": f"{base}/manifest.json", "type": "Manifest", "label": {"en": ["Oral history 7"]}}]
Expand Down
Loading
0