mirror of
https://github.com/idanoo/autobrr
synced 2025-07-23 08:49:13 +00:00
feat(notifications): add LunaSea support (#1284)
* feat(notifications): add lunasea * fix(web): truncate overflow in PasswordFieldWide * refactor(notifications): centralize msg building Left the building logic in discord.go and notifiarr.go as is because of their unique structure. * refactor: moved components and swapped to outline - Refactored the iconComponentMap to use a single iconStyle variable. * upped size from 4 to 5 * rename NotificationBuilder function
This commit is contained in:
parent
da365da17c
commit
a89a1a55d9
13 changed files with 266 additions and 203 deletions
|
@ -14,7 +14,6 @@ import (
|
|||
"github.com/autobrr/autobrr/internal/domain"
|
||||
"github.com/autobrr/autobrr/pkg/errors"
|
||||
|
||||
"github.com/dustin/go-humanize"
|
||||
"github.com/rs/zerolog"
|
||||
)
|
||||
|
||||
|
@ -26,26 +25,28 @@ type gotifyMessage struct {
|
|||
type gotifySender struct {
|
||||
log zerolog.Logger
|
||||
Settings domain.Notification
|
||||
builder NotificationBuilderPlainText
|
||||
}
|
||||
|
||||
func NewGotifySender(log zerolog.Logger, settings domain.Notification) domain.NotificationSender {
|
||||
return &gotifySender{
|
||||
log: log.With().Str("sender", "gotify").Logger(),
|
||||
Settings: settings,
|
||||
builder: NotificationBuilderPlainText{},
|
||||
}
|
||||
}
|
||||
|
||||
func (s *gotifySender) Send(event domain.NotificationEvent, payload domain.NotificationPayload) error {
|
||||
m := gotifyMessage{
|
||||
Message: s.buildMessage(payload),
|
||||
Title: s.buildTitle(event),
|
||||
Message: s.builder.BuildBody(payload),
|
||||
Title: s.builder.BuildTitle(event),
|
||||
}
|
||||
|
||||
data := url.Values{}
|
||||
data.Set("message", m.Message)
|
||||
data.Set("title", m.Title)
|
||||
|
||||
url := fmt.Sprintf("%v/message?token=%v", s.Settings.Host, s.Settings.Token);
|
||||
url := fmt.Sprintf("%v/message?token=%v", s.Settings.Host, s.Settings.Token)
|
||||
req, err := http.NewRequest(http.MethodPost, url, strings.NewReader(data.Encode()))
|
||||
if err != nil {
|
||||
s.log.Error().Err(err).Msgf("gotify client request error: %v", event)
|
||||
|
@ -116,61 +117,3 @@ func (s *gotifySender) isEnabledEvent(event domain.NotificationEvent) bool {
|
|||
|
||||
return false
|
||||
}
|
||||
|
||||
func (s *gotifySender) buildMessage(payload domain.NotificationPayload) string {
|
||||
msg := ""
|
||||
|
||||
if payload.Subject != "" && payload.Message != "" {
|
||||
msg += fmt.Sprintf("%v\n%v", payload.Subject, payload.Message)
|
||||
}
|
||||
if payload.ReleaseName != "" {
|
||||
msg += fmt.Sprintf("\nNew release: %v", payload.ReleaseName)
|
||||
}
|
||||
if payload.Size > 0 {
|
||||
msg += fmt.Sprintf("\nSize: %v", humanize.Bytes(payload.Size))
|
||||
}
|
||||
if payload.Status != "" {
|
||||
msg += fmt.Sprintf("\nStatus: %v", payload.Status.String())
|
||||
}
|
||||
if payload.Indexer != "" {
|
||||
msg += fmt.Sprintf("\nIndexer: %v", payload.Indexer)
|
||||
}
|
||||
if payload.Filter != "" {
|
||||
msg += fmt.Sprintf("\nFilter: %v", payload.Filter)
|
||||
}
|
||||
if payload.Action != "" {
|
||||
action := fmt.Sprintf("\nAction: %v Type: %v", payload.Action, payload.ActionType)
|
||||
if payload.ActionClient != "" {
|
||||
action += fmt.Sprintf(" Client: %v", payload.ActionClient)
|
||||
}
|
||||
msg += action
|
||||
}
|
||||
if len(payload.Rejections) > 0 {
|
||||
msg += fmt.Sprintf("\nRejections: %v", strings.Join(payload.Rejections, ", "))
|
||||
}
|
||||
|
||||
return msg
|
||||
}
|
||||
|
||||
func (s *gotifySender) buildTitle(event domain.NotificationEvent) string {
|
||||
title := ""
|
||||
|
||||
switch event {
|
||||
case domain.NotificationEventAppUpdateAvailable:
|
||||
title = "Autobrr update available"
|
||||
case domain.NotificationEventPushApproved:
|
||||
title = "Push Approved"
|
||||
case domain.NotificationEventPushRejected:
|
||||
title = "Push Rejected"
|
||||
case domain.NotificationEventPushError:
|
||||
title = "Error"
|
||||
case domain.NotificationEventIRCDisconnected:
|
||||
title = "IRC Disconnected"
|
||||
case domain.NotificationEventIRCReconnected:
|
||||
title = "IRC Reconnected"
|
||||
case domain.NotificationEventTest:
|
||||
title = "Test"
|
||||
}
|
||||
|
||||
return title
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue