feat(block): --image-file / --image-upload (and friends) for append/insert#30
Merged
Conversation
…nsert
Before this change there was no first-class CLI path to turn an uploaded
file into a block. Users had to run `notion file upload`, capture the
id, then hand-craft a PATCH /v1/blocks/<id>/children JSON body and send
it via `notion api`. The existing --image-url only accepted external
http(s) links.
This PR adds a symmetric triple for every media type Notion supports:
--image-url / --image-file / --image-upload
--file-url / --file-file / --file-upload
--video-url / --video-file / --video-upload
--audio-url / --audio-file / --audio-upload
--pdf-url / --pdf-file / --pdf-upload
Semantics:
--<kind>-url http(s) external URL → block.<kind>.type = external
--<kind>-file local path → upload then embed
--<kind>-upload existing file_upload id → embed directly
Flags are mutually exclusive with each other and with --file/positional
text. --caption works with any of them.
Implementation lives in cmd/media_source.go:
- registerMediaFlags: adds the 15 flags + --caption to a cobra command.
- resolveMediaSource: validates, returns the single active source.
- mediaSource.Build: performs the upload (for --*-file) and assembles
the final block map.
The legacy --image-url flag and its validator/builder are now thin
back-compat wrappers around the new helpers, so existing tests and
usage keep working byte-for-byte.
Closes #23
1ddb106 to
dec1330
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
Add first-class CLI paths to embed uploaded files as Notion blocks — no more hand-written
notion api PATCH /v1/blocks/...JSON for the upload-then-embed flow.Why
Tracked in #23. After
notion file upload, there was no way to insert the result as an image / file / video / audio / pdf block. Existing--image-urlonly took external http(s) URLs. The workaround was to drop tonotion apiwith a hand-written block spec. Agent workflows that produce charts/diagrams hit this constantly.Changes
Symmetric triple for every media kind:
--<kind>-url <URL>--<kind>-file <path>--<kind>-upload <id>file_uploadid…where
<kind>is one ofimage,file,video,audio,pdf.--captionworks with all of them.New file
cmd/media_source.go:registerMediaFlags(cmd)— adds the 15 flags +--captionin one call.resolveMediaSource(cmd, filePath, text)— picks the single active source, validates mutual exclusion and conflicts with--file/ positional text, rejects non-http(s) URLs.mediaSource.Build(c)— performs any upload step and returns the final block map.The legacy
--image-urland its helpers are now thin back-compat wrappers around the new plumbing, so existing tests and invocations stay byte-for-byte identical.Examples
Test plan
TestMediaSource_Build_File_UploadsAndReferencesverifies that--image-fileperforms exactly onePOST /v1/file_uploadsand does not patch the parent (the caller's append/insert path is responsible for that).Closes #23