Skip to content

Commit

Permalink
Merge pull request #30 from nevermined-io/feature/sdk_0196
Browse files Browse the repository at this point in the history
bumping to sdk `v0.19.6`
  • Loading branch information
aaitor authored Mar 15, 2022
2 parents ab425be + 1a9efef commit 8129a13
Show file tree
Hide file tree
Showing 7 changed files with 147 additions and 208 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
with:
node-version: '12'
node-version: '16'
- name: Install dependencies
run: |
yarn install --ignore-engines
Expand Down
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@
same "printed page" as the copyright notice for easier
identification within third-party archives.

Copyright [yyyy] [name of copyright owner]
Copyright 2022 Nevermined AG

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ Commands:
ncli provenance Provenance functions
ncli nfts721 Create and manage NFTs (ERC-721) attached to Nevermined assets
ncli nfts1155 Create and manage NFTs (ERC-1155) attached to Nevermined assets
ncli utils Utility commands to faciliate files management, encryption, etc
Options:
--help Show help [boolean]
Expand Down Expand Up @@ -146,7 +147,7 @@ When you want to connect and interact with a different network of the default (`
## License

```
Copyright 2021 Keyko GmbH
Copyright 2022 Nevermined AG
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@nevermined-io/cli",
"version": "0.2.3",
"version": "0.2.4",
"main": "index.js",
"repository": "[email protected]:nevermined-io/cli.git",
"author": "Nevermined",
Expand All @@ -20,7 +20,7 @@
"ncli": "./dist/src/index.js"
},
"dependencies": {
"@nevermined-io/nevermined-sdk-js": "^0.19.0",
"@nevermined-io/nevermined-sdk-js": "^0.19.7",
"@truffle/hdwallet-provider": "^1.4.1",
"chalk": "^4.1.2",
"cli-docs-generator": "^1.0.7",
Expand Down
20 changes: 9 additions & 11 deletions src/commands/utils/getNftMetadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,23 +71,21 @@ export const getNftMetadata = async (
chalk.dim(`NFT Metadata URL: ${chalk.yellowBright(metadataUrl)}\n`)
)

let metadataContent = '{}'
if (metadataUrl.startsWith('cid://')) {
const metadataContent = await IpfsHelper.get(metadataUrl)
logger.info(
`NFT Metadata: \n${JSON.stringify(
JSON.parse(metadataContent),
null,
2
)}\n`
)
const metadata = await IpfsHelper.get(metadataUrl)
metadataContent = await metadata.text()
} else if (metadataUrl.startsWith('http')) {
const metadataContent = await fetch(metadataUrl)
logger.info(`NFT Metadata: \n${metadataContent}\n`)
const metadata = await fetch(metadataUrl)
metadataContent = await metadata.text()
} else {
logger.warn('Unable to understand URL format')
return StatusCodes.ERROR
}

// Print the metadata
logger.info(
`NFT Metadata: \n${JSON.stringify(JSON.parse(metadataContent), null, 2)}\n`
)

return StatusCodes.OK
}
10 changes: 7 additions & 3 deletions src/utils/IpfsHelper.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const IpfsHttpClientLite = require('ipfs-http-client-lite')
const fetch = require('node-fetch')

const IPFS_GATEWAY = process.env.IPFS_GATEWAY || 'https://ipfs.infura.io:5001'

Expand All @@ -9,8 +10,11 @@ export default class IpfsHelper {
return addResult[0].hash
}

public static async get(cid: string): Promise<string> {
const ipfs = IpfsHttpClientLite(IPFS_GATEWAY)
return await ipfs.cat(cid.replace('cid://', ''))
public static async get(cid: string): Promise<Response> {
const url = IPFS_GATEWAY + '/api/v0/cat?arg=' + cid.replace('cid://', '')
var options = {
method: 'POST'
}
return fetch(url, options)
}
}
Loading

0 comments on commit 8129a13

Please sign in to comment.