Skip to content

Commit

Permalink
Merge pull request #52 from aquiladev/pin
Browse files Browse the repository at this point in the history
Pin input
  • Loading branch information
aquiladev authored Aug 30, 2022
2 parents d4b05b3 + 0240d08 commit 04b4325
Show file tree
Hide file tree
Showing 11 changed files with 52 additions and 49 deletions.
15 changes: 8 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,16 @@ IPFS upload GitHub Action. It allows uploading DApps or content to IPFS in a Git
Parameter |Required |Description
--- |--- |---
`path` |Yes |Directory's path to upload.
`pin` |No |Pin object when adding. (Default `true`)
`pinName` |No |Human name for pin.
`service` |No |Type of target service to upload. Supported services [`ipfs`, `pinata`, `infura`, `filebase`]. Default `ipfs`
`timeout` |No |Request timeout. Default `60000` (1 minute)
`verbose` |No |Level of verbosity [`false` - quiet, `true` - verbose]. Default `false`
`service` |No |Type of target service to upload. Supported services [`ipfs`, `pinata`, `infura`, `filebase`]. (Default `ipfs`)
`timeout` |No |Request timeout. (Default `60000` (1 minute))
`verbose` |No |Level of verbosity [`false` - quiet, `true` - verbose]. (Default `false`)
`host` |No |[ipfs] IPFS host. Default `ipfs.komputing.org`
`port` |No |[ipfs] IPFS host's port. Default `443`
`protocol` |No |[ipfs] IPFS host's protocol. Default `https`
`headers` |No |[ipfs] IPFS headers as json object. Default `{}`
`key` |No |[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. Default `undefined`
`port` |No |[ipfs] IPFS host's port. (Default `443`)
`protocol` |No |[ipfs] IPFS host's protocol. (Default `https`)
`headers` |No |[ipfs] IPFS headers as json object. (Default `{}`)
`key` |No |[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. (Default `undefined`)
`pinataKey` |No |[pinata] API Key. Required for pinata service.
`pinataSecret` |No |[pinata] Secret Key. Required for pinata service.
`pinataPinName` |No |[pinata] Human name for pin. **Obsolete**, use `pinName` instead.
Expand Down
4 changes: 4 additions & 0 deletions action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ inputs:
path:
description: 'Directory path to upload'
required: true
pin:
description: 'Pin object when adding'
required: false
default: true
pinName:
description: 'Human name for pin'
required: false
Expand Down
35 changes: 17 additions & 18 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -144435,15 +144435,15 @@ module.exports = {
const { filebaseKey, filebaseSecret, filebaseBucket } = options;

if (!filebaseKey) {
throw new Error("filebaseKey is empty");
throw new Error("[filebase] Key is empty. (input `filebaseKey`)");
}

if (!filebaseSecret) {
throw new Error("filebaseSecret is empty");
throw new Error("[filebase] Secret is empty. (input `filebaseSecret`)");
}

if (!filebaseBucket) {
throw new Error("filebaseBucket is empty");
throw new Error("[filebase] Bucket is empty. (input `filebaseBucket`)");
}

return { key: filebaseKey, secret: filebaseSecret, bucket: filebaseBucket };
Expand Down Expand Up @@ -144512,11 +144512,13 @@ module.exports = {
builder: async (options) => {
const { infuraProjectId, infuraProjectSecret, headers, timeout } = options;
if (!infuraProjectId) {
throw new Error("[infura] ProjectId is empty");
throw new Error("[infura] ProjectId is empty. (input `infuraProjectId`)");
}

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

const token = Buffer.from(
Expand All @@ -144535,15 +144537,12 @@ module.exports = {
});
},
upload: async (api, options) => {
const { path, pattern, verbose } = options;
const { path, pattern, pin } = options;
const { cid } = await last(
api.addAll(globSource(fsPath.dirname(path), pattern), { pin: true })
api.addAll(globSource(fsPath.dirname(path), pattern), { pin })
);

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

if (verbose) console.log(cid);

return {
cid: cid.toString(),
ipfs: cid.toString(),
Expand All @@ -144570,18 +144569,16 @@ module.exports = {
return create({ host, port, protocol, timeout, headers });
},
upload: async (api, options) => {
const { path, pattern, timeout, verbose, key } = options;
const { path, pattern, pin, timeout, key, verbose } = options;
const { cid } = await last(
api.addAll(globSource(fsPath.dirname(path), pattern), {
pin: true,
pin,
timeout,
})
);

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

if (verbose) console.log(cid);

let _key;
if (key) {
const keys = await api.key.list();
Expand Down Expand Up @@ -144665,11 +144662,11 @@ module.exports = {
builder: async (options) => {
const { pinataKey, pinataSecret } = options;
if (!pinataKey) {
throw new Error("[pinata] API Key is empty");
throw new Error("[pinata] Key is empty. (input `pinataKey`)");
}

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

return pinataSDK(pinataKey, pinataSecret);
Expand Down Expand Up @@ -144713,13 +144710,14 @@ const uploader = __nccwpck_require__(95130);
async function run() {
try {
const path = core.getInput("path");
const pin = core.getInput("pin");
const pinName = core.getInput("pinName");
const service = core.getInput("service");
const host = core.getInput("host");
const port = core.getInput("port");
const protocol = core.getInput("protocol");
const headers = core.getInput("headers");
const key = core.getInput("key");
const pinName = core.getInput("pinName");
const pinataKey = core.getInput("pinataKey");
const pinataSecret = core.getInput("pinataSecret");
const pinataPinName = core.getInput("pinataPinName");
Expand All @@ -144733,13 +144731,14 @@ async function run() {

const options = {
path,
pin,
pinName,
service,
host,
port,
protocol,
headers: JSON.parse(headers || "{}"),
key,
pinName,
pinataKey,
pinataSecret,
pinataPinName,
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ipfs-action",
"version": "0.3.1-alpha.1",
"version": "0.3.1-alpha.2",
"description": "IPFS upload action",
"main": "index.js",
"scripts": {
Expand Down
6 changes: 3 additions & 3 deletions pinners/filebase.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ module.exports = {
const { filebaseKey, filebaseSecret, filebaseBucket } = options;

if (!filebaseKey) {
throw new Error("filebaseKey is empty");
throw new Error("[filebase] Key is empty. (input `filebaseKey`)");
}

if (!filebaseSecret) {
throw new Error("filebaseSecret is empty");
throw new Error("[filebase] Secret is empty. (input `filebaseSecret`)");
}

if (!filebaseBucket) {
throw new Error("filebaseBucket is empty");
throw new Error("[filebase] Bucket is empty. (input `filebaseBucket`)");
}

return { key: filebaseKey, secret: filebaseSecret, bucket: filebaseBucket };
Expand Down
13 changes: 6 additions & 7 deletions pinners/infura.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@ module.exports = {
builder: async (options) => {
const { infuraProjectId, infuraProjectSecret, headers, timeout } = options;
if (!infuraProjectId) {
throw new Error("[infura] ProjectId is empty");
throw new Error("[infura] ProjectId is empty. (input `infuraProjectId`)");
}

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

const token = Buffer.from(
Expand All @@ -30,15 +32,12 @@ module.exports = {
});
},
upload: async (api, options) => {
const { path, pattern, verbose } = options;
const { path, pattern, pin } = options;
const { cid } = await last(
api.addAll(globSource(fsPath.dirname(path), pattern), { pin: true })
api.addAll(globSource(fsPath.dirname(path), pattern), { pin })
);

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

if (verbose) console.log(cid);

return {
cid: cid.toString(),
ipfs: cid.toString(),
Expand Down
6 changes: 2 additions & 4 deletions pinners/ipfs.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,16 @@ module.exports = {
return create({ host, port, protocol, timeout, headers });
},
upload: async (api, options) => {
const { path, pattern, timeout, verbose, key } = options;
const { path, pattern, pin, timeout, key, verbose } = options;
const { cid } = await last(
api.addAll(globSource(fsPath.dirname(path), pattern), {
pin: true,
pin,
timeout,
})
);

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

if (verbose) console.log(cid);

let _key;
if (key) {
const keys = await api.key.list();
Expand Down
4 changes: 2 additions & 2 deletions pinners/pinata.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ module.exports = {
builder: async (options) => {
const { pinataKey, pinataSecret } = options;
if (!pinataKey) {
throw new Error("[pinata] API Key is empty");
throw new Error("[pinata] Key is empty. (input `pinataKey`)");
}

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

return pinataSDK(pinataKey, pinataSecret);
Expand Down
6 changes: 4 additions & 2 deletions runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@ const uploader = require("./uploader");
async function run() {
try {
const path = core.getInput("path");
const pin = core.getInput("pin");
const pinName = core.getInput("pinName");
const service = core.getInput("service");
const host = core.getInput("host");
const port = core.getInput("port");
const protocol = core.getInput("protocol");
const headers = core.getInput("headers");
const key = core.getInput("key");
const pinName = core.getInput("pinName");
const pinataKey = core.getInput("pinataKey");
const pinataSecret = core.getInput("pinataSecret");
const pinataPinName = core.getInput("pinataPinName");
Expand All @@ -26,13 +27,14 @@ async function run() {

const options = {
path,
pin,
pinName,
service,
host,
port,
protocol,
headers: JSON.parse(headers || "{}"),
key,
pinName,
pinataKey,
pinataSecret,
pinataPinName,
Expand Down
6 changes: 3 additions & 3 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("[pinata] API Key is empty");
).rejects.toThrow("[pinata] Key is empty. (input `pinataKey`)");
});

it("throws error when pinataSecret is empty", async () => {
Expand All @@ -57,7 +57,7 @@ describe("filebase", () => {
it("throws error when filebaseKey is empty", async () => {
await expect(
uploader.upload({ ...options, path: "./data", service: "filebase" })
).rejects.toThrow("filebaseKey is empty");
).rejects.toThrow("[filebase] Key is empty. (input `filebaseKey`)");
});

it("throws error when filebaseSecret is empty", async () => {
Expand All @@ -68,6 +68,6 @@ describe("filebase", () => {
service: "filebase",
filebaseKey: ".",
})
).rejects.toThrow("filebaseSecret is empty");
).rejects.toThrow("[filebase] Secret is empty. (input `filebaseSecret`)");
});
});

0 comments on commit 04b4325

Please sign in to comment.