mirror of
https://github.com/idanoo/autobrr
synced 2025-07-23 08:49:13 +00:00
feat(irc): manually re-process announces (#1419)
* fix(releases): add manual processing * feat(irc): add re-process button to channel msg * feat(irc): add missing client method * feat(web): change reprocess icon placement --------- Co-authored-by: martylukyy <35452459+martylukyy@users.noreply.github.com>
This commit is contained in:
parent
d9fc163655
commit
be05ffba73
15 changed files with 306 additions and 18 deletions
|
@ -6,8 +6,10 @@ package http
|
|||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/autobrr/autobrr/internal/domain"
|
||||
|
||||
|
@ -25,6 +27,7 @@ type ircService interface {
|
|||
StoreChannel(ctx context.Context, networkID int64, channel *domain.IrcChannel) error
|
||||
RestartNetwork(ctx context.Context, id int64) error
|
||||
SendCmd(ctx context.Context, req *domain.SendIrcCmdRequest) error
|
||||
ManualProcessAnnounce(ctx context.Context, req *domain.IRCManualProcessRequest) error
|
||||
}
|
||||
|
||||
type ircHandler struct {
|
||||
|
@ -54,6 +57,8 @@ func (h ircHandler) Routes(r chi.Router) {
|
|||
r.Post("/cmd", h.sendCmd)
|
||||
r.Post("/channel", h.storeChannel)
|
||||
r.Get("/restart", h.restartNetwork)
|
||||
|
||||
r.Post("/channel/{channel}/announce/process", h.announceProcess)
|
||||
})
|
||||
|
||||
r.HandleFunc("/events", func(w http.ResponseWriter, r *http.Request) {
|
||||
|
@ -185,6 +190,58 @@ func (h ircHandler) sendCmd(w http.ResponseWriter, r *http.Request) {
|
|||
h.encoder.NoContent(w)
|
||||
}
|
||||
|
||||
// announceProcess manually trigger announce process
|
||||
func (h ircHandler) announceProcess(w http.ResponseWriter, r *http.Request) {
|
||||
var (
|
||||
ctx = r.Context()
|
||||
data domain.IRCManualProcessRequest
|
||||
)
|
||||
|
||||
paramNetworkID := chi.URLParam(r, "networkID")
|
||||
if paramNetworkID == "" {
|
||||
h.encoder.StatusResponse(w, http.StatusBadRequest, map[string]interface{}{
|
||||
"code": "BAD_REQUEST_PARAMS",
|
||||
"message": "parameter networkID missing",
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
networkID, err := strconv.Atoi(paramNetworkID)
|
||||
if err != nil {
|
||||
h.encoder.Error(w, err)
|
||||
return
|
||||
}
|
||||
|
||||
paramChannel := chi.URLParam(r, "channel")
|
||||
if paramChannel == "" {
|
||||
h.encoder.StatusResponse(w, http.StatusBadRequest, map[string]interface{}{
|
||||
"code": "BAD_REQUEST_PARAMS",
|
||||
"message": "parameter channel missing",
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
if err := json.NewDecoder(r.Body).Decode(&data); err != nil {
|
||||
h.encoder.Error(w, err)
|
||||
return
|
||||
}
|
||||
|
||||
data.NetworkId = int64(networkID)
|
||||
data.Channel = paramChannel
|
||||
|
||||
// we cant pass # as an url parameter so the frontend has to strip it
|
||||
if !strings.HasPrefix("#", data.Channel) {
|
||||
data.Channel = fmt.Sprintf("#%s", data.Channel)
|
||||
}
|
||||
|
||||
if err := h.service.ManualProcessAnnounce(ctx, &data); err != nil {
|
||||
h.encoder.Error(w, err)
|
||||
return
|
||||
}
|
||||
|
||||
h.encoder.NoContent(w)
|
||||
}
|
||||
|
||||
func (h ircHandler) storeChannel(w http.ResponseWriter, r *http.Request) {
|
||||
var (
|
||||
ctx = r.Context()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue