-
Notifications
You must be signed in to change notification settings - Fork 88
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
WIP: issue #213 - load chunks from a dat, prototype #214
Open
ryanramage
wants to merge
5
commits into
mmckegg:master
Choose a base branch
from
ryanramage:dat-chunks
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 4 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
e70983a
issue #213 - load chunks from a dat, prototype
ryanramage 875ba4b
Merge branch 'master' into dat-chunks
ryanramage 7aa3b46
align to suggested changes by mmckegg
ryanramage 72f587b
some ugly style'n but more modal
ryanramage eb0c2a8
starting work on publish of external chunks
ryanramage File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
var fs = require('fs') | ||
var url = require('url') | ||
var path = require('path') | ||
var Dat = require('dat-node') | ||
var smalltalk = require('smalltalk') | ||
var mirror = require('mirror-folder') | ||
var ram = require('random-access-memory') | ||
|
||
module.exports = function (collection, index, context, fileObject, cb) { | ||
smalltalk.prompt('Enter Dat url', '', 'dat://').then(function (value) { | ||
var datDetails = url.parse(value) | ||
var datHash = datDetails.hostname | ||
|
||
var folderPath = fileObject.resolvePath(datHash) | ||
fetchDat(datHash, folderPath, function (err) { | ||
var path = fileObject.resolvePath(datHash + '/index.json') | ||
var externalDescriptor = { | ||
node: 'Node 1', | ||
scale: '$global', | ||
node: 'externalChunk', | ||
src: fileObject.relative(path), | ||
id: 'dat ' + datHash.substring(0, 5), | ||
routes: {output: '$default'} | ||
} | ||
var node = collection.insert(externalDescriptor, index) | ||
awaitResolve(node.loaded, function () { | ||
cb && cb(null, node) | ||
}) | ||
}) | ||
}) | ||
} | ||
|
||
function fetchDat(hash, folderPath, cb) { | ||
fs.mkdirSync(folderPath) | ||
Dat(ram, {key: hash, sparse: true}, function (err, dat) { | ||
if (err) return cb(err) | ||
var network = dat.joinNetwork() | ||
network.once('connection', function () { console.log('Connected') }) | ||
dat.archive.metadata.update(function () { | ||
var progress = mirror({fs: dat.archive, name: '/'}, folderPath, function (err) { | ||
if (err) return cb(err) | ||
dat.leaveNetwork() | ||
dat.close(cb) | ||
}) | ||
progress.on('put', function (src) { | ||
console.log('Downloading', src.name) | ||
}) | ||
}) | ||
console.log(`Downloading: ${dat.key.toString('hex')}\n`) | ||
}) | ||
} | ||
|
||
|
||
function awaitResolve (obs, cb) { | ||
if (obs()) { | ||
cb(obs()) | ||
} else { | ||
var release = obs(function (value) { | ||
if (release) { | ||
release() | ||
cb(value) | ||
} | ||
}) | ||
} | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
var createDatNode = require('./create-dat-node') | ||
|
||
module.exports = { | ||
name: 'dat', | ||
node: 'dat-chunk', | ||
group: 'simpleChunks', | ||
description: 'Load a chunk from dat p2p', | ||
action: (opts, cb) => { | ||
console.log('spwan', opts) | ||
createDatNode(opts.collection, opts.index, opts.context, opts.fileObject, cb) | ||
} | ||
} |
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
.smalltalk { | ||
position: absolute; | ||
z-index: 1; | ||
border: 10px solid springgreen; | ||
background: whitesmoke; | ||
padding: 10px; | ||
border-radius: 10px; | ||
margin-left: 40%; | ||
margin-top: 300px; | ||
} | ||
|
||
.smalltalk input { | ||
width: 380px; | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Like I mentioned in this comment, you might want to include some of these params (particularly shape) in the export itself.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, thats a good idea. I need to start thinking of how to add meta to the chunk so publishers can help people find them. I think for the exported chunk, I will add a property to the index.json called "published". So it can contain published metadata that can be used by the externalDescriptor
so the file might look like this at the top
e9569d6ff35812c3269e55b3be144512ac6bad1f3ec8510fd389afd0fdcd202a/index.json
Later we can start indexing this info into a db and make a search that can help people find stuff.
I think I want to add a 'publish' button to the tab that appears when you edit a chunk.