feat(file): accept stdin and http(s) URLs as upload sources#31
Merged
Conversation
Previously `notion file upload` only worked with a local filesystem
path. To upload something that lived behind a URL (chat attachment, CI
artifact, object-storage direct link) you had to curl to a tmp file
first. To pipe bytes into Notion you couldn't at all.
This change introduces a fileSource abstraction and three loaders:
<path> local file (existing behavior, unchanged)
- read from stdin (requires --name)
http(s)://... HTTP GET, follows redirects, reads Content-Type
and Content-Disposition filename if present
A new --name flag overrides the filename in all three modes. It is
required for stdin (we can't guess) and recommended for URLs whose
path segment is opaque (e.g. /download?id=123).
Deliberately scoped out of this PR (use a curl-pipe for these):
- custom auth headers for the URL loader
- chunked / streaming upload (single-part, same as before)
Tests use httptest for URL loading, os.Pipe to redirect stdin, and
integration tests wire uploadFromAny through the existing fileUploadAPI
mock to prove every source funnels into the same two-step upload flow.
Closes #26
1be49cd to
8ba87cf
Compare
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.
What
Let
notion file uploadaccept three kinds of source:<path>-http(s)://…Plus a new
--name <filename>flag to override the filename (required for stdin, optional for URLs whose path segment is opaque).Why
Tracked in #26. Before this PR, uploading anything behind a URL required a manual two-step with
curl -o /tmp/... && notion file upload /tmp/... && rm. And stdin wasn't supported at all, so pipelines likegh run view --log | notion file upload - --name run.logwere impossible.Changes
cmd/file.gorefactored around afileSourceabstraction. Three loaders funnel into a singleuploadFromSource(api, src, targetID)function that performs the existing two-step create + send + (optional) attach flow.loadSourceFromPath— unchanged semantics, preserved for legacy callers (uploadFileback-compat shim still works).loadSourceFromStdin— requires--name; rejects empty stdin up-front.loadSourceFromURL— readsContent-Type, derives filename fromContent-Dispositionor URL path, strips query/hash, handles non-2xx with a clear error. Scheme + path cuts meanhttps://x.com/sensibly falls back todownloadinstead ofx.com.Deliberately out of scope for this PR (the curl-pipe still works for these):
single_partmode, unchanged).Test plan
httptestservers for URL success,Content-Dispositionfilename extraction, and 404 propagation.os.Pipestdin redirection for stdin tests.POST /v1/file_uploads→UploadFileContentsequence as a local file.Closes #26