Permalink
Browse files

torrent drag and drop works! (close #33)

  • Loading branch information...
feross committed Mar 5, 2014
1 parent 8b491b1 commit b943af8e4e0563b05fc7f3d6f9b71536d8e69c60
Showing with 17 additions and 10 deletions.
  1. +1 −2 lib/app.js
  2. +16 −8 lib/torrent.js
View
@@ -70,8 +70,7 @@ App.prototype.initUI = function () {
files.forEach(function (file) {
util.fileToBuffer(file, function (err, torrent) {
if (err) return console.error(err)
- console.log(torrent)
- // window.torrentManager.addTorrent()
+ window.torrentManager.addTorrent(torrent)
})
})
})
View
@@ -320,11 +320,17 @@ Torrent.prototype._onMetadata = function (metadata) {
try {
var info = bncode.decode(metadata)
- self.torrentFile = bncode.encode({
- 'announce-list': [],
- infoHash: self.infoHash,
- info: info
- })
+
+ if (info.info) {
+ self.torrentFile = info
+ } else {
+ self.torrentFile = bncode.encode({
+ 'announce-list': [],
+ infoHash: self.infoHash,
+ info: info
+ })
+ }
+
self.parsedTorrent = parseTorrent(self.torrentFile)
} catch (e) {
console.error(e)
@@ -343,9 +349,11 @@ Torrent.prototype._onMetadata = function (metadata) {
console.log('done with torrent!')
})
- self.swarm.wires.forEach(function (wire) {
- self._onWireWithMetadata(wire)
- })
+ if (self.swarm) {
+ self.swarm.wires.forEach(function (wire) {
+ self._onWireWithMetadata(wire)
+ })
+ }
}
/**

0 comments on commit b943af8

Please sign in to comment.