Skip to content

feat(express): let a download keep the original file name - #159

Merged
LukasGold merged 1 commit into
mainfrom
feat/download-filename-modes
Sep 2, 2026
Merged

feat(express): let a download keep the original file name#159
LukasGold merged 1 commit into
mainfrom
feat/download-filename-modes

Conversation

@LukasGold

Copy link
Copy Markdown
Contributor

Closes #94.

Changes

  • FilenameMode in src/osw/express.py, with the three forms the issue lists:
    • osw_id: OSW02a0e8a917594129b3b8f2f48e2c3f7f.txt, the name on the wiki. Unchanged default.
    • name: My_textfile.txt
    • name_and_osw_id: My_textfile_OSW02a0e8a917594129b3b8f2f48e2c3f7f.txt
  • target_fn_mode on osw_download_file and DownloadFileResult.
  • build_target_fn builds the name from the wiki file name and the stored original name.
  • _load_wiki_file collects the page load that DownloadFileResult.__init__ now does from two places.
  • tests/test_download_filename_modes.py: 16 offline tests.

Rationale

DownloadFileResult took the target file name straight from the url or page title, so a download always landed as the OSW-ID. The original name is already stored in the JSON data of the file page, put there by WikiFileController._init on upload, so nothing new has to be recorded to offer the other two forms.

The default stays the OSW-ID, so existing callers see no change.

Notes

  • The two new modes read the original name from the file page, so they load it even when use_cached is set. The name is not knowable without it. osw_id still resolves the path without any request.
  • Domain resolution moved above the target path so the early load has a domain to work with. Same logic, same inputs, only the position changed.
  • A page with no stored name falls back to the OSW-ID form and warns. Files predating the name being written have nothing else to go on.
  • The stored name is reduced to its last path segment, so a name from the wiki cannot redirect the download out of the target directory.
  • Every suffix is kept, not just the last. The OSW-ID carries no dot, so OSW....drawio.png yields My_drawing.drawio.png.
  • Upload needs no option of its own: it already stores the original name, and the wiki page title stays the OSW-ID, which is what identifies the file.

Verification

Offline suite passes (70 passed, 1 skipped). The tests cover build_target_fn directly. The full download path needs a live instance, so the round trip has not been run here.

- add FilenameMode with osw_id, name and name_and_osw_id
- add target_fn_mode to osw_download_file, defaulting to osw_id
- load the file page before the target path when the mode needs the name
- move domain resolution up, the early load depends on it
@github-actions

github-actions Bot commented Sep 2, 2026

Copy link
Copy Markdown
Contributor

Release preview

Merging this PR would release v2.1.0 (current: v2.0.2).

Changelog preview (truncated)
## v2.1.0 (2026-09-02)

### Features

- **express**: Let a download keep the original file name
  ([`d8c30c9`](https://github.com/OpenSemanticLab/osw-python/commit/d8c30c99414977c7a8ed6fb0f72118c0b7d3d595))

### Testing

- Rename oold.py to oold_test.py so its tests are collected
  ([`20072a9`](https://github.com/OpenSemanticLab/osw-python/commit/20072a9249cd97126a222c62a70f84e0433343ef))

Preview via python-semantic-release and conventional commits.

@LukasGold LukasGold left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Implemented as asked for

@LukasGold
LukasGold merged commit 9c07c00 into main Sep 2, 2026
12 checks passed
@LukasGold
LukasGold deleted the feat/download-filename-modes branch September 2, 2026 15:59
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.

download / upload of files via osw.express functions should maintain filename

1 participant