main
md 55 lines 2.95 KB
Rendered Raw
1 # download_work_dir_file.py DOX
2
3 ## Purpose
4
5 - Own the `download_work_dir_file.py` API endpoint.
6 - This module handles workdir file operations for download work dir file.
7 - Keep this file-level DOX profile synchronized with `download_work_dir_file.py` because this directory is intentionally flat.
8
9 ## Ownership
10
11 - `download_work_dir_file.py` owns the runtime implementation.
12 - `download_work_dir_file.py.dox.md` owns durable notes about responsibilities, contracts, side effects, and verification for that implementation.
13 - Classes:
14 - `DownloadFile` (`ApiHandler`)
15 - `get_methods(cls)`
16 - `async process(self, input: Input, request: Request) -> Output`
17 - Top-level functions:
18 - `stream_file_download(file_source, download_name, chunk_size=...)`: Create a streaming response for file downloads that shows progress in browser.
19 - `make_disposition(download_name: str) -> str`
20 - `resolve_download_path(path: str) -> str`: Resolve a requested download path from the File Browser root.
21 - `async fetch_file(path)`
22
23 ## Runtime Contracts
24
25 - HTTP handlers must derive from `helpers.api.ApiHandler`; WebSocket handlers must derive from `helpers.ws.WsHandler`.
26 - Update this file whenever request payloads, authentication or CSRF requirements, response shapes, route side effects, or WebSocket event contracts change.
27 - `DownloadFile` is an `ApiHandler`.
28 - `DownloadFile` defines `process(...)`.
29 - `DownloadFile` defines `get_methods(...)`.
30 - The endpoint retains the default authenticated and CSRF-protected browser contract.
31 - Download paths use `/` as their root, matching the authenticated File Browser and editor filesystem scope.
32 - Observed side-effect areas: filesystem reads, network calls.
33 - Imported dependency areas include: `api`, `base64`, `flask`, `helpers`, `helpers.api`, `io`, `mimetypes`, `os`, `pathlib`, `urllib.parse`.
34
35 ## Key Concepts
36
37 - Important called helpers/classes observed in the source: `mimetypes.guess_type`, `Response`, `quote`, `Path.resolve`, `Path`, `candidate.is_absolute`, `os.path.getsize`, `generate`, `download_name.encode.decode`, `candidate.resolve`, `resolve`, `resolved.relative_to`, `Exception`, `file.read`, `base64.b64encode.decode`, `file_source.tell`, `file_source.seek`, `ValueError`, `file_path.startswith`, `runtime.call_development_function`.
38 - Keep request/response, tool, or helper semantics documented here at the same time as source changes.
39
40 ## Work Guidance
41
42 - Preserve authentication, CSRF, loopback, and API-key checks unless the endpoint contract explicitly changes.
43 - Update frontend callers, plugin callers, and tests together when payload shape changes.
44 - Use `helpers.api.Response` for non-JSON responses, files, redirects, or status-specific replies.
45
46 ## Verification
47
48 - Run endpoint-specific or API/WebSocket tests for changed behavior; smoke-test browser callers when no focused test exists.
49 - Related tests observed by source search:
50 - `tests/test_download_toast_regressions.py`
51 - `tests/test_office_canvas_setup.py`
52
53 ## Child DOX Index
54
55 No child DOX files.