Skip to content

Commit 04b4325

Browse files
authored
Merge pull request #52 from aquiladev/pin
Pin input
2 parents d4b05b3 + 0240d08 commit 04b4325

11 files changed

+52
-49
lines changed

README.md

+8-7
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,16 @@ IPFS upload GitHub Action. It allows uploading DApps or content to IPFS in a Git
99
Parameter |Required |Description
1010
--- |--- |---
1111
`path` |Yes |Directory's path to upload.
12+
`pin` |No |Pin object when adding. (Default `true`)
1213
`pinName` |No |Human name for pin.
13-
`service` |No |Type of target service to upload. Supported services [`ipfs`, `pinata`, `infura`, `filebase`]. Default `ipfs`
14-
`timeout` |No |Request timeout. Default `60000` (1 minute)
15-
`verbose` |No |Level of verbosity [`false` - quiet, `true` - verbose]. Default `false`
14+
`service` |No |Type of target service to upload. Supported services [`ipfs`, `pinata`, `infura`, `filebase`]. (Default `ipfs`)
15+
`timeout` |No |Request timeout. (Default `60000` (1 minute))
16+
`verbose` |No |Level of verbosity [`false` - quiet, `true` - verbose]. (Default `false`)
1617
`host` |No |[ipfs] IPFS host. Default `ipfs.komputing.org`
17-
`port` |No |[ipfs] IPFS host's port. Default `443`
18-
`protocol` |No |[ipfs] IPFS host's protocol. Default `https`
19-
`headers` |No |[ipfs] IPFS headers as json object. Default `{}`
20-
`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`
18+
`port` |No |[ipfs] IPFS host's port. (Default `443`)
19+
`protocol` |No |[ipfs] IPFS host's protocol. (Default `https`)
20+
`headers` |No |[ipfs] IPFS headers as json object. (Default `{}`)
21+
`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`)
2122
`pinataKey` |No |[pinata] API Key. Required for pinata service.
2223
`pinataSecret` |No |[pinata] Secret Key. Required for pinata service.
2324
`pinataPinName` |No |[pinata] Human name for pin. **Obsolete**, use `pinName` instead.

action.yaml

+4
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ inputs:
77
path:
88
description: 'Directory path to upload'
99
required: true
10+
pin:
11+
description: 'Pin object when adding'
12+
required: false
13+
default: true
1014
pinName:
1115
description: 'Human name for pin'
1216
required: false

dist/index.js

+17-18
Original file line numberDiff line numberDiff line change
@@ -144435,15 +144435,15 @@ module.exports = {
144435144435
const { filebaseKey, filebaseSecret, filebaseBucket } = options;
144436144436

144437144437
if (!filebaseKey) {
144438-
throw new Error("filebaseKey is empty");
144438+
throw new Error("[filebase] Key is empty. (input `filebaseKey`)");
144439144439
}
144440144440

144441144441
if (!filebaseSecret) {
144442-
throw new Error("filebaseSecret is empty");
144442+
throw new Error("[filebase] Secret is empty. (input `filebaseSecret`)");
144443144443
}
144444144444

144445144445
if (!filebaseBucket) {
144446-
throw new Error("filebaseBucket is empty");
144446+
throw new Error("[filebase] Bucket is empty. (input `filebaseBucket`)");
144447144447
}
144448144448

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

144518144518
if (!infuraProjectSecret) {
144519-
throw new Error("[infura] ProjectSecret is empty");
144519+
throw new Error(
144520+
"[infura] ProjectSecret is empty. (input `infuraProjectSecret`)"
144521+
);
144520144522
}
144521144523

144522144524
const token = Buffer.from(
@@ -144535,15 +144537,12 @@ module.exports = {
144535144537
});
144536144538
},
144537144539
upload: async (api, options) => {
144538-
const { path, pattern, verbose } = options;
144540+
const { path, pattern, pin } = options;
144539144541
const { cid } = await last(
144540-
api.addAll(globSource(fsPath.dirname(path), pattern), { pin: true })
144542+
api.addAll(globSource(fsPath.dirname(path), pattern), { pin })
144541144543
);
144542144544

144543144545
if (!cid) throw new Error("Content hash is not found.");
144544-
144545-
if (verbose) console.log(cid);
144546-
144547144546
return {
144548144547
cid: cid.toString(),
144549144548
ipfs: cid.toString(),
@@ -144570,18 +144569,16 @@ module.exports = {
144570144569
return create({ host, port, protocol, timeout, headers });
144571144570
},
144572144571
upload: async (api, options) => {
144573-
const { path, pattern, timeout, verbose, key } = options;
144572+
const { path, pattern, pin, timeout, key, verbose } = options;
144574144573
const { cid } = await last(
144575144574
api.addAll(globSource(fsPath.dirname(path), pattern), {
144576-
pin: true,
144575+
pin,
144577144576
timeout,
144578144577
})
144579144578
);
144580144579

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

144583-
if (verbose) console.log(cid);
144584-
144585144582
let _key;
144586144583
if (key) {
144587144584
const keys = await api.key.list();
@@ -144665,11 +144662,11 @@ module.exports = {
144665144662
builder: async (options) => {
144666144663
const { pinataKey, pinataSecret } = options;
144667144664
if (!pinataKey) {
144668-
throw new Error("[pinata] API Key is empty");
144665+
throw new Error("[pinata] Key is empty. (input `pinataKey`)");
144669144666
}
144670144667

144671144668
if (!pinataSecret) {
144672-
throw new Error("[pinata] Secret is empty");
144669+
throw new Error("[pinata] Secret is empty. (input `pinataSecret`)");
144673144670
}
144674144671

144675144672
return pinataSDK(pinataKey, pinataSecret);
@@ -144713,13 +144710,14 @@ const uploader = __nccwpck_require__(95130);
144713144710
async function run() {
144714144711
try {
144715144712
const path = core.getInput("path");
144713+
const pin = core.getInput("pin");
144714+
const pinName = core.getInput("pinName");
144716144715
const service = core.getInput("service");
144717144716
const host = core.getInput("host");
144718144717
const port = core.getInput("port");
144719144718
const protocol = core.getInput("protocol");
144720144719
const headers = core.getInput("headers");
144721144720
const key = core.getInput("key");
144722-
const pinName = core.getInput("pinName");
144723144721
const pinataKey = core.getInput("pinataKey");
144724144722
const pinataSecret = core.getInput("pinataSecret");
144725144723
const pinataPinName = core.getInput("pinataPinName");
@@ -144733,13 +144731,14 @@ async function run() {
144733144731

144734144732
const options = {
144735144733
path,
144734+
pin,
144735+
pinName,
144736144736
service,
144737144737
host,
144738144738
port,
144739144739
protocol,
144740144740
headers: JSON.parse(headers || "{}"),
144741144741
key,
144742-
pinName,
144743144742
pinataKey,
144744144743
pinataSecret,
144745144744
pinataPinName,

package-lock.json

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "ipfs-action",
3-
"version": "0.3.1-alpha.1",
3+
"version": "0.3.1-alpha.2",
44
"description": "IPFS upload action",
55
"main": "index.js",
66
"scripts": {

pinners/filebase.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,15 @@ module.exports = {
77
const { filebaseKey, filebaseSecret, filebaseBucket } = options;
88

99
if (!filebaseKey) {
10-
throw new Error("filebaseKey is empty");
10+
throw new Error("[filebase] Key is empty. (input `filebaseKey`)");
1111
}
1212

1313
if (!filebaseSecret) {
14-
throw new Error("filebaseSecret is empty");
14+
throw new Error("[filebase] Secret is empty. (input `filebaseSecret`)");
1515
}
1616

1717
if (!filebaseBucket) {
18-
throw new Error("filebaseBucket is empty");
18+
throw new Error("[filebase] Bucket is empty. (input `filebaseBucket`)");
1919
}
2020

2121
return { key: filebaseKey, secret: filebaseSecret, bucket: filebaseBucket };

pinners/infura.js

+6-7
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,13 @@ module.exports = {
77
builder: async (options) => {
88
const { infuraProjectId, infuraProjectSecret, headers, timeout } = options;
99
if (!infuraProjectId) {
10-
throw new Error("[infura] ProjectId is empty");
10+
throw new Error("[infura] ProjectId is empty. (input `infuraProjectId`)");
1111
}
1212

1313
if (!infuraProjectSecret) {
14-
throw new Error("[infura] ProjectSecret is empty");
14+
throw new Error(
15+
"[infura] ProjectSecret is empty. (input `infuraProjectSecret`)"
16+
);
1517
}
1618

1719
const token = Buffer.from(
@@ -30,15 +32,12 @@ module.exports = {
3032
});
3133
},
3234
upload: async (api, options) => {
33-
const { path, pattern, verbose } = options;
35+
const { path, pattern, pin } = options;
3436
const { cid } = await last(
35-
api.addAll(globSource(fsPath.dirname(path), pattern), { pin: true })
37+
api.addAll(globSource(fsPath.dirname(path), pattern), { pin })
3638
);
3739

3840
if (!cid) throw new Error("Content hash is not found.");
39-
40-
if (verbose) console.log(cid);
41-
4241
return {
4342
cid: cid.toString(),
4443
ipfs: cid.toString(),

pinners/ipfs.js

+2-4
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,16 @@ module.exports = {
1111
return create({ host, port, protocol, timeout, headers });
1212
},
1313
upload: async (api, options) => {
14-
const { path, pattern, timeout, verbose, key } = options;
14+
const { path, pattern, pin, timeout, key, verbose } = options;
1515
const { cid } = await last(
1616
api.addAll(globSource(fsPath.dirname(path), pattern), {
17-
pin: true,
17+
pin,
1818
timeout,
1919
})
2020
);
2121

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

24-
if (verbose) console.log(cid);
25-
2624
let _key;
2725
if (key) {
2826
const keys = await api.key.list();

pinners/pinata.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@ module.exports = {
1212
builder: async (options) => {
1313
const { pinataKey, pinataSecret } = options;
1414
if (!pinataKey) {
15-
throw new Error("[pinata] API Key is empty");
15+
throw new Error("[pinata] Key is empty. (input `pinataKey`)");
1616
}
1717

1818
if (!pinataSecret) {
19-
throw new Error("[pinata] Secret is empty");
19+
throw new Error("[pinata] Secret is empty. (input `pinataSecret`)");
2020
}
2121

2222
return pinataSDK(pinataKey, pinataSecret);

runner.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,14 @@ const uploader = require("./uploader");
66
async function run() {
77
try {
88
const path = core.getInput("path");
9+
const pin = core.getInput("pin");
10+
const pinName = core.getInput("pinName");
911
const service = core.getInput("service");
1012
const host = core.getInput("host");
1113
const port = core.getInput("port");
1214
const protocol = core.getInput("protocol");
1315
const headers = core.getInput("headers");
1416
const key = core.getInput("key");
15-
const pinName = core.getInput("pinName");
1617
const pinataKey = core.getInput("pinataKey");
1718
const pinataSecret = core.getInput("pinataSecret");
1819
const pinataPinName = core.getInput("pinataPinName");
@@ -26,13 +27,14 @@ async function run() {
2627

2728
const options = {
2829
path,
30+
pin,
31+
pinName,
2932
service,
3033
host,
3134
port,
3235
protocol,
3336
headers: JSON.parse(headers || "{}"),
3437
key,
35-
pinName,
3638
pinataKey,
3739
pinataSecret,
3840
pinataPinName,

uploader.test.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ describe("pinata", () => {
3838
it("throws error when pinataKey is empty", async () => {
3939
await expect(
4040
uploader.upload({ ...options, path: "./data", service: "pinata" })
41-
).rejects.toThrow("[pinata] API Key is empty");
41+
).rejects.toThrow("[pinata] Key is empty. (input `pinataKey`)");
4242
});
4343

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

6363
it("throws error when filebaseSecret is empty", async () => {
@@ -68,6 +68,6 @@ describe("filebase", () => {
6868
service: "filebase",
6969
filebaseKey: ".",
7070
})
71-
).rejects.toThrow("filebaseSecret is empty");
71+
).rejects.toThrow("[filebase] Secret is empty. (input `filebaseSecret`)");
7272
});
7373
});

0 commit comments

Comments
 (0)