|
| 1 | +--- |
| 2 | +title: "Keep Your Ipfs Site Online With Filebase Ipns" |
| 3 | +date: 2024-09-04T22:39:37+08:00 |
| 4 | +draft: false |
| 5 | +tags: |
| 6 | +- ipfs |
| 7 | +- filebase |
| 8 | +- github |
| 9 | +--- |
| 10 | + |
| 11 | +本文会介绍如何接入`filebase`的`IPNS`服务,使你的`IPFS`站点永久在线。 |
| 12 | + |
| 13 | +#### 背景 |
| 14 | + |
| 15 | +周末更新博客时,发现workflow的上传IPFS任务执行失败了。 |
| 16 | + |
| 17 | +``` |
| 18 | +Run aquiladev/ipfs-action@master |
| 19 | +Error: RequestInit: duplex option is required when sending a body. |
| 20 | +node:internal/deps/undici/undici:12502 |
| 21 | + Error.captureStackTrace(err, this); |
| 22 | + ^ |
| 23 | +
|
| 24 | +TypeError: RequestInit: duplex option is required when sending a body. |
| 25 | + at node:internal/deps/undici/undici:12502:13 |
| 26 | + at process.processTicksAndRejections (node:internal/process/task_queues:95:5) |
| 27 | +
|
| 28 | +Node.js v20.13.1 |
| 29 | +``` |
| 30 | + |
| 31 | +查了一下,应该是`Github`更新了NodeJS版本导致的。 |
| 32 | + |
| 33 | +``` |
| 34 | +The following actions use a deprecated Node.js version and will be forced to run on node20: actions/checkout@v2, peaceiris/actions-hugo@v2, peaceiris/actions-gh-pages@v3, aquiladev/ipfs-action@master. For more info: https://github.blog/changelog/2024-03-07-github-actions-all-actions-will-run-on-node20-instead-of-node16-by-default/ |
| 35 | +``` |
| 36 | + |
| 37 | +研究了一下,问题在于[js-ipfs](https://github.com/ipfs/js-ipfs)包的`fetch`方法没有传`duplex`参数导致。 |
| 38 | + |
| 39 | +看`Github`文档,官方已经不再更新了。 |
| 40 | + |
| 41 | +``` |
| 42 | +DEPRECATED: js-IPFS has been superseded by Helia |
| 43 | +``` |
| 44 | + |
| 45 | +搜索一番,发现了两个包[helia](https://github.com/ipfs/helia)和[js-kubo-rpc-client](https://github.com/ipfs/js-kubo-rpc-client)。 |
| 46 | + |
| 47 | +`helia`调用方法有[变化](https://github.com/ipfs/helia/wiki/Migrating-from-js-IPFS),`js-kubo-rpc-client`和原来的`js-ipfs`使用一致。 |
| 48 | + |
| 49 | +捣鼓了一番,没调通,不懂前端的锅,只能放弃,顺便给作者提了个[issue](https://github.com/aquiladev/ipfs-action/issues/78),还是作者来适配吧。 |
| 50 | + |
| 51 | +隔天看的时候,在[Pull requests](https://github.com/aquiladev/ipfs-action/pulls)里发现已经有升级后的提交了。 |
| 52 | + |
| 53 | +哈哈,原来`filebase`官方早就升级适配了,[filebase/ipfs-action](https://github.com/filebase/ipfs-action/tree/master),顺带发现居然还支持了`IPNS`更新,太完美了!!! |
| 54 | + |
| 55 | +#### 折腾记录 |
| 56 | + |
| 57 | +关于`IPNS`的作用,可以参考zu1k大佬的[IPFS 新手指北](https://zu1k.com/posts/tutorials/p2p/ipfs/)。 |
| 58 | + |
| 59 | +关于`IPFS`的部署,可以参考我的[将博客部署到星际文件系统(IPFS)](https://liudon.com/posts/deploy-blog-to-ipfs/)。 |
| 60 | + |
| 61 | +##### 生成密钥 |
| 62 | + |
| 63 | +因为我在云主机上部署了`ipfs`服务,已经有在更新`IPNS`。 |
| 64 | + |
| 65 | +这里引入`filebase`后,相当于多个节点来更新,需要保证`IPNS`地址上一致的。 |
| 66 | + |
| 67 | +所以需要将云主机的密钥导出后,导入到`filebase`。 |
| 68 | + |
| 69 | +之前使用的是`ipfs`默认密钥,这个是无法导出的,所以只能重新生成一个密钥, |
| 70 | +`ipfs-action`为密钥名字,改成你自己的: |
| 71 | + |
| 72 | +``` |
| 73 | +ipfs key gen ipfs-action |
| 74 | +
|
| 75 | +> k51qzi5uqu5dh5kbbff1ucw3ksphpy3vxx4en4dbtfh90pvw4mzd8nfm5r5fnl |
| 76 | +``` |
| 77 | + |
| 78 | +**注意:**`filebase`还不支持`type/size`参数,这里必须使用默认方式创建,否则在`filebase`导入已有密钥会报错。 |
| 79 | + |
| 80 | + |
| 81 | + |
| 82 | +查看已有密钥: |
| 83 | + |
| 84 | +``` |
| 85 | +ipfs key list -l |
| 86 | +> k51qzi5uqu5djx9olgjcibdiurrr09w75v6rdfx0cvwye295k787sssssf0d9d self |
| 87 | +> k51qzi5uqu5dktnw0vc8j9ci42e8gk741ici7ofpv40mo4f6e1ossssnc7uwg ipfs-action |
| 88 | +``` |
| 89 | + |
| 90 | +导出密钥: |
| 91 | + |
| 92 | +``` |
| 93 | +ipfs key export ipfs-action |
| 94 | +``` |
| 95 | + |
| 96 | +执行后,当前目录下会生成一个`ipfs-action.key`文件,内容为二进制。 |
| 97 | + |
| 98 | +`filebase`导入key要求为base64编码,将其转为base64编码: |
| 99 | + |
| 100 | +``` |
| 101 | +cat ipfs-action.key | base64 |
| 102 | +> 5oiR5piv5rWL6K+V |
| 103 | +``` |
| 104 | + |
| 105 | +记住这里的base64内容,下面会用到。 |
| 106 | + |
| 107 | +##### 创建NAME |
| 108 | + |
| 109 | +进入[filebase控制台](https://console.filebase.com/names),点击`Create Name`。 |
| 110 | + |
| 111 | + |
| 112 | + |
| 113 | +``` |
| 114 | +Label: 备注,可以随便填 |
| 115 | +CID: 填入IPFS的cid地址 |
| 116 | +Name Network: 固定选IPNS |
| 117 | +Enabled:固定选Yes |
| 118 | +Import Existing Private Key (Optional):填入第一步的base64内容 |
| 119 | +``` |
| 120 | + |
| 121 | +确定提交。 |
| 122 | + |
| 123 | +#### 修改workflow |
| 124 | + |
| 125 | +``` |
| 126 | +- name: IPFS upload to filebase |
| 127 | +uses: filebase/ipfs-action@master |
| 128 | +with: |
| 129 | + path: ./public |
| 130 | + service: filebase |
| 131 | + pinName: ipfs-action |
| 132 | + filebaseBucket: ${{ secrets.FILEBASE_BUCKET }} |
| 133 | + filebaseKey: ${{ secrets.FILEBASE_KEY }} |
| 134 | + filebaseSecret: ${{ secrets.FILEBASE_SECRET }} |
| 135 | + key: ipfs-action |
| 136 | +``` |
| 137 | + |
| 138 | +新增`key`参数,值为第二步`Label`填入的内容。 |
| 139 | + |
| 140 | +提交后,执行workflow,在执行结果里找到`IPNS`地址。 |
| 141 | + |
| 142 | +``` |
| 143 | +Run filebase/ipfs-action@master |
| 144 | +Parsing options... |
| 145 | +Parsed Options: {"path":"/home/runner/work/***.github.io/***.github.io/public","service":"filebase","host":"ipfs.io","port":"5001","protocol":"https","headers":{},"key":"ipfs-action","pinName":"ipfs-action","pinataKey":"","pinataSecret":"","pinataPinName":"","filebaseBucket":"***","filebaseKey":"***","filebaseSecret":"***","infuraProjectId":"","infuraProjectSecret":"","timeout":"60000","verbose":false,"pattern":"public/**/*"} |
| 146 | +Adding files... |
| 147 | +Starting filebase client |
| 148 | +Started filebase client |
| 149 | +Storing files... |
| 150 | +Stored files... |
| 151 | +CID: bafybeihagzsdupyrecky7bnstzckgf5flxbrdz542jmfaep4xtbj6aa2ea |
| 152 | +Updating name... |
| 153 | +Updated name... |
| 154 | +Done |
| 155 | +Upload to IPFS finished successfully { |
| 156 | + cid: 'bafybeihagzsdupyrecky7bnstzckgf5flxbrdz542jmfaep4xtbj6aa2ea', |
| 157 | + ipfs: 'bafybeihagzsdupyrecky7bnstzckgf5flxbrdz542jmfaep4xtbj6aa2ea', |
| 158 | + ipns: 'k51qzi5uqu5dktnw0vc8j9ci42e8gk741ici7ofpv40mo4f6e1ovj1isnc7uwg' |
| 159 | +} |
| 160 | +``` |
| 161 | + |
| 162 | +#### 更新DNSlink |
| 163 | + |
| 164 | +更新域名的dnslink值: |
| 165 | + |
| 166 | +普通域名 |
| 167 | + |
| 168 | + |
| 169 | + |
| 170 | +eth域名 |
| 171 | + |
| 172 | + |
0 commit comments