Skip to content
This repository has been archived by the owner on Aug 27, 2020. It is now read-only.

Commit

Permalink
Add trackers to stats endpoint. Tack trackers on to magnet links. Fix…
Browse files Browse the repository at this point in the history
… styles.

Closes #50.
  • Loading branch information
stephen304 committed Jan 25, 2015
1 parent f9ae067 commit 37560b5
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 9 deletions.
2 changes: 1 addition & 1 deletion api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions api/torrentdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
19 changes: 19 additions & 0 deletions web/app/scripts/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
8 changes: 4 additions & 4 deletions web/app/views/search.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<th>
Imported
</th>
<th style="width: 70px;">
<th>
Swarm
</th>
</tr>
Expand All @@ -25,15 +25,15 @@
{{result.Category}}
</td>
<td>
<a href="magnet:?xt=urn:btih:{{result.Btih}}"><i class="fa fa-magnet"></i></a>
<a href="magnet:?xt=urn:btih:{{result.Btih + magnetTrackers}}"><i class="fa fa-magnet"></i></a>
</td>
<td>
<a ui-sref="torrent({btih: '{{result.Btih}}'})">{{result.Title}}</a>
</td>
<td>
<span class="label label-default pull-right" am-time-ago="result.Imported"></span>
<span style="margin-top:4px;" class="label label-default pull-right" am-time-ago="result.Imported"></span>
</td>
<td>
<td style="white-space:nowrap;">
<span class="label label-success">{{result.Swarm.Seeders}}</span> <span class="label label-danger">{{result.Swarm.Leechers}}</span>
</td>
</tr>
Expand Down
2 changes: 1 addition & 1 deletion web/app/views/torrent.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ <h4>Torrent Details</h4>
<span class="label label-default pull-right">{{torrent.Size}} bytes</span>
</li>
</ul>
<a href="magnet:?xt=urn:btih:{{torrent.Btih}}" class="btn btn-success" style="width: 100%;" role="button">Download!</a>
<a href="magnet:?xt=urn:btih:{{torrent.Btih + magnetTrackers}}" class="btn btn-success" style="width: 100%;" role="button">Download!</a>
</div>
<div class="col-md-4">
<h4>Tracker Stats</h4>
Expand Down

0 comments on commit 37560b5

Please sign in to comment.