feat(hosted-file): implement intelligent ID resolution for V3 download action

- Updates download_file_action to automatically resolve container IDs (like event_file) to the underlying hosted_file.
- Updates GUIDE__V3_FRONTEND_API.md to document the 'ID Vision' standard for downloads.
- Resolves 404 errors observed when frontend passed event_file IDs to the hosted_file download endpoint.
This commit is contained in:
Scott Idem
2026-02-03 12:05:04 -05:00
parent f449e59b55
commit ea117bf268
2 changed files with 11 additions and 0 deletions

View File

@@ -209,7 +209,17 @@ async def download_file_action(
raise HTTPException(status_code=status.HTTP_403_FORBIDDEN, detail="Authentication required or invalid site_key.")
# 2. Resolve File Record
# ID Vision: Attempt to resolve the ID.
# If not found in hosted_file, check if it's an event_file ID that we can resolve to a hosted_file.
resolved_id = redis_lookup_id_random(record_id_random=hosted_file_id, table_name='hosted_file')
if not resolved_id:
log.info(f"ID {hosted_file_id} not found in hosted_file. Checking event_file...")
if ef_id := redis_lookup_id_random(record_id_random=hosted_file_id, table_name='event_file'):
if ef_rec := sql_select(sql="SELECT hosted_file_id FROM event_file WHERE id = :id", data={'id': ef_id}):
resolved_id = ef_rec.get('hosted_file_id')
log.info(f"Resolved event_file {hosted_file_id} to hosted_file {resolved_id}")
if not resolved_id:
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail="Hosted file record not found.")

View File

@@ -89,6 +89,7 @@ V3 uses specialized **"Action"** routes for binary operations to separate proces
**Path**: `GET /v3/action/hosted_file/{id}/download`
**Features:**
- **ID Vision:** Automatically resolves `{id}` if it belongs to a container object (e.g., `event_file`) instead of a direct `hosted_file`.
- **Streaming:** Supports standard `Range` headers for large files and video seeking.
- **Auth Bypass:** Use `?site_key=<auth_key>` to download without an API Key header or JWT (useful for public kiosks).
- **Testing:** Supports `delay_ms` query parameter.