From b7cb033f1b960fd2a329599b455a4c6a0e047908 Mon Sep 17 00:00:00 2001 From: JesseTheRobot Date: Tue, 20 Jun 2023 12:21:22 +0000 Subject: [PATCH] feat: :sparkles: CLI: Add tags option to CLI for upload and upload-dir --- src/node/cli.ts | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/node/cli.ts b/src/node/cli.ts index 9b31b05f..8817a3c3 100644 --- a/src/node/cli.ts +++ b/src/node/cli.ts @@ -19,6 +19,7 @@ program .option("-c, --currency ", "The currency to use") .option("--timeout ", "The timeout (in ms) for API HTTP requests - increase if you get timeouts for upload") .option("--no-confirmation", "Disable confirmations for certain actions") + .option("-t, --tags [value...]", "Tags to include, format ") .option( "--multiplier ", "Adjust the multiplier used for tx rewards - the higher the faster the network will process the transaction.", @@ -92,7 +93,8 @@ program .action(async (file: string) => { try { const bundlr = await init(options, "upload"); - const res = await bundlr.uploadFile(file); + const tags = parseTags(options?.tags); + const res = await bundlr.uploadFile(file, { tags: tags ?? [] }); console.log(`Uploaded to https://arweave.net/${res?.id}`); } catch (err: any) { console.error(`Error whilst uploading file: ${options.debug ? err.stack : err.message} `); @@ -121,11 +123,13 @@ program async function uploadDir(folder: string): Promise { try { const bundler = await init(options, "upload"); + const tags = parseTags(options?.tags); const res = await bundler.uploadFolder(folder, { indexFile: options.indexFile, batchSize: +options.batchSize, interactivePreflight: options.confirmation, keepDeleted: !options.removeDeleted, + manifestTags: tags ?? [], logFunction: async (log): Promise => { console.log(log); }, @@ -137,6 +141,15 @@ async function uploadDir(folder: string): Promise { } } +const parseTags = (arr: string[]): { name: string; value: string }[] | undefined => { + if (!arr) return; + if (arr.length % 2 !== 0) throw new Error(`Tags key is missing a value!`); + return arr.reduce<{ name: string; value: string }[]>((a, v, i) => { + (i + 1) % 2 === 0 ? (a.at(-1)!.value = v) : a.push({ name: v, value: "" }); + return a; + }, []); +}; + program .command("fund") .description("Funds your account with the specified amount of atomic units")