feat: add notifications (#216)

* feat: initial notifications support

* chore: update deps
This commit is contained in:
Ludvig Lundgren 2022-04-04 19:13:09 +02:00 committed by GitHub
parent 3185832708
commit 431742fd94
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
20 changed files with 1632 additions and 36 deletions

18
internal/domain/event.go Normal file
View file

@ -0,0 +1,18 @@
package domain
import "time"
type EventsReleasePushed struct {
ReleaseName string
Filter string
Indexer string
InfoHash string
Size uint64
Status ReleasePushStatus
Action string
ActionType ActionType
Rejections []string
Protocol ReleaseProtocol // torrent
Implementation ReleaseImplementation // irc, rss, api
Timestamp time.Time
}

View file

@ -0,0 +1,75 @@
package domain
import (
"context"
"time"
)
type NotificationRepo interface {
List(ctx context.Context) ([]Notification, error)
//FindByType(ctx context.Context, nType NotificationType) ([]Notification, error)
Find(ctx context.Context, params NotificationQueryParams) ([]Notification, int, error)
FindByID(ctx context.Context, id int) (*Notification, error)
Store(ctx context.Context, notification Notification) (*Notification, error)
Update(ctx context.Context, notification Notification) (*Notification, error)
Delete(ctx context.Context, notificationID int) error
}
type Notification struct {
ID int `json:"id"`
Name string `json:"name"`
Type NotificationType `json:"type"`
Enabled bool `json:"enabled"`
Events []string `json:"events"`
Token string `json:"token"`
APIKey string `json:"api_key"`
Webhook string `json:"webhook"`
Title string `json:"title"`
Icon string `json:"icon"`
Username string `json:"username"`
Host string `json:"host"`
Password string `json:"password"`
Channel string `json:"channel"`
Rooms string `json:"rooms"`
Targets string `json:"targets"`
Devices string `json:"devices"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}
type NotificationType string
const (
NotificationTypeDiscord NotificationType = "DISCORD"
NotificationTypeIFTTT NotificationType = "IFTTT"
NotificationTypeJoin NotificationType = "JOIN"
NotificationTypeMattermost NotificationType = "MATTERMOST"
NotificationTypeMatrix NotificationType = "MATRIX"
NotificationTypePushBullet NotificationType = "PUSH_BULLET"
NotificationTypePushover NotificationType = "PUSHOVER"
NotificationTypeRocketChat NotificationType = "ROCKETCHAT"
NotificationTypeSlack NotificationType = "SLACK"
NotificationTypeTelegram NotificationType = "TELEGRAM"
)
type NotificationEvent string
const (
NotificationEventPushApproved NotificationEvent = "PUSH_APPROVED"
NotificationEventPushRejected NotificationEvent = "PUSH_REJECTED"
NotificationEventUpdateAvailable NotificationEvent = "UPDATE_AVAILABLE"
NotificationEventIRCHealth NotificationEvent = "IRC_HEALTH"
)
type NotificationEventArr []NotificationEvent
type NotificationQueryParams struct {
Limit uint64
Offset uint64
Sort map[string]string
Filters struct {
Indexers []string
PushStatus string
}
Search string
}

View file

@ -1501,6 +1501,19 @@ const (
ReleasePushStatusPending ReleasePushStatus = "PENDING" // Initial status
)
func (r ReleasePushStatus) String() string {
switch r {
case ReleasePushStatusApproved:
return "Approved"
case ReleasePushStatusRejected:
return "Rejected"
case ReleasePushStatusErr:
return "Error"
default:
return "Unknown"
}
}
type ReleaseFilterStatus string
const (