Repository navigation
zulip: Add fetch_upload() for downloading uploaded files. - #948
Open
harshvardhan178251 wants to merge 2 commits into
Open
harshvardhan178251 wants to merge 2 commits into
harshvardhan178251 wants to merge 2 commits into
Conversation
Collaborator
Author
|
Hi — a quick status check on this issue from my side. My PR #948 adds |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes: #628
Zulip upload responses return a root-relative
/user_uploads/...URL, andGET /api/v1/user_uploads/...returns a JSON temporary-access URL rather than the file, socall_endpoint()cannot be used to download uploads. This PR addsClient.fetch_upload(url_or_path, timeout=None):http(s)URL on this Zulip server (off-origin URLs are rejected) or a server-root-relative/user_uploads/...path (resolved against the server root;self.base_url's trailing/api/is stripped).ZulipErrorif the server doesn't return 200, or if the URL is absolute but off-origin (prevents leaking the bot's credentials).call_endpointand no new API prefix behavior.Design decision worth flagging: the
/api/v1prefix refactor suggested as "one option" in the issue is deliberately not included here — it would break existing bots that rely oncall_endpoint()behaving as before.fetch_upload()is additive only; happy to revisit the refactor as a separate PR.How did you test this PR?
zulip/tests/test_fetch_upload.py(mocked HTTP layer): absolute-URL passthrough, root-relative path resolution against the server root, custom timeout, rejection of bare relative paths, non-200 →ZulipError.zuliptest suite passes locally (17 passed).ruff checkandmypyclean. (The pre-existingzulip_bots/failures were left untouched.)Self-review checklist
Communicate decisions, questions, and potential concerns.
Individual commits are ready for review (see commit discipline).