diff --git a/deeptutor/api/routers/reading.py b/deeptutor/api/routers/reading.py index 2adb1e904..cd035758e 100644 --- a/deeptutor/api/routers/reading.py +++ b/deeptutor/api/routers/reading.py @@ -1058,6 +1058,8 @@ async def upload_material( filename = (file.filename or "").strip() if not filename: raise HTTPException(status_code=400, detail="The upload has no filename.") + if filename.lower().endswith(".epub.zip"): + filename = filename[: -len(".zip")] tmp_dir = Path(tempfile.mkdtemp(prefix="dt-reading-")) tmp_path = tmp_dir / Path(filename).name diff --git a/tests/reading/test_router.py b/tests/reading/test_router.py index d86c4ddcf..2a62f1698 100644 --- a/tests/reading/test_router.py +++ b/tests/reading/test_router.py @@ -436,6 +436,14 @@ def test_epub_render_response_is_normalized_and_raw_preserves_upload(client: Tes assert all("__MACOSX" not in info.filename for info in infos) +def test_upload_unwraps_a_safari_folder_drag_epub_zip(client: TestClient) -> None: + material = _upload(client, name="book.epub.zip", data=_epub_bytes(finder_package=True)) + + assert material["render_mode"] == "epub" + assert material["unit_count"] >= 1 + assert material["filename"] == "book.epub" + + def test_epub_pairing_requires_confirmation_and_preserves_source_materials( client: TestClient, ) -> None: