diff --git a/pkgs/cli/src/commands/pinata.ts b/pkgs/cli/src/commands/pinata.ts index 41c99cf..dccb967 100644 --- a/pkgs/cli/src/commands/pinata.ts +++ b/pkgs/cli/src/commands/pinata.ts @@ -1,6 +1,9 @@ import { Command } from "commander"; import { getJwt, setJwt } from "../services/pinata"; import { PinataSDK } from "pinata-web3"; +import path from "path"; +import fs from "fs"; +import { startLoading } from "../services/loading"; export const pinataCommands = new Command(); @@ -109,3 +112,29 @@ pinataCommands console.log("URI:", `ipfs://${upload.IpfsHash}`); } ); + +/** + * 画像をipfsにアップロードするコマンド + */ +pinataCommands + .command("uploadImage") + .description("Upload image on ipfs") + .requiredOption("--imagePath ", "Path to image") + .action(async ({ imagePath }) => { + const { jwt } = getJwt(); + + const stop = startLoading(); + + const pinata = new PinataSDK({ pinataJwt: jwt }); + const currentDir = process.cwd(); + const absPath = path.join(currentDir, imagePath); + const stream = fs.createReadStream(absPath); + const upload = await pinata.upload.stream(stream, { + metadata: { name: `TobanCLI_${new Date().getTime()}` }, + }); + + stop(); + + console.log("CID:", upload.IpfsHash); + console.log("URI:", `ipfs://${upload.IpfsHash}`); + }); diff --git a/pkgs/cli/src/image/test.png b/pkgs/cli/src/image/test.png new file mode 100644 index 0000000..fe5f67e Binary files /dev/null and b/pkgs/cli/src/image/test.png differ