-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
60 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,50 @@ | ||
import { create, globSource } from 'kubo-rpc-client'; | ||
import { writeFile } from 'node:fs'; | ||
|
||
async function addDir(){ | ||
const auth = process.env.IPFS_RPC_API_SECRET; | ||
const url = process.env.IPFS_RPC_API_URL; | ||
console.log('auth:', auth) | ||
const auth = process.env.IPFS_RPC_API_SECRET; | ||
const url = process.env.IPFS_RPC_API_URL; | ||
const key = process.env.IPFS_RPC_API_NAME_KEY; | ||
const cids_path = process.env.CIDS_FILE_PATH; | ||
|
||
async function IPFSDeploy(){ | ||
const files = []; | ||
const client = await create({ | ||
url: `${url}/api/v0`, | ||
headers: { | ||
authorization: `Bearer ${auth}`, | ||
} | ||
}) | ||
|
||
for await (const file of client.addAll(globSource(".", "public/**/*"))) { | ||
console.log(file) | ||
console.log('adding files on IPFS..'); | ||
for await (const file of client.addAll(globSource(".", "public/**/*"))) { | ||
files.push({ path: file.path, cid: file.cid.toString() }); | ||
} | ||
|
||
const newPublicDirCID = files[files.length - 1].cid; | ||
console.log(`pinned: ${newPublicDirCID}`); | ||
|
||
let unpinned; | ||
for await (const file of client.pin.ls()) { | ||
unpinned = file.cid.toString(); | ||
if (file.type === 'recursive' && unpinned !== newPublicDirCID) { | ||
await client.pin.rmAll(unpinned); | ||
} | ||
} | ||
|
||
console.log(`unpinned: ${unpinned}`); | ||
|
||
console.log('publishion on IPNS...') | ||
const r = await client.name.publish(`${newPublicDirCID}`, { key }); | ||
|
||
console.log('new version available on:'); | ||
console.log(`IPFS address: https://ipfs.io/ipfs/${newPublicDirCID}`); | ||
console.log(`IPNS address: https://ipfs.io/ipns/${r.name}`); | ||
|
||
console.log(`saving unpinned and pinned CIDs in ${save_dir}`) | ||
await writeFile(save_dir, `${unpinned}\n${newPublicDirCID}`, err => { | ||
if (err) throw err; | ||
console.log(`${save_dir} has been saved`); | ||
}); | ||
} | ||
|
||
addDir() | ||
IPFSDeploy(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters