Created
May 18, 2020 15:44
-
-
Save andrewxhill/a73c0a23221773fd30326753a7f840c1 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Buckets | |
* | |
* You can now create Buckets for your User. | |
* Bucket contain raw files and documents. | |
*/ | |
const buckets = new Buckets(db.context); | |
const roots = await buckets.list(); | |
const existing = roots.find((bucket) => bucket.name === 'files') | |
const webpage = generateWebpage(this.state.content || ''); | |
/** | |
* Add a simple file | |
* | |
* Alternative formats are here: https://github.com/textileio/js-textile/blob/master/src/normalize.ts#L14 | |
* | |
* We add the file as index.html so that we can render it right in the browser afterwards. | |
*/ | |
const file = { path: '/index.html', content: Buffer.from(webpage) } | |
/** | |
* Push the file to the root of the Files Bucket. | |
*/ | |
const raw = await buckets.pushPath(existing.key!, 'index.html', file) | |
/** | |
* Render the new website at the URL | |
* https://${existing.key}.textile.space | |
* existing.key is the IPNS address of the user's Bucket | |
* the user can push changes to existing.key at any time. | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment