Skip to content

fix(api): generate download filenames from the exported format - #120

Merged
HC-ONLINE merged 2 commits into
mainfrom
fix/download-filename-by-format
Oct 16, 2026
Merged

HC-ONLINE merged 2 commits into
mainfrom
fix/download-filename-by-format

Conversation

@HC-ONLINE

Copy link
Copy Markdown
Owner

Description

GET /api/download/{token} always returned Content-Disposition: attachment; filename=export.json, regardless of the real export format (JSON, JSONL, CSV or HTML). The filename was hardcoded in the download route, and the download helper stored file_format="json" for every token, so the metadata needed to build the correct filename was both wrong and inaccessible.

This PR:

  • fix: derives the download filename from the token's stored export format, validated against the supported-format allowlist (prevents header injection from registry values). DownloadService.get_info() now exposes token metadata to the route; the helper resolves the real format (service-reported format → export file extension → json fallback) instead of hardcoding "json".
  • refactor: centralizes the supported export formats in a single source of truth (ExportFormat Literal + EXPORT_FORMATS in export/base.py, re-exported from ciberwebscan.export), replacing five duplicated inline Literal definitions in the API request models and reusing the set in get_exporter, the download helper and the download route.

Verified end-to-end against a local API instance: exports in all four formats download with the matching filename (export.csv, export.jsonl, export.html, export.json).

Related Issue

None (internal code review finding).

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update

Checklist

  • I have followed the style guidelines of this project (Ruff & Pyright)
  • I have performed a self-review of my code
  • I have commented my code, particularly in hard-to-understand areas
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • I have updated the documentation accordingly

Screenshots (if applicable)

N/A — API header behavior change; no UI involved.

@HC-ONLINE
HC-ONLINE merged commit 07b203a into main Oct 16, 2026
8 checks passed
@HC-ONLINE
HC-ONLINE deleted the fix/download-filename-by-format branch October 16, 2026 19:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant