allow to delete torrents
This commit is contained in:
17
main.go
17
main.go
@@ -322,6 +322,23 @@ func main() {
|
||||
}{true}, 200)
|
||||
})
|
||||
|
||||
mux.HandleFunc("DELETE /api/torrents/{id}", func(w http.ResponseWriter, r *http.Request) {
|
||||
torrentId, err := strconv.Atoi(r.PathValue("id"))
|
||||
if err != nil {
|
||||
http.Error(w, err.Error(), 500)
|
||||
return
|
||||
}
|
||||
|
||||
if err := m.DeleteTorrentById(int64(torrentId)); err != nil {
|
||||
http.Error(w, err.Error(), 404)
|
||||
return
|
||||
}
|
||||
|
||||
sendJSON(w, struct {
|
||||
Ok bool `json:"ok"`
|
||||
}{true}, 200)
|
||||
})
|
||||
|
||||
addr := fmt.Sprintf("%s:%d", *hostname, *port)
|
||||
fmt.Printf("starting http server on %s\n", addr)
|
||||
if err := http.ListenAndServe(addr, mux); err != nil {
|
||||
|
||||
Reference in New Issue
Block a user