Skip to content

Commit

Permalink
add infura project params
Browse files Browse the repository at this point in the history
  • Loading branch information
aquiladev committed Aug 14, 2022
1 parent 479c2e1 commit 55ec948
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 12 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ logs
*.log
npm-debug.log*

node_modules
node_modules
10 changes: 8 additions & 2 deletions action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,20 @@ inputs:
description: "[ipfs] IPNS key name. IPNS key will be published when the key parameter is provided. The key will be created if it does not exist"
required: false
pinataKey:
description: '[pinata] Api Key. Required for pinata service'
description: '[pinata] API Key. Required for pinata service'
required: false
pinataSecret:
description: '[pinata] Secret Api Key. Required for pinata service'
description: '[pinata] Secret Key. Required for pinata service'
required: false
pinataPinName:
description: '[pinata] Human name for pin'
required: false
infuraProjectId:
description: '[infura] Project ID. Required for infura service'
required: false
infuraProjectSecret:
description: '[infura] Project Secret. Required for infura service'
required: false
outputs:
hash:
description: 'IPFS CID'
Expand Down
29 changes: 25 additions & 4 deletions pinners/infura.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,41 @@ const path = require("path");
module.exports = {
name: "Infura",
builder: async (options) => {
const { timeout } = options;
const { infuraProjectId, infuraProjectSecret, headers, timeout } = options;
if (!infuraProjectId) {
throw new Error("[infura] ProjectId is empty");
}

if (!infuraProjectSecret) {
throw new Error("[infura] ProjectSecret is empty");
}

const token = Buffer.from(
`${infuraProjectId}:${infuraProjectSecret}`
).toString("base64");

return create({
host: "ipfs.infura.io",
port: "5001",
protocol: "https",
headers: {
...headers,
authorization: `Basic ${token}`,
},
timeout,
});
},
upload: async (api, options) => {
const { path: p, timeout, verbose } = options;

const pattern = fs.lstatSync(p).isDirectory() ? `${path.basename(p)}/**/*` : path.basename(p);
const { cid } = await last(api.addAll(globSource(path.dirname(p), pattern), { pin: true, timeout }));
const pattern = fs.lstatSync(p).isDirectory()
? `${path.basename(p)}/**/*`
: path.basename(p);
const { cid } = await last(
api.addAll(globSource(path.dirname(p), pattern), {
pin: true,
timeout,
})
);

if (!cid) throw new Error("Content hash is not found.");

Expand Down
5 changes: 2 additions & 3 deletions pinners/pinata.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,12 @@ module.exports = {
name: "Pinata",
builder: async (options) => {
const { pinataKey, pinataSecret } = options;

if (!pinataKey) {
throw new Error("PinataKey is empty");
throw new Error("[pinata] API Key is empty");
}

if (!pinataSecret) {
throw new Error("PinataSecret is empty");
throw new Error("[pinata] Secret is empty");
}

return pinataSDK(pinataKey, pinataSecret);
Expand Down
4 changes: 4 additions & 0 deletions runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ async function run() {
const pinataKey = core.getInput("pinataKey");
const pinataSecret = core.getInput("pinataSecret");
const pinataPinName = core.getInput("pinataPinName");
const infuraProjectId = core.getInput("infuraProjectId");
const infuraProjectSecret = core.getInput("infuraProjectSecret");
const timeout = core.getInput("timeout");
const verbose = core.getInput("verbose") === "true";

Expand All @@ -29,6 +31,8 @@ async function run() {
pinataKey,
pinataSecret,
pinataPinName,
infuraProjectId,
infuraProjectSecret,
timeout,
verbose,
};
Expand Down
4 changes: 2 additions & 2 deletions uploader.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ describe("pinata", () => {
it("throws error when pinataKey is empty", async () => {
await expect(
uploader.upload({ ...options, path: "./data", service: "pinata" })
).rejects.toThrow("PinataKey is empty");
).rejects.toThrow("[pinata] API Key is empty");
});

it("throws error when pinataSecret is empty", async () => {
Expand All @@ -49,6 +49,6 @@ describe("pinata", () => {
service: "pinata",
pinataKey: ".",
})
).rejects.toThrow("PinataSecret is empty");
).rejects.toThrow("[pinata] Secret is empty");
});
});

0 comments on commit 55ec948

Please sign in to comment.