allow to delete torrents

This commit is contained in:
2026-02-12 23:34:53 +03:00
parent 155cb3e726
commit 738917979e
4 changed files with 59 additions and 1 deletions

17
main.go
View File

@@ -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 {