Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -387,13 +387,19 @@ 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:

- `--channel <slug|id>` (required)
- `--title <text>`
- `--description <text>`
- `--alt-text <text>`
- `--original-source-url <url>`
- `--original-source-title <text>`
- `--insert-at <n>`

#### `batch`

Expand Down
32 changes: 30 additions & 2 deletions src/commands/upload.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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,
},
}),
);
Expand Down
73 changes: 69 additions & 4 deletions src/lib/registry.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -693,14 +693,36 @@ export const commands: CommandDefinition[] = [
help: [
{
usage:
"upload <file> --channel <ch> [--title <text>] [--description <text>]",
"upload <file> --channel <ch> [--title <text>] [--description <text>] [--alt-text <text>] [--original-source-url <url>] [--original-source-title <text>] [--insert-at <n>]",
description: "Options",
},
{
usage:
'upload <file> --channel <ch> --title "Title" --description "Notes"',
description: "Example",
},
{
usage: 'upload <file> --channel <ch> --alt-text "Accessible text"',
description: "Example",
},
{
usage:
'upload <file> --channel <ch> --original-source-url <url> --original-source-title "Source"',
description: "Example",
},
{
usage: "upload <file> --channel <ch> --insert-at 1",
description: "Example",
},
{
usage: "upload <file> --channel <ch> --metadata status=reviewed",
description: "Example",
},
{
usage:
"upload <file> --channel <ch> --connection-metadata placement=homepage",
description: "Example",
},
],
render(args, flags) {
return (
Expand All @@ -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,
},
}),
);
Expand Down Expand Up @@ -2042,8 +2089,26 @@ export const commandHelpDocs: Record<string, CommandHelpDoc> = {
flag: "--description <text>",
description: "Optional block description",
},
{ flag: "--alt-text <text>", description: "Optional block alt text" },
{
flag: "--original-source-url <url>",
description: "Optional original source URL",
},
{
flag: "--original-source-title <text>",
description: "Optional original source title",
},
{
flag: "--insert-at <n>",
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: {
Expand Down