Skip to content

Commit

Permalink
feat: script'n'test
Browse files Browse the repository at this point in the history
  • Loading branch information
Majorfi committed Mar 28, 2024
1 parent d907899 commit 638fe64
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 15 deletions.
45 changes: 30 additions & 15 deletions .github/scripts/push-to-ipfs.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import path from 'path';
import fs from 'fs';

const CHAIN_RECORD_NAME = 'k51qzi5uqu5dljyjy7wm6qdvoqrscpg7t4kjabdm3y8nawvjucpefnoxi25ko0'
const TOKEN_RECORD_NAME = 'k51qzi5uqu5dh311gjp23ymb82owles107sl1z4jmdbzzek6ejjeb8uuso2yil'

try {
if (!process.env.PERSONAL_ACCESS_TOKEN) {
Expand Down Expand Up @@ -57,16 +58,33 @@ const setIPNSRecord = async (cid, retry) => {
}

let cid;
const pathToData = path.join(process.cwd(), 'chains');
async function execute() {
async function executeChains() {
const pathToData = path.join(process.cwd(), 'chains');
const timestamp = new Date().getTime().toString()
const file = path.join(pathToData, '_info.json')
const infoJSON = {
timestamp: timestamp,
record: CHAIN_RECORD_NAME
}
const infoJSON = {timestamp: timestamp, record: CHAIN_RECORD_NAME}
fs.writeFileSync(file, JSON.stringify(infoJSON, null, 2))

console.log(`Uploading directory ${pathToData}`)
const results = await uploadDirectoryToIPFS(pathToData)
if (results) {
for (const item of results) {
if (item.path === '') {
cid = item.cid
break;
}
}
}

await setIPNSRecord(cid.toString(), 0)
}

async function executeTokens() {
const pathToData = path.join(process.cwd(), 'tokens');
const timestamp = new Date().getTime().toString()
const file = path.join(pathToData, '_info.json')
const infoJSON = {timestamp: timestamp, record: TOKEN_RECORD_NAME}
fs.writeFileSync(file, JSON.stringify(infoJSON, null, 2))

console.log(`Uploading directory ${pathToData}`)
const results = await uploadDirectoryToIPFS(pathToData)
Expand All @@ -80,16 +98,13 @@ async function execute() {
}

await setIPNSRecord(cid.toString(), 0)
}

async function execute() {
await executeChains()
await executeTokens()

process.exit(0)
}

execute()
// fleekSdk.ipns().listRecords()
// .then(async (records) => {
// console.log(records)
// })
// .catch((error) => {
// console.error(error)
// process.exit(1)
// })

4 changes: 4 additions & 0 deletions tokens/_info.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"timestamp": "1711648256668",
"record": "k51qzi5uqu5dh311gjp23ymb82owles107sl1z4jmdbzzek6ejjeb8uuso2yil"
}

0 comments on commit 638fe64

Please sign in to comment.