diff options
author | Feross Aboukhadijeh <feross@feross.org> | 2014-10-22 10:47:12 +0400 |
---|---|---|
committer | Feross Aboukhadijeh <feross@feross.org> | 2014-10-22 10:47:12 +0400 |
commit | 2a26d392f0cde3ffed5a72e2fbeea8776eb7463c (patch) | |
tree | 6572e6ce2f1034d7fe8c3688403f174a24e42ac7 /lib | |
parent | 2cb0c2804650d562dca8859791def19280c0bf8e (diff) |
server: homepage list files in torrent
Diffstat (limited to 'lib')
-rw-r--r-- | lib/server.js | 23 |
1 files changed, 14 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') |