From 37560b590120c353f1497d1efdf743a4364c0e60 Mon Sep 17 00:00:00 2001 From: Stephen Smith Date: Sun, 25 Jan 2015 17:04:32 -0500 Subject: [PATCH] Add trackers to stats endpoint. Tack trackers on to magnet links. Fix styles. Closes #50. --- api/api.go | 2 +- api/torrentdb.go | 6 +++--- web/app/scripts/app.js | 19 +++++++++++++++++++ web/app/views/search.html | 8 ++++---- web/app/views/torrent.html | 2 +- 5 files changed, 28 insertions(+), 9 deletions(-) diff --git a/api/api.go b/api/api.go index 9f0f784..5a0cb78 100644 --- a/api/api.go +++ b/api/api.go @@ -24,7 +24,7 @@ func NewAPI() *API { } func (api *API) AddRoutes() { - api.M.Get("/stats", torrentDB.Count) + api.M.Get("/stats", torrentDB.Stats) api.M.Get("/browse", torrentDB.Categories) api.M.Get("/browse/:category", torrentDB.Browse) api.M.Get("/torrent/:btih", torrentDB.Get) diff --git a/api/torrentdb.go b/api/torrentdb.go index 1fe0e42..43adca8 100644 --- a/api/torrentdb.go +++ b/api/torrentdb.go @@ -47,13 +47,13 @@ func (torrentDB *TorrentDB) Close() { torrentDB.session.Close() } -func (torrentDB *TorrentDB) Count(r render.Render) { +func (torrentDB *TorrentDB) Stats(r render.Render) { count, err := torrentDB.collection.Count() if err != nil { - r.JSON(500, map[string]interface{}{"count": "API Error"}) + r.JSON(500, map[string]interface{}{"message": "API Error"}) return } - r.JSON(200, map[string]interface{}{"count": count}) + r.JSON(200, map[string]interface{}{"Count": count, "Trackers": trackers}) } func (torrentDB *TorrentDB) Categories(r render.Render) { diff --git a/web/app/scripts/app.js b/web/app/scripts/app.js index fcde09b..06d322c 100644 --- a/web/app/scripts/app.js +++ b/web/app/scripts/app.js @@ -82,6 +82,25 @@ angular error(function() { // Error! }); + $http.get($rootScope.api + 'stats'). + success(function(data, status) { + if (status === 200) { + $rootScope.stats = data; + $rootScope.magnetTrackers = ''; + for (var index = 0; index < data.Trackers.length; ++index) { + $rootScope.magnetTrackers = $rootScope.magnetTrackers + '&tr=' + data.Trackers[index]; + } + $rootScope.magnetTrackers = $rootScope.magnetTrackers.replace(/\//g, '%2F'); + $rootScope.magnetTrackers = $rootScope.magnetTrackers.replace(/:/g, '%3A'); + console.log($rootScope.magnetTrackers); + } + else { + // Error! + } + }). + error(function() { + // Error! + }); }; init(); }); diff --git a/web/app/views/search.html b/web/app/views/search.html index d9359ff..4428621 100644 --- a/web/app/views/search.html +++ b/web/app/views/search.html @@ -14,7 +14,7 @@ Imported - + Swarm @@ -25,15 +25,15 @@ {{result.Category}} - + {{result.Title}} - + - + {{result.Swarm.Seeders}} {{result.Swarm.Leechers}} diff --git a/web/app/views/torrent.html b/web/app/views/torrent.html index f1d4727..9e3bf9c 100644 --- a/web/app/views/torrent.html +++ b/web/app/views/torrent.html @@ -17,7 +17,7 @@

Torrent Details

{{torrent.Size}} bytes - Download! + Download!

Tracker Stats