chore: aria2 notifier

This commit is contained in:
Noah Hsu
2022-06-20 22:29:52 +08:00
parent 6c552a9d62
commit 1b3387ca1a
10 changed files with 92 additions and 29 deletions

View File

@ -1,36 +1,70 @@
package aria2
import "github.com/alist-org/alist/v3/pkg/aria2/rpc"
import (
"github.com/alist-org/alist/v3/pkg/aria2/rpc"
"github.com/alist-org/alist/v3/pkg/generic_sync"
)
const (
Downloading = iota
Paused
Stopped
Completed
Errored
)
type Notify struct {
Signals generic_sync.MapOf[string, chan int]
}
func (n Notify) OnDownloadStart(events []rpc.Event) {
//TODO update task status
panic("implement me")
func NewNotify() *Notify {
return &Notify{Signals: generic_sync.MapOf[string, chan int]{}}
}
func (n Notify) OnDownloadPause(events []rpc.Event) {
//TODO update task status
panic("implement me")
func (n *Notify) OnDownloadStart(events []rpc.Event) {
for _, e := range events {
if signal, ok := n.Signals.Load(e.Gid); ok {
signal <- Downloading
}
}
}
func (n Notify) OnDownloadStop(events []rpc.Event) {
//TODO update task status
panic("implement me")
func (n *Notify) OnDownloadPause(events []rpc.Event) {
for _, e := range events {
if signal, ok := n.Signals.Load(e.Gid); ok {
signal <- Paused
}
}
}
func (n Notify) OnDownloadComplete(events []rpc.Event) {
//TODO get files and upload them
panic("implement me")
func (n *Notify) OnDownloadStop(events []rpc.Event) {
for _, e := range events {
if signal, ok := n.Signals.Load(e.Gid); ok {
signal <- Stopped
}
}
}
func (n Notify) OnDownloadError(events []rpc.Event) {
//TODO update task status
panic("implement me")
func (n *Notify) OnDownloadComplete(events []rpc.Event) {
for _, e := range events {
if signal, ok := n.Signals.Load(e.Gid); ok {
signal <- Completed
}
}
}
func (n Notify) OnBtDownloadComplete(events []rpc.Event) {
//TODO get files and upload them
panic("implement me")
func (n *Notify) OnDownloadError(events []rpc.Event) {
for _, e := range events {
if signal, ok := n.Signals.Load(e.Gid); ok {
signal <- Errored
}
}
}
func (n *Notify) OnBtDownloadComplete(events []rpc.Event) {
for _, e := range events {
if signal, ok := n.Signals.Load(e.Gid); ok {
signal <- Completed
}
}
}