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
path: root/lib
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 /lib
parent2cb0c2804650d562dca8859791def19280c0bf8e (diff)
server: homepage list files in torrent
Diffstat (limited to 'lib')
-rw-r--r--lib/server.js23
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')