Merge branch 'torrents' into 'master'

Add route to list torrents of a user's polochon

See merge request !67
This commit is contained in:
Grégoire Delattre 2017-05-18 11:32:06 +00:00
commit fcf64fb4ee
2 changed files with 22 additions and 0 deletions

View File

@ -42,3 +42,24 @@ func DownloadHandler(env *web.Env, w http.ResponseWriter, r *http.Request) error
return env.RenderOK(w, "Torrent added") return env.RenderOK(w, "Torrent added")
} }
// ListHandler downloads a movie via polochon
func ListHandler(env *web.Env, w http.ResponseWriter, r *http.Request) error {
v := auth.GetCurrentUser(r, env.Log)
user, ok := v.(*users.User)
if !ok {
return env.RenderError(w, errors.New("invalid user type"))
}
client, err := user.NewPapiClient()
if err != nil {
return env.RenderError(w, err)
}
torrents, err := client.GetTorrents()
if err != nil {
return env.RenderError(w, err)
}
return env.RenderJSON(w, torrents)
}

View File

@ -49,6 +49,7 @@ func setupRoutes(env *web.Env) {
// Torrents routes // Torrents routes
env.Handle("/torrents", torrents.DownloadHandler).WithRole(users.UserRole).Methods("POST") env.Handle("/torrents", torrents.DownloadHandler).WithRole(users.UserRole).Methods("POST")
env.Handle("/torrents", torrents.ListHandler).WithRole(users.UserRole).Methods("GET")
// Route to refresh all movies and shows // Route to refresh all movies and shows
env.Handle("/refresh", extmedias.RefreshHandler).WithRole(users.AdminRole).Methods("POST") env.Handle("/refresh", extmedias.RefreshHandler).WithRole(users.AdminRole).Methods("POST")