diff --git a/pkgs/cli/src/commands/pinata.ts b/pkgs/cli/src/commands/pinata.ts index 41c99cf..74d43fa 100644 --- a/pkgs/cli/src/commands/pinata.ts +++ b/pkgs/cli/src/commands/pinata.ts @@ -1,6 +1,8 @@ import { Command } from "commander"; import { getJwt, setJwt } from "../services/pinata"; import { PinataSDK } from "pinata-web3"; +import path from "path"; +import fs from "fs"; export const pinataCommands = new Command(); @@ -109,3 +111,22 @@ 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 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); + + console.log("CID:", 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