Initial import.
This commit is contained in:
commit
013f198b74
|
@ -0,0 +1,7 @@
|
|||
{
|
||||
"extends": "standard",
|
||||
"rules": {
|
||||
},
|
||||
"plugins": [
|
||||
]
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
node_modules
|
||||
npm-debug.log
|
||||
dist
|
|
@ -0,0 +1,31 @@
|
|||
<html>
|
||||
<head>
|
||||
<title>Sample App</title>
|
||||
</head>
|
||||
<body>
|
||||
<script>
|
||||
// From https://github.com/LZMA-JS/LZMA-JS (lzma-d.js)
|
||||
/*var e=function(){"use ...*/
|
||||
|
||||
// Data portion made with: webpack && cat dist/bundle.js | lzma | base64 -w 0
|
||||
// IDEA: Load this from a CDN (unpkg.com?), and only resort to the local copy if the CDN copy doesn't load.
|
||||
var compressed_javascript = "data:application/octet-stream;base64,XQAAgAD..."
|
||||
document.body.insertAdjacentHTML('beforeend', new Date() + 'start<br />');
|
||||
|
||||
fetch(compressed_javascript).then(response => {
|
||||
document.body.insertAdjacentHTML('beforeend', new Date() + 'decompressed<br />');
|
||||
compressed_javascript = null
|
||||
return response.arrayBuffer()
|
||||
}).then(buffer => {
|
||||
LZMA.decompress(new Uint8Array(buffer), function(result, error) {
|
||||
document.body.insertAdjacentHTML('beforeend', new Date() + 'starting eval<br />');
|
||||
buffer = null
|
||||
eval(result)
|
||||
})
|
||||
})
|
||||
|
||||
// For conversion of this file to data URI, run: cat index.html | python -c "import urllib, sys; print urllib.quote(sys.stdin.read())"
|
||||
// Then prepend with: "data:text/html;charset=utf-8,"
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,22 @@
|
|||
{
|
||||
"name": "bundle-webpack",
|
||||
"version": "1.0.0",
|
||||
"description": "Bundle js-ipfs with WebPack",
|
||||
"scripts": {
|
||||
"start": "node server.js"
|
||||
},
|
||||
"license": "MIT",
|
||||
"keywords": [],
|
||||
"devDependencies": {
|
||||
"babel-core": "^6.24.1",
|
||||
"babel-loader": "^7.0.0",
|
||||
"babel-preset-stage-0": "^6.24.1",
|
||||
"json-loader": "^0.5.4",
|
||||
"uglifyjs-webpack-plugin": "^1.1.2",
|
||||
"webpack": "^2.5.1",
|
||||
"webpack-dev-server": "^2.4.5"
|
||||
},
|
||||
"dependencies": {
|
||||
"ipfs": "file:../../"
|
||||
}
|
||||
}
|
|
@ -0,0 +1,19 @@
|
|||
'use strict'
|
||||
|
||||
const webpack = require('webpack')
|
||||
const WebpackDevServer = require('webpack-dev-server')
|
||||
const config = require('./webpack.config')
|
||||
|
||||
const wds = new WebpackDevServer(webpack(config), {
|
||||
publicPath: config.output.publicPath,
|
||||
hot: true,
|
||||
historyApiFallback: true
|
||||
})
|
||||
|
||||
wds.listen(3000, 'localhost', (err, result) => {
|
||||
if (err) {
|
||||
throw err
|
||||
}
|
||||
|
||||
console.log('Listening at localhost:3000')
|
||||
})
|
|
@ -0,0 +1,68 @@
|
|||
'use strict'
|
||||
|
||||
const IPFS = require('ipfs')
|
||||
const Repo = require('ipfs-repo')
|
||||
const LevelStore = require('datastore-level')
|
||||
|
||||
function MemoryLevelStore() {
|
||||
return new LevelStore('/memory', {db: require('memdown')})
|
||||
}
|
||||
MemoryLevelStore.prototype = new LevelStore('/memory', {db: require('memdown')})
|
||||
MemoryLevelStore.prototype.constructor = MemoryLevelStore
|
||||
|
||||
const stringToUse = 'Hello world from self-contained, self-hosted js-ipfs!!!'
|
||||
|
||||
function App() {
|
||||
let node
|
||||
|
||||
create()
|
||||
|
||||
function create () {
|
||||
// Create the IPFS node instance
|
||||
|
||||
var repo_name = String(Math.random() + Date.now())
|
||||
var storage_backends = {
|
||||
root: MemoryLevelStore,
|
||||
blocks: MemoryLevelStore,
|
||||
datastore: MemoryLevelStore,
|
||||
}
|
||||
|
||||
node = new IPFS({ repo: new Repo(repo_name, {storageBackends: storage_backends}) })
|
||||
|
||||
node.once('ready', () => {
|
||||
console.log('IPFS node is ready')
|
||||
ops()
|
||||
})
|
||||
}
|
||||
|
||||
function ops () {
|
||||
node.id((err, res) => {
|
||||
if (err) {
|
||||
throw err
|
||||
}
|
||||
|
||||
document.body.insertAdjacentHTML('beforeend',
|
||||
"<h1>Everything is working!</h1>" +
|
||||
"<p>Your ID is <strong>" + res.id + "</strong></p>" +
|
||||
"<p>Your IPFS version is <strong>" + res.agentVersion + "</strong></p>" +
|
||||
"<p>Your IPFS protocol version is <strong>" + res.protocolVersion + "</strong></p>"
|
||||
)
|
||||
})
|
||||
|
||||
node.files.add([Buffer.from(stringToUse)], (err, filesAdded) => {
|
||||
if (err) { console.log("ERROR"); throw err }
|
||||
|
||||
const hash = filesAdded[0].hash
|
||||
document.body.insertAdjacentHTML('beforeend', "<hr /><div>Added a file!<br /><a href=\"https://gateway.ipfs.io/ipfs/" + hash + "\">" + hash + "</a></div>")
|
||||
|
||||
node.files.cat(hash, (err, data) => {
|
||||
if (err) { console.log("ERROR 2"); throw err }
|
||||
document.body.insertAdjacentHTML('beforeend', "<p>Contents of this file: <br />" + data + "</p>")
|
||||
})
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = App
|
||||
|
||||
App()
|
|
@ -0,0 +1,32 @@
|
|||
'use strict'
|
||||
|
||||
var path = require('path')
|
||||
var webpack = require('webpack')
|
||||
const UglifyJSPlugin = require('uglifyjs-webpack-plugin');
|
||||
|
||||
module.exports = {
|
||||
devtool: 'eval',
|
||||
entry: [
|
||||
'./src/index'
|
||||
],
|
||||
output: {
|
||||
path: path.join(__dirname, 'dist'),
|
||||
filename: 'bundle.js',
|
||||
publicPath: '/static/'
|
||||
},
|
||||
plugins: [
|
||||
new UglifyJSPlugin()
|
||||
],
|
||||
module: {
|
||||
loaders: [{
|
||||
test: /\.js$/,
|
||||
// loaders: ['babel-loader'],
|
||||
include: path.join(__dirname, 'src')
|
||||
}, /*{ test: /\.json$/, loader: 'json-loader' }*/]
|
||||
},
|
||||
node: {
|
||||
fs: 'empty',
|
||||
net: 'empty',
|
||||
tls: 'empty'
|
||||
}
|
||||
}
|
Reference in New Issue