Skip to content

Commit

Permalink
Remove IPFS size get
Browse files Browse the repository at this point in the history
  • Loading branch information
badkk committed Mar 19, 2021
1 parent 0e5e014 commit 8a7788a
Show file tree
Hide file tree
Showing 7 changed files with 245 additions and 2,938 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
- uses: actions/[email protected]
- name: Crust IPFS pin action
id: pin
uses: crustio/[email protected].7
uses: crustio/[email protected].8
with:
cid: QmevJf2rdNibZCGrgeyVJEM82y5DsXgMDHXM6zBtQ6G4Vj
seeds: ${{ secrets.CRUST_SEEDS }}
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ Decentralized pin your site to Crust IPFS Network from Github Action
## Example usage

```yaml
uses: crustio/ipfs-crust-action@1.0.7
uses: crustio/ipfs-crust-action@v1.0.8
with:
cid: QmevJf2rdNibZCGrgeyVJEM82y5DsXgMDHXM6zBtQ6G4Vj
seeds: ${{ secrets.CRUST_SEEDS }}
Expand Down
3,093 changes: 226 additions & 2,867 deletions dist/index.js

Large diffs are not rendered by default.

24 changes: 12 additions & 12 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
const core = require('@actions/core');
const axios = require('axios');
const { ApiPromise, WsProvider } = require('@polkadot/api');
const { typesBundleForPolkadot, types } = require('@crustio/type-definitions');
const { checkCid, checkSeeds, sendTx, parseObj } = require('./util');
const { checkCid, checkSeeds, sendTx } = require('./util');

async function main() {
// 1. Get all inputs
Expand All @@ -23,16 +22,17 @@ async function main() {
});
await chain.isReadyOrError;

// 4. Get file size
const ipfs = axios.create({
baseURL: ipfsGateway + '/api/v0',
timeout: 60 * 1000, // 1 min
headers: {'Content-Type': 'application/json'},
});
const res = await ipfs.post(`/object/stat?arg=${cid}`);
const objInfo = parseObj(res.data);
const size = objInfo.CumulativeSize;
console.log(`Got IPFS object size: ${size}`);
// 4. Get file size by hard code instead of requsting ipfs.gateway(leads timeout)
// const ipfs = axios.create({
// baseURL: ipfsGateway + '/api/v0',
// timeout: 60 * 1000, // 1 min
// headers: {'Content-Type': 'application/json'},
// });
// const res = await ipfs.post(`/object/stat?arg=${cid}`);
// const objInfo = parseObj(res.data);
// const size = objInfo.CumulativeSize;
const size = 200 * 1024 * 1024; // 200 MB
// console.log(`Got IPFS object size: ${size}`);

// 5. Construct tx
const tx = chain.tx.market.placeStorageOrder(cid, size, 0);
Expand Down
47 changes: 3 additions & 44 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 2 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ipfs-crust-action",
"version": "1.0.7",
"version": "1.0.8",
"description": "Decentralized pin your site to Crust IPFS Network from Github Action",
"main": "dist/index.js",
"scripts": {
Expand All @@ -26,7 +26,6 @@
"@actions/core": "^1.2.6",
"@crustio/type-definitions": "^0.0.5",
"@polkadot/api": "^4.1.1",
"@vercel/ncc": "^0.27.0",
"axios": "^0.21.1"
"@vercel/ncc": "^0.27.0"
}
}
10 changes: 0 additions & 10 deletions util.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,15 +68,6 @@ async function sendTx(tx, seeds) {
});
}

/**
* Parse any object to JSON object
* @param {Object} o any type
* @returns JSONObject
*/
function parseObj(o) {
return JSON.parse(JSON.stringify(o));
}

/* PRIVATE METHODS */
/**
* Load keyring pair with seeds
Expand All @@ -95,5 +86,4 @@ module.exports = {
checkCid,
checkSeeds,
sendTx,
parseObj,
}

0 comments on commit 8a7788a

Please sign in to comment.