Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cliから適当なパスに置いた画像をipfsにアップロード #136

Merged
merged 3 commits into from
Oct 3, 2024
Merged
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
29 changes: 29 additions & 0 deletions pkgs/cli/src/commands/pinata.ts
Original file line number Diff line number Diff line change
@@ -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();

Expand Down Expand Up @@ -109,3 +112,29 @@ pinataCommands
console.log("URI:", `ipfs://${upload.IpfsHash}`);
}
);

/**
* 画像をipfsにアップロードするコマンド
*/
pinataCommands
.command("uploadImage")
.description("Upload image on ipfs")
.requiredOption("--imagePath <path>", "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}`);
});
Binary file added pkgs/cli/src/image/test.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading