Skip to content

Commit 0f0d353

Browse files
authored
feat: Filebase support (#241)
1 parent a7c9ef9 commit 0f0d353

File tree

7 files changed

+131
-3
lines changed

7 files changed

+131
-3
lines changed

md/api.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,11 @@ const cid = await deploy({
6464
host: argv.ipfsCluster && argv.ipfsCluster.host,
6565
username: argv.ipfsCluster && argv.ipfsCluster.username,
6666
password: argv.ipfsCluster && argv.ipfsCluster.password
67+
},
68+
filebase: {
69+
apiKey: argv.filebase && argv.filebase.apiKey,
70+
secretApiKey: argv.filebase && argv.filebase.secretApiKey,
71+
bucket: argv.filebase && argv.filebase.bucket
6772
}
6873
}
6974
})

md/usage.md

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
- [IPFS Cluster](#ipfs-cluster)
1010
- [Pinata](#pinata)
1111
- [C4REX](#c4rex)
12+
- [Filebase](#filebase)
1213
- [DNS Providers Configuration](#dns-providers-configuration)
1314
- [Cloudflare](#cloudflare)
1415
- [DNSimple](#dnsimple)
@@ -69,7 +70,7 @@ Options:
6970
-p, --pinner Pin to this services. If -u is set, these services are
7071
only used to pin and not upload. Defaults to "infura" if
7172
neither -u or -p are set.
72-
[choices: "dappnode", "infura", "ipfs-cluster", "pinata"]
73+
[choices: "dappnode", "infura", "ipfs-cluster", "pinata", "filebase"]
7374
-d, --dns DNS provider whose dnslink TXT field will be updated
7475
[choices: "cloudflare", "dnsimple", "dreamhost"]
7576
-c, --cid Pin this CID instead of uploading
@@ -187,6 +188,18 @@ C4REX is a free to use upload and pinning service provided by [C4REX nearshore s
187188

188189
- Usage: `-u c4rex -p c4rex`
189190

191+
### [Filebase](https://filebase.com)
192+
193+
Filebase is another freemium pinning service. It gives you more control over
194+
what's uploaded. You can delete, label and add custom metadata. This service
195+
requires signup.
196+
197+
- Usage: `-p filebase`
198+
- Environment variables
199+
- `IPFS_DEPLOY_FILEBASE__API_KEY=<api key>`
200+
- `IPFS_DEPLOY_FILEBASE__SECRET_API_KEY=<secret api key>`
201+
- `IPFS_DEPLOY_FILEBASE__BUCKET=<bucket>`
202+
190203
## DNS Providers Configuration
191204

192205
### [Cloudflare](https://cloudflare.com)

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "ipfs-deploy",
3-
"version": "11.2.2",
3+
"version": "11.2.3",
44
"description": "Zero-Config CLI to Deploy Static Websites to IPFS",
55
"keywords": [
66
"ipfs",
@@ -67,6 +67,7 @@
6767
],
6868
"dependencies": {
6969
"@aws-sdk/client-route-53": "^3.53.0",
70+
"@filebase/client": "^0.0.2",
7071
"axios": "^0.26.0",
7172
"byte-size": "^8.1.0",
7273
"chalk": "^4.1.1",
@@ -75,6 +76,7 @@
7576
"dnslink-dnsimple": "^1.0.1",
7677
"dotenv": "^16.0.0",
7778
"dreamhost": "^1.0.5",
79+
"files-from-path": "^0.2.6",
7880
"form-data": "^4.0.0",
7981
"ipfs-http-client": "^50.1.0",
8082
"it-all": "^1.0.6",

src/cli.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,11 @@ const options = {
161161
host: argv.ipfsCluster && argv.ipfsCluster.host,
162162
username: argv.ipfsCluster && argv.ipfsCluster.username,
163163
password: argv.ipfsCluster && argv.ipfsCluster.password
164+
},
165+
filebase: {
166+
apiKey: argv.filebase && argv.filebase.apiKey,
167+
secretApiKey: argv.filebase && argv.filebase.secretApiKey,
168+
bucket: argv.filebase && argv.filebase.bucket
164169
}
165170
},
166171

src/pinners/filebase.js

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
'use strict'
2+
3+
const isEmpty = require('lodash.isempty')
4+
const { FilebaseClient } = require('@filebase/client')
5+
const { filesFromPath } = require('files-from-path')
6+
const { default: axios } = require('axios')
7+
8+
/**
9+
* @typedef {import('./types').FilebaseOptions} FilebaseOptions
10+
* @typedef {import('./types').PinDirOptions} PinDirOptions
11+
*/
12+
13+
const PIN_HASH_URL = 'https://api.filebase.io/v1/ipfs/pins'
14+
15+
class Filebase {
16+
/**
17+
* @param {FilebaseOptions} options
18+
*/
19+
constructor ({ apiKey, secretApiKey, bucket }) {
20+
if ([apiKey, secretApiKey, bucket].some(isEmpty)) {
21+
throw new Error('apiKey and secretApiKey are required for Pinata')
22+
}
23+
24+
this.auth = {
25+
api_key: apiKey,
26+
secret_api_key: secretApiKey,
27+
bucket: bucket
28+
}
29+
30+
this.tokenString = btoa(`${this.auth.api_key}:${this.auth.secret_api_key}:${this.auth.bucket}`)
31+
}
32+
33+
/**
34+
* @param {string} dir
35+
* @param {PinDirOptions|undefined} options
36+
* @returns {Promise<string>}
37+
*/
38+
async pinDir (dir, { tag, hidden = false } = {}) {
39+
const files = []
40+
for await (const file of filesFromPath(dir, { pathPrefix: dir })) {
41+
files.push(file)
42+
}
43+
44+
const cid = await FilebaseClient.storeDirectory(
45+
{ endpoint: 'https://s3.filebase.com', token: this.tokenString },
46+
files,
47+
tag
48+
)
49+
50+
return cid
51+
}
52+
53+
/**
54+
* @param {string} cid
55+
* @param {string|undefined} tag
56+
* @returns {Promise<void>}
57+
*/
58+
async pinCid (cid, tag) {
59+
const body = JSON.stringify({
60+
cid: cid,
61+
name: tag
62+
})
63+
64+
const config = {
65+
headers: {
66+
Authorization: `Bearer ${this.tokenString}`,
67+
'Content-Type': 'application/json'
68+
}
69+
}
70+
71+
await axios.post(PIN_HASH_URL, body, config)
72+
}
73+
74+
/**
75+
* @param {string} cid
76+
* @returns string
77+
*/
78+
gatewayUrl (cid) {
79+
return `https://ipfs.filebase.io/ipfs/${cid}`
80+
}
81+
82+
static get displayName () {
83+
return 'Filebase'
84+
}
85+
86+
get displayName () {
87+
return Filebase.displayName
88+
}
89+
90+
static get slug () {
91+
return 'filebase'
92+
}
93+
}
94+
95+
module.exports = Filebase

src/pinners/index.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,15 @@ const Infura = require('./infura')
55
const IpfsCluster = require('./ipfs-cluster')
66
const Pinata = require('./pinata')
77
const c4rex = require('./c4rex')
8+
const Filebase = require('./filebase')
89

910
const pinners = [
1011
DAppNode,
1112
Infura,
1213
IpfsCluster,
1314
Pinata,
14-
c4rex
15+
c4rex,
16+
Filebase
1517
]
1618

1719
const pinnersMap = pinners.reduce((map, pinner) => {

src/pinners/types.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,9 @@ export interface PinataOptions {
2525
apiKey: string
2626
secretApiKey: string
2727
}
28+
29+
export interface FilebaseOptions {
30+
apiKey: string
31+
secretApiKey: string
32+
bucket: string
33+
}

0 commit comments

Comments
 (0)