alist/internal/aria2/notify.go

71 lines
1.3 KiB
Go
Raw Normal View History

2022-06-20 12:34:58 +00:00
package aria2
2022-06-20 14:29:52 +00:00
import (
"github.com/alist-org/alist/v3/pkg/aria2/rpc"
"github.com/alist-org/alist/v3/pkg/generic_sync"
)
const (
2022-06-21 09:37:02 +00:00
Downloading = iota
2022-06-20 14:29:52 +00:00
Paused
Stopped
Completed
Errored
)
2022-06-20 12:34:58 +00:00
type Notify struct {
2022-06-20 14:29:52 +00:00
Signals generic_sync.MapOf[string, chan int]
}
func NewNotify() *Notify {
return &Notify{Signals: generic_sync.MapOf[string, chan int]{}}
2022-06-20 12:34:58 +00:00
}
2022-06-20 14:29:52 +00:00
func (n *Notify) OnDownloadStart(events []rpc.Event) {
for _, e := range events {
if signal, ok := n.Signals.Load(e.Gid); ok {
signal <- Downloading
}
}
2022-06-20 12:34:58 +00:00
}
2022-06-20 14:29:52 +00:00
func (n *Notify) OnDownloadPause(events []rpc.Event) {
for _, e := range events {
if signal, ok := n.Signals.Load(e.Gid); ok {
signal <- Paused
}
}
2022-06-20 12:34:58 +00:00
}
2022-06-20 14:29:52 +00:00
func (n *Notify) OnDownloadStop(events []rpc.Event) {
for _, e := range events {
if signal, ok := n.Signals.Load(e.Gid); ok {
signal <- Stopped
}
}
2022-06-20 12:34:58 +00:00
}
2022-06-20 14:29:52 +00:00
func (n *Notify) OnDownloadComplete(events []rpc.Event) {
for _, e := range events {
if signal, ok := n.Signals.Load(e.Gid); ok {
signal <- Completed
}
}
2022-06-20 12:34:58 +00:00
}
2022-06-20 14:29:52 +00:00
func (n *Notify) OnDownloadError(events []rpc.Event) {
for _, e := range events {
if signal, ok := n.Signals.Load(e.Gid); ok {
signal <- Errored
}
}
2022-06-20 12:34:58 +00:00
}
2022-06-20 14:29:52 +00:00
func (n *Notify) OnBtDownloadComplete(events []rpc.Event) {
for _, e := range events {
if signal, ok := n.Signals.Load(e.Gid); ok {
signal <- Completed
}
}
2022-06-20 12:34:58 +00:00
}