Name the packaged file by Document Type with the original extension 🟩

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
Khalim Conn-Kowlessar 2026-07-08 09:07:25 +00:00
parent 63933db529
commit b89b9fe944

View file

@ -8,6 +8,7 @@ orchestrator does the S3/DB work; this module only lays out the archive.
from __future__ import annotations from __future__ import annotations
import posixpath
from dataclasses import dataclass from dataclasses import dataclass
from datetime import datetime from datetime import datetime
from typing import Optional, Sequence from typing import Optional, Sequence
@ -57,6 +58,14 @@ class DownloadPackagePlan:
skipped: tuple[SkippedDocument, ...] skipped: tuple[SkippedDocument, ...]
def _extension_of(s3_key: str) -> str:
"""The file extension of an S3 key (``.pdf``, ``.zip``, …), empty when the
key's basename has none. Used to keep the packaged file openable while
naming it by Document Type."""
_root, ext = posixpath.splitext(posixpath.basename(s3_key))
return ext
def plan_download_package( def plan_download_package(
documents: Sequence[ResolvedDocument], documents: Sequence[ResolvedDocument],
) -> DownloadPackagePlan: ) -> DownloadPackagePlan:
@ -83,7 +92,7 @@ def plan_download_package(
entries: list[PackageEntry] = [ entries: list[PackageEntry] = [
PackageEntry( PackageEntry(
zip_path=f"{document.address} ({document.landlord_property_id})/" zip_path=f"{document.address} ({document.landlord_property_id})/"
f"{document.document_type}", f"{document.document_type}{_extension_of(document.s3_key)}",
s3_bucket=document.s3_bucket, s3_bucket=document.s3_bucket,
s3_key=document.s3_key, s3_key=document.s3_key,
) )