mirror of
https://github.com/navidrome/navidrome.git
synced 2025-04-15 11:40:36 +03:00
49 lines
827 B
Go
49 lines
827 B
Go
package events
|
|
|
|
import (
|
|
"encoding/json"
|
|
"reflect"
|
|
"strings"
|
|
"time"
|
|
"unicode"
|
|
)
|
|
|
|
type Event interface {
|
|
Name(Event) string
|
|
Data(Event) string
|
|
}
|
|
|
|
type baseEvent struct{}
|
|
|
|
func (e *baseEvent) Name(evt Event) string {
|
|
str := strings.TrimPrefix(reflect.TypeOf(evt).String(), "*events.")
|
|
return str[:0] + string(unicode.ToLower(rune(str[0]))) + str[1:]
|
|
}
|
|
|
|
func (e *baseEvent) Data(evt Event) string {
|
|
data, _ := json.Marshal(evt)
|
|
return string(data)
|
|
}
|
|
|
|
type ScanStatus struct {
|
|
baseEvent
|
|
Scanning bool `json:"scanning"`
|
|
Count int64 `json:"count"`
|
|
FolderCount int64 `json:"folderCount"`
|
|
}
|
|
|
|
type KeepAlive struct {
|
|
baseEvent
|
|
TS int64 `json:"ts"`
|
|
}
|
|
|
|
type RefreshResource struct {
|
|
baseEvent
|
|
Resource string `json:"resource"`
|
|
}
|
|
|
|
type ServerStart struct {
|
|
baseEvent
|
|
StartTime time.Time `json:"startTime"`
|
|
}
|