Skip to content

Instantly share code, notes, and snippets.

@andrewxhill
Created May 18, 2020 15:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andrewxhill/a73c0a23221773fd30326753a7f840c1 to your computer and use it in GitHub Desktop.
Save andrewxhill/a73c0a23221773fd30326753a7f840c1 to your computer and use it in GitHub Desktop.
/**
* 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