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

In 01_Tutorial I have some confusion #160

Open
@Gezi-lzq

Description

@Gezi-lzq

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));

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions