Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/webtorrent/webtorrent.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFeross Aboukhadijeh <feross@feross.org>2014-10-22 10:47:12 +0400
committerFeross Aboukhadijeh <feross@feross.org>2014-10-22 10:47:12 +0400
commit2a26d392f0cde3ffed5a72e2fbeea8776eb7463c (patch)
tree6572e6ce2f1034d7fe8c3688403f174a24e42ac7
parent2cb0c2804650d562dca8859791def19280c0bf8e (diff)
server: homepage list files in torrent
-rw-r--r--lib/server.js23
-rw-r--r--package.json1
2 files changed, 15 insertions, 9 deletions
diff --git a/lib/server.js b/lib/server.js
index 0f59aa2..e15f78e 100644
--- a/lib/server.js
+++ b/lib/server.js
@@ -33,20 +33,25 @@ module.exports = function Server (torrent, opts) {
var pathname = url.parse(req.url).pathname
if (pathname === '/favicon.ico') return res.end()
- if (pathname === '/') {
- return res.end('TODO: list files')
- }
-
- var index = Number(pathname.slice(1))
- if (Number.isNaN(index) || index >= torrent.files.length) {
- res.statusCode = 404
- return res.end()
- }
if (torrent.ready) onReady()
else torrent.once('ready', onReady)
function onReady () {
+
+ if (pathname === '/') {
+ res.setHeader('Content-Type', 'text/html')
+ return res.end('<h1>WebTorrent</h1><ol>' + torrent.files.map(function (file, i) {
+ return '<li><a href="/' + i + '">' + file.name + '</a></li>'
+ }).join('<br>') + '</ol>')
+ }
+
+ var index = Number(pathname.slice(1))
+ if (Number.isNaN(index) || index >= torrent.files.length) {
+ res.statusCode = 404
+ return res.end()
+ }
+
var file = torrent.files[index]
res.setHeader('Accept-Ranges', 'bytes')
diff --git a/package.json b/package.json
index c3a033d..16c73e3 100644
--- a/package.json
+++ b/package.json
@@ -71,6 +71,7 @@
"bittorrent-tracker": "^2.5.0",
"brfs": "^1.2.0",
"browserify": "^6.1.0",
+ "portfinder": "^0.2.1",
"run-auto": "^1.0.0",
"tape": "2.x",
"uglify-js": "^2.4.15",