109 points · by fiatjaf · 8y ago · 80 comments
Don't do this:
module.exports = IPFSDropzone
Do this (and change documentation accordingly) module.exports = {IPFSDropzone}
or to go full ES6 do this export {IPFSDropzone};
add the package babel-env and add this script to package.json: "scripts": {
"prepublish": "node node_modules/babel-cli/bin/babel *.js -d build/"
},
and change main to "build/index.js".Run "npm run prepublish" to test.
Edit: Now that I think of it, compiling with babel is probably unnecessary. But it doesn't hurt and can help old setups.
> module.exports = IPFSDropzone
> Do this (and change documentation accordingly)
> module.exports = {IPFSDropzone}
Why? Exporting a single class for this kind of lib is preferable. I'd do:
export default IPFSDropzone;
See react-dropzone which does this [1]. (For that matter the author's questions around project setup would probably be answered by looking at react-dropzone's which looks pretty good).Also with npm scripts, local deps that expose executables are added to your PATH so you can call them directly, e.g.
"prepublish": "babel *.js -d build/"
[1] https://github.com/react-dropzone/react-dropzone/blob/master...Additionally, ES6 default exports don't mix well with commonJS, sometimes I have to add require('foo').default for no apparent reason.
> Also with npm scripts, local deps that expose executables are added to your PATH
I think it didn't work reliably on windows or cygwin or something. I just tried and it works everywhere. Good to know! The only gotcha is that ";" and "&&" must have spaces around.
* If I go ES6 I'll require all people importing it to also use an ES6 module bundler -- which means Babel only, or Rollup, which never works.
* If I precompile and expect non-Babel people to use the precompiled then these people will have duplicated dependencies everywhere.
Not complaining, but all this compatibility mess seems hard to me. I use Browserify!
But I do see ES6 modules in the wild, some of them I'm using with other languages. So I guess it's fine to leave it as-is. Or if you want to ensure maximum compatibility, use babel as I suggested but add the sources to .npmignore so they're not duplicated in the published packages.
1. You add the files to your own node. This is how content gets added, but obviously it only lasts as long as your node is connected to the Internet, just like an ordinary HTTP server.
2. Someone views your content using their node. This causes their node to cache the content temporarily (IIRC for 30 minutes by default) and publish it to other nodes. In theory, if your content got at least one view every half hour it could live on in the users' caches forever.
3. Someone tells their node to pin your content. The node will then keep it permanently (until they unpin it) and serve it whenever it's connected to the Internet. Generally they would do this if they believe it's valuable--either because they want to keep it themselves, or as a public service to make it available to others (for example, pinning the Turkish Wikipedia to help evade censorship).
There are also several pinning services, which you can pay to have them pin your content on their node, in much the same way as you'd pay a hosting provider to serve your content.
The 30 minute interval would apply to the IPFS gateway that someone else would use to download your content (generally a standalone process though I believe there are efforts to make a browser with an embedded gateway). IPFS nodes automatically publish their cache, effectively making an autoscaling distributed CDN. However they will only cache content that they have gotten on behalf of their user; they won't go out and pull random content from the network to host it.
That's just the Go implementation though, there's an implementation entirely in JavaScript, and it would be more than plausible to bake the service into a browser bundle so it works like you describe. However, I believe there's strength in separation personally. The acts of hosting an IPFS gateway, and accessing IPFS content through a gateway, are separate.
From what I've read I could just run the ipfs-daemon on my VPS/hosting server, but is there a user friendly way where I don't have to manually add every file everytime? How easy is it to host a web page with it?
How will does IPFS handle NAT? Could I host my own pinning server on a Raspberry Pi on my home network?
The IPFS daemon handles NAT in much the same way that BitTorrent does: NATed peers will dial out to un-NATed ones to establish a connection. I'm not sure if it also handles UPnP and the like to automatically forward ports if possible.
Personally I believe IPFS to be far superior. BitTorrent has already shown that P2P works great. We don't need tokens for this.
For example, imagine someone has a blog, for which they've paid the network some number of tokens to host. I find one of their articles to be particularly useful, so I pin it on my own node (perhaps with a bandwidth limit if I don't want to get flooded should it become popular) and thus donate a small amount of hosting to the owner of the blog.
It also means you don't need to trust the server to send you the correct content, since everything is automatically checked against its content hash.
It also means it's automatically a CDN - you don't need to be able to serve every single person who wants to look at your content, because they'll all be serving it to each other.
IPFS is not just going to act as an ad-hoc CDN, it's also going to work as a regional CDN.
If someone does a report on your funny video on WGN-TV and ten thousand Chicagoans hit your tiny little website in the next ten minutes, your server will get a few hits because nobody else has it yet. After that the network effect kicks in, and eventually everyone is loading it from an IPFS server somewhere in Chicago. When they start 'retweeting' it and everyone is looking for it, it'll end up scattered all over the country.
Until people lose interest, and then the copies will begin to disappear as the next fad automatically pushes it out.
Try reading their documentation. https://ipfs.io/docs/
I've arbitrarily imposed these limits because the purpose of the app is not for casual visitors to wander around the world browsing everybody's files, they're supposed to go to specific addresses and browse only their files there.
This measure will not protect anyone absolutely, since an "attacker" can easily read the entire database and figure out where are all the files, but it protects users from 99% of the casual visitors.
The code is here: https://github.com/zubairq/visifile/blob/master/public/index...
If someone knows where to plug into Uppy's upload function then it should be really easy.