diff --git a/README.md b/README.md index db938de..5ac1174 100644 --- a/README.md +++ b/README.md @@ -387,6 +387,8 @@ Examples: ```bash arena upload photo.jpg --channel my-channel arena upload photo.jpg --channel my-channel --title "Cover" --description "Homepage image" +arena upload photo.jpg --channel my-channel --alt-text "Cover image" --insert-at 1 +arena upload photo.jpg --channel my-channel --original-source-url https://source.com --original-source-title "Original" ``` Options: @@ -394,6 +396,10 @@ Options: - `--channel ` (required) - `--title ` - `--description ` +- `--alt-text ` +- `--original-source-url ` +- `--original-source-title ` +- `--insert-at ` #### `batch` diff --git a/src/commands/upload.tsx b/src/commands/upload.tsx index 3c100c2..d3e6ab5 100644 --- a/src/commands/upload.tsx +++ b/src/commands/upload.tsx @@ -4,15 +4,33 @@ import { client, getData } from "../api/client"; import { Spinner } from "../components/Spinner"; import { useCommand } from "../hooks/use-command"; import { uploadLocalFile } from "../lib/upload"; +import { Metadata } from "../api/types"; interface Props { file: string; channel: string; title?: string; description?: string; + altText?: string; + originalSourceUrl?: string; + originalSourceTitle?: string; + insertAt?: number; + metadata?: Metadata; + connectionMetadata?: Metadata; } -export function UploadCommand({ file, channel, title, description }: Props) { +export function UploadCommand({ + file, + channel, + title, + description, + altText, + originalSourceUrl, + originalSourceTitle, + insertAt, + metadata, + connectionMetadata, +}: Props) { const { data, error, loading } = useCommand(async () => { const { s3Url } = await uploadLocalFile(file); const ch = await getData( @@ -24,9 +42,19 @@ export function UploadCommand({ file, channel, title, description }: Props) { client.POST("/v3/blocks", { body: { value: s3Url, - channel_ids: [ch.id], + channels: [ + { + id: ch.id, + position: insertAt, + metadata: connectionMetadata, + }, + ], title, description, + alt_text: altText, + original_source_url: originalSourceUrl, + original_source_title: originalSourceTitle, + metadata, }, }), ); diff --git a/src/lib/registry.tsx b/src/lib/registry.tsx index 6a697fa..80522c9 100644 --- a/src/lib/registry.tsx +++ b/src/lib/registry.tsx @@ -693,7 +693,7 @@ export const commands: CommandDefinition[] = [ help: [ { usage: - "upload --channel [--title ] [--description ]", + "upload --channel [--title ] [--description ] [--alt-text ] [--original-source-url ] [--original-source-title ] [--insert-at ]", description: "Options", }, { @@ -701,6 +701,28 @@ export const commands: CommandDefinition[] = [ 'upload --channel --title "Title" --description "Notes"', description: "Example", }, + { + usage: 'upload --channel --alt-text "Accessible text"', + description: "Example", + }, + { + usage: + 'upload --channel --original-source-url --original-source-title "Source"', + description: "Example", + }, + { + usage: "upload --channel --insert-at 1", + description: "Example", + }, + { + usage: "upload --channel --metadata status=reviewed", + description: "Example", + }, + { + usage: + "upload --channel --connection-metadata placement=homepage", + description: "Example", + }, ], render(args, flags) { return ( @@ -709,23 +731,48 @@ export const commands: CommandDefinition[] = [ channel={requireFlag(flags, "channel")} title={flag(flags, "title")} description={flag(flags, "description")} + altText={flag(flags, "alt-text")} + originalSourceUrl={flag(flags, "original-source-url")} + originalSourceTitle={flag(flags, "original-source-title")} + insertAt={intFlag(flags, "insert-at")} + metadata={entityMetadataFlag(flags)} + connectionMetadata={entityMetadataFlag(flags, "connection-metadata")} /> ); }, async json(args, flags) { const file = requireArg(args, 0, "file"); const channel = requireFlag(flags, "channel"); - const { s3Url } = await uploadLocalFile(file); + const ch = await getData( client.GET("/v3/channels/{id}", { params: { path: { id: channel } } }), ); + + const { s3Url } = await uploadLocalFile(file); + + const metadata = entityMetadataFlag(flags); + const connectionMetadata = entityMetadataFlag( + flags, + "connection-metadata", + ); + return getData( client.POST("/v3/blocks", { body: { value: s3Url, - channel_ids: [ch.id], + channels: [ + { + id: ch.id, + position: intFlag(flags, "insert-at"), + metadata: connectionMetadata, + }, + ], title: flag(flags, "title"), description: flag(flags, "description"), + alt_text: flag(flags, "alt-text"), + original_source_url: flag(flags, "original-source-url"), + original_source_title: flag(flags, "original-source-title"), + metadata, }, }), ); @@ -2042,8 +2089,26 @@ export const commandHelpDocs: Record = { flag: "--description ", description: "Optional block description", }, + { flag: "--alt-text ", description: "Optional block alt text" }, + { + flag: "--original-source-url ", + description: "Optional original source URL", + }, + { + flag: "--original-source-title ", + description: "Optional original source title", + }, + { + flag: "--insert-at ", + description: "Optional insert position within the channel", + }, + ], + examples: [ + "arena upload photo.jpg --channel my-channel", + 'arena upload photo.jpg --channel my-channel --title "Cover" --description "Homepage image"', + 'arena upload photo.jpg --channel my-channel --alt-text "Cover image" --insert-at 1', + 'arena upload photo.jpg --channel my-channel --original-source-url https://source.com --original-source-title "Original"', ], - examples: ["arena upload photo.jpg --channel my-channel"], seeAlso: ["add", "batch", "import"], }, batch: {