main
md 56 lines 3.16 KB
Rendered Raw
1 # download_work_dir_files.py DOX
2
3 ## Purpose
4
5 - Own the `download_work_dir_files.py` API endpoint.
6 - This module handles workdir file operations for download work dir files.
7 - Keep this file-level DOX profile synchronized with `download_work_dir_files.py` because this directory is intentionally flat.
8
9 ## Ownership
10
11 - `download_work_dir_files.py` owns the runtime implementation.
12 - `download_work_dir_files.py.dox.md` owns durable notes about responsibilities, contracts, side effects, and verification for that implementation.
13 - Classes:
14 - `DownloadFiles` (`ApiHandler`)
15 - `async process(self, input: Input, request: Request) -> Output`
16 - Top-level functions:
17 - `normalize_paths(paths) -> list[str]`
18 - `selected_archive_name(count: int) -> str`
19 - `create_selected_zip(paths: list[str], current_path: str=...) -> str`
20 - `resolve_download_path(path: str, base_dir: Path) -> Path`
21 - `collapse_nested_paths(paths: list[Path]) -> list[Path]`
22 - `archive_root_name(source_path: Path, current_dir: Path | None, base_dir: Path) -> str`
23 - `unique_archive_name(name: str, used_names: set[str]) -> str`
24 - `write_zip_entry(zip_file: zipfile.ZipFile, source_path: Path, arc_root: str) -> None`
25
26 ## Runtime Contracts
27
28 - HTTP handlers must derive from `helpers.api.ApiHandler`; WebSocket handlers must derive from `helpers.ws.WsHandler`.
29 - Update this file whenever request payloads, authentication or CSRF requirements, response shapes, route side effects, or WebSocket event contracts change.
30 - `DownloadFiles` is an `ApiHandler`.
31 - `DownloadFiles` defines `process(...)`.
32 - The endpoint retains the default authenticated and CSRF-protected browser contract.
33 - Selected paths use `/` as their root, matching the authenticated File Browser and editor filesystem scope.
34 - Observed side-effect areas: filesystem reads, filesystem writes, filesystem deletion.
35 - Imported dependency areas include: `api.download_work_dir_file`, `base64`, `flask`, `helpers`, `helpers.api`, `helpers.localization`, `io`, `os`, `pathlib`, `tempfile`, `zipfile`.
36
37 ## Key Concepts
38
39 - Important called helpers/classes observed in the source: `Localization.get.now.strftime`, `Path.resolve`, `normalize_paths`, `collapse_nested_paths`, `Path`, `os.path.splitext`, `source_path.is_dir`, `zip_file.write`, `selected_archive_name`, `runtime.is_development`, `stream_file_download`, `ValueError`, `raw_path.strip`, `resolve_download_path`, `current_dir.is_file`, `resolved.exists`, `FileNotFoundError`, `tempfile.NamedTemporaryFile`, `zipfile.ZipFile`, `candidate.is_absolute`.
40 - Keep request/response, tool, or helper semantics documented here at the same time as source changes.
41
42 ## Work Guidance
43
44 - Preserve authentication, CSRF, loopback, and API-key checks unless the endpoint contract explicitly changes.
45 - Update frontend callers, plugin callers, and tests together when payload shape changes.
46 - Use `helpers.api.Response` for non-JSON responses, files, redirects, or status-specific replies.
47
48 ## Verification
49
50 - Run endpoint-specific or API/WebSocket tests for changed behavior; smoke-test browser callers when no focused test exists.
51 - Related tests observed by source search:
52 - `tests/test_download_toast_regressions.py`
53
54 ## Child DOX Index
55
56 No child DOX files.