Dynamic website with user functionality

If you add a directory but only one file is new, the adding process will generally be faster. But if you have 1000s of files, while only 1% is newer, it might be faster to write a script that just adds what you want to add.

You can manipulate directories in IPFS with the ipfs object patch commands.

USAGE
  ipfs object patch - Create a new merkledag object based on an existing one.

SYNOPSIS
  ipfs object patch

DESCRIPTION

  'ipfs object patch <root> <cmd> <args>' is a plumbing command used to
  build custom DAG objects. It mutates objects, creating new objects as a
  result. This is the Merkle-DAG version of modifying an object.

SUBCOMMANDS
  ipfs object patch add-link <root> <name> <ref> - Add a link to a given object.
  ipfs object patch append-data <root> <data>    - Append data to the data segment of a dag node.
  ipfs object patch rm-link <root> <link>        - Remove a link from an object.
  ipfs object patch set-data <root> <data>       - Set the data field of an IPFS object.

  Use 'ipfs object patch <subcmd> --help' for more information about each command.

Quick example:

$ tree
.
└── test-directory
    ├── file-a
    └── file-b

$ ipfs add -r test-directory
added QmSJY8R8qM1HWRTxWxtRwtdxTq6Jqgtx5GQ2RvrUJRUoRx test-directory/file-a
added QmeRjufJQ5oNb3PEmDFZeZ9jPuZRbp5Gnaeahcw8ogq7nd test-directory/file-b
added QmVK4zcfWHyEqHmkWqMPNTH1q3LyPndPCoE5PYRfq1V8A2 test-directory

$ echo "c file" >> test-directory/file-c

$ tree
.
└── test-directory
    ├── file-a
    ├── file-b
    └── file-c

1 directory, 3 files

$ ipfs add test-directory/file-c
added QmPrLX9CiHph7yF5ZtU1ypxxdxgNX3RYLhjcJVSqyCTGr3 file-c

$ ipfs object patch add-link QmVK4zcfWHyEqHmkWqMPNTH1q3LyPndPCoE5PYRfq1V8A2 file-c QmPrLX9CiHph7yF5ZtU1ypxxdxgNX3RYLhjcJVSqyCTGr3
QmZm33yVb5uXAMjZDbL7Q1x69ZTFL6e65sMvYof1R7eh1J

What happened on the example above is:

  • Use tree to print the directory structure
  • Add directory with ipfs add
  • Create a new file named file-c
  • Check directory structure again
  • Add just file-c to IPFS
  • Use ipfs object patch add-link to add a new link to our directory object.
  • The output returns from the add-link command is the new hash to our root-directory with the updated link
$ ipfs object patch add-link QmVK4zcfWHyEqHmkWqMPNTH1q3LyPndPCoE5PYRfq1V8A2 file-c QmPrLX9CiHph7yF5ZtU1ypxxdxgNX3RYLhjcJVSqyCTGr3

Translates to

$ ipfs object patch add-link <root-directory> <link-name> <link-hash>

Where root-directory is the hash you want to add a link in.

link-name is the name of that link (for example, the filename)

link-hash is the hash that link should resolve to.

3 Likes

Thank you… I really need to look into this. I do not want to use IPNS for every single file that is modified, that sounds way overkill. Object paths definitely seem like the better solution, so one can reference an updating file using a constant address.

One question would remain if object paths can be protected by keys or passwords, so only the owner can modify it. Of course, with the commands being automatically used by JavaScript as part of the site’s interface and functionality.

Hello, I just found your post and I had something similar in mind. I wanted to use blockstack for user authentication&stuff…
but that requires user to download blockstack browser.
Have you been able to produce any code yet?
Maybe we could do it in a collaboration since I am new to IPFS &Blockchain aswell (got few years of programming expirience)

I haven’t started coding this project yet: Very busy working on other things, getting a browser with IPFS support (including js-ipfs-api) is still tricky at this date, and I need to decide how I’ll be fixing the limitations imposed by lack of a server side processor.

I’ve considered using pubsub as a database for a workaround, similarly to how a normal Apache server would use MySQL. The problem I understand is that pubsub isn’t persistent, so it’s more like TCP where you receive a data packet only once then it’s lost forever. Makes this all the more complicated.

for Database maybe you can check that : https://www.bigchaindb.com/getstarted/

Another new contender in this space is Shift:

https://www.shiftnrg.org/news/news-item/4