|  | 
| 17 | 17 |  * Can be piped to `pbcopy` on macOS to copy the output to clipboard. | 
| 18 | 18 |  */ | 
| 19 | 19 | 
 | 
| 20 |  | -// parse input | 
| 21 |  | -let input = process.argv[2]; | 
| 22 |  | -if (!input) { | 
| 23 |  | -  console.error("No input provided."); | 
| 24 |  | -  return; | 
| 25 |  | -} | 
|  | 20 | +async function main() { | 
|  | 21 | +  // parse input | 
|  | 22 | +  let input = process.argv[2]; | 
|  | 23 | +  if (!input) { | 
|  | 24 | +    console.error("No input provided."); | 
|  | 25 | +    return; | 
|  | 26 | +  } | 
|  | 27 | + | 
|  | 28 | +  let arweaveTxId; | 
|  | 29 | +  if (input.startsWith("0x")) { | 
|  | 30 | +    // if it starts with 0x, we assume its all hex | 
|  | 31 | +    arweaveTxId = JSON.parse( | 
|  | 32 | +      Buffer.from(input.slice(2), "hex").toString() | 
|  | 33 | +    ).arweave; | 
|  | 34 | +  } else if (input.startsWith("{")) { | 
|  | 35 | +    // if it starts with {, we assume its a JSON string | 
|  | 36 | +    console.log("input", input); | 
|  | 37 | +    arweaveTxId = JSON.parse(input).arweave; | 
|  | 38 | +  } else { | 
|  | 39 | +    // otherwise, we assume its a base64 txid | 
|  | 40 | +    arweaveTxId = input; | 
|  | 41 | +  } | 
| 26 | 42 | 
 | 
| 27 |  | -let arweaveTxId; | 
| 28 |  | -if (input.startsWith("0x")) { | 
| 29 |  | -  // if it starts with 0x, we assume its all hex | 
| 30 |  | -  arweaveTxId = JSON.parse( | 
| 31 |  | -    Buffer.from(input.slice(2), "hex").toString() | 
| 32 |  | -  ).arweave; | 
| 33 |  | -} else if (input.startsWith("{")) { | 
| 34 |  | -  // if it starts with {, we assume its a JSON string | 
| 35 |  | -  console.log("input", input); | 
| 36 |  | -  arweaveTxId = JSON.parse(input).arweave; | 
| 37 |  | -} else { | 
| 38 |  | -  // otherwise, we assume its a base64 txid | 
| 39 |  | -  arweaveTxId = input; | 
|  | 43 | +  // construct the URL | 
|  | 44 | +  // download the actual response from Arweave | 
|  | 45 | +  const url = `https://arweave.net/${arweaveTxId}`; | 
|  | 46 | +  const res = await fetch(url); | 
|  | 47 | +  console.log(await res.text()); | 
| 40 | 48 | } | 
| 41 | 49 | 
 | 
| 42 |  | -// construct the URL | 
| 43 |  | -// download the actual response from Arweave | 
| 44 |  | -const url = `https://arweave.net/${arweaveTxId}`; | 
| 45 |  | -const res = await fetch(url); | 
| 46 |  | -console.log(await res.text()); | 
|  | 50 | +main().catch(console.error); | 
0 commit comments