Skip to content
This repository has been archived by the owner on Dec 18, 2024. It is now read-only.

In 01_Tutorial I have some confusion #160

Open
Gezi-lzq opened this issue Feb 8, 2022 · 0 comments
Open

In 01_Tutorial I have some confusion #160

Gezi-lzq opened this issue Feb 8, 2022 · 0 comments

Comments

@Gezi-lzq
Copy link

Gezi-lzq commented Feb 8, 2022

01_Tutorial/02_Managing_Data.md:

const IPFS = require('ipfs')
const cid = await NPP.addNewPiece("QmNR2n4zywCV61MeMLB6JwPueAPqheqpfiA4fLPMxouEmQ")
cid = new IPFS.CID(cid)
const content = await NPP.node.dag.get(cid)
console.log(content.value.payload)

If I use const cid = ... , I should appear when running. TypeError: Assignment to Constant Variable.
And, I think it should be in the create () method, when the _init () method is called, addawait this._init();

Below is the main.js file example I have written according to the tutorial in learning.
Only by the modifications mentioned above, it can make this file to run normal, I am not sure if the behavior is correct.

const NPP = require("./newpieceplease");
const IPFS = require("ipfs");

async function main() {
  NPP.onready = () => {
    console.log("IPFS node identifier ", NPP.orbitdb.id);
    console.log("database address ", NPP.pieces.id);
  };
  await NPP.create();
  console.log("created");
  // test 
  addPieceTest();
}

async function addPieceTest() {
  let cid = await NPP.addNewPiece(
    "QmNR2n4zywCV61MeMLB6JwPueAPqheqpfiA4fLPMxouEmQ"
  );
  cid = new IPFS.CID(cid);
  const content = await NPP.node.dag.get(cid);
  console.log(content.value.payload);
}
main();

I have modified the AddNewpiece function in order to run, so that I will return to cid atif (existingpiece)

  async addNewPiece(hash, instrument = "Piano") {
    const existingPiece = this.getPieceByHash(hash)
    if (existingPiece) {
-     await this.updatePieceByHash(hash, instrument)
+    const cid = await this.updatePieceByHash(hash, instrument)
+    return cid
    }
    const cid = await this.pieces.put({ hash, instrument })
    return cid;
  }

/01_Tutorial/03_Structuring_Data.md:
Utilizing the practice counter
...
These can be used in your application code like so:

const piece = NPP.getPieceByHash('QmdzDacgJ9EQF9Z8G3L1fzFwiEu255Nm5WiCey9ntrDPSL')
const cid = await NPP.incrementPracticeCounter(piece)
const content = await NPP.node.dag.get(cid)
console.log(content.value.payload)

const content = await NPP.node.dag.get(cid) Should be changed

const content = await NPP.node.dag.get(new IPFS.CID(cid));
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant