Merge branch 'removeTorrent' into 'master'
Add remove torrent feature See merge request !74
This commit is contained in:
commit
1ccda506fa
@ -4,6 +4,9 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"strconv"
|
||||||
|
|
||||||
|
"github.com/gorilla/mux"
|
||||||
|
|
||||||
"gitlab.quimbo.fr/odwrtw/canape-sql/src/internal/auth"
|
"gitlab.quimbo.fr/odwrtw/canape-sql/src/internal/auth"
|
||||||
"gitlab.quimbo.fr/odwrtw/canape-sql/src/internal/users"
|
"gitlab.quimbo.fr/odwrtw/canape-sql/src/internal/users"
|
||||||
@ -43,7 +46,7 @@ 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
|
// ListHandler downloads a torrent via polochon
|
||||||
func ListHandler(env *web.Env, w http.ResponseWriter, r *http.Request) error {
|
func ListHandler(env *web.Env, w http.ResponseWriter, r *http.Request) error {
|
||||||
v := auth.GetCurrentUser(r, env.Log)
|
v := auth.GetCurrentUser(r, env.Log)
|
||||||
user, ok := v.(*users.User)
|
user, ok := v.(*users.User)
|
||||||
@ -63,3 +66,31 @@ func ListHandler(env *web.Env, w http.ResponseWriter, r *http.Request) error {
|
|||||||
|
|
||||||
return env.RenderJSON(w, torrents)
|
return env.RenderJSON(w, torrents)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// RemoveHandler removes a torrents via polochon
|
||||||
|
func RemoveHandler(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"))
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get the torrent ID from the URL
|
||||||
|
vars := mux.Vars(r)
|
||||||
|
torrentID, err := strconv.Atoi(vars["id"])
|
||||||
|
if err != nil {
|
||||||
|
return env.RenderError(w, errors.New("invalid argument"))
|
||||||
|
}
|
||||||
|
|
||||||
|
client, err := user.NewPapiClient()
|
||||||
|
if err != nil {
|
||||||
|
return env.RenderError(w, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
err = client.RemoveTorrent(torrentID)
|
||||||
|
if err != nil {
|
||||||
|
return env.RenderError(w, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return env.RenderOK(w, "Torrent removed")
|
||||||
|
}
|
||||||
|
@ -43,7 +43,7 @@ import getRoutes from './routes'
|
|||||||
function mapStateToProps(state) {
|
function mapStateToProps(state) {
|
||||||
let torrentCount = 0;
|
let torrentCount = 0;
|
||||||
if (state.torrentStore.has('torrents')) {
|
if (state.torrentStore.has('torrents')) {
|
||||||
torrentCount = state.torrentStore.has('torrents').size;
|
torrentCount = state.torrentStore.get('torrents').size;
|
||||||
}
|
}
|
||||||
return {
|
return {
|
||||||
username: state.userStore.username,
|
username: state.userStore.username,
|
||||||
|
@ -52,6 +52,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")
|
env.Handle("/torrents", torrents.ListHandler).WithRole(users.UserRole).Methods("GET")
|
||||||
|
env.Handle("/torrents/{id:[0-9]+}", torrents.RemoveHandler).WithRole(users.UserRole).Methods("DELETE")
|
||||||
|
|
||||||
// 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")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user