2019-11-16 16:06:34 +01:00
|
|
|
package event
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/leandro-lugaresi/hub"
|
2020-07-04 12:54:35 +02:00
|
|
|
"github.com/photoprism/photoprism/internal/i18n"
|
2019-11-16 16:06:34 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
type Hub = hub.Hub
|
|
|
|
type Data = hub.Fields
|
|
|
|
type Message = hub.Message
|
2019-12-02 00:30:58 +01:00
|
|
|
|
2019-11-16 16:06:34 +01:00
|
|
|
var channelCap = 10
|
|
|
|
var sharedHub = NewHub()
|
|
|
|
|
2019-12-11 14:10:20 +01:00
|
|
|
func NewHub() *Hub {
|
2019-11-16 16:06:34 +01:00
|
|
|
return hub.New()
|
|
|
|
}
|
|
|
|
|
|
|
|
func SharedHub() *Hub {
|
|
|
|
return sharedHub
|
|
|
|
}
|
|
|
|
|
|
|
|
func Error(msg string) {
|
2019-12-02 00:30:58 +01:00
|
|
|
Log.Error(msg)
|
2019-11-16 23:55:56 +01:00
|
|
|
Publish("notify.error", Data{"msg": msg})
|
2019-11-16 16:06:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
func Success(msg string) {
|
2019-12-02 00:30:58 +01:00
|
|
|
Log.Info(msg)
|
2019-11-16 23:55:56 +01:00
|
|
|
Publish("notify.success", Data{"msg": msg})
|
2019-11-16 16:06:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
func Info(msg string) {
|
2019-12-02 00:30:58 +01:00
|
|
|
Log.Info(msg)
|
2019-11-16 23:55:56 +01:00
|
|
|
Publish("notify.info", Data{"msg": msg})
|
2019-11-16 16:06:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
func Warning(msg string) {
|
2019-12-02 00:30:58 +01:00
|
|
|
Log.Warn(msg)
|
2019-11-16 23:55:56 +01:00
|
|
|
Publish("notify.warning", Data{"msg": msg})
|
2019-11-16 16:06:34 +01:00
|
|
|
}
|
|
|
|
|
2020-07-04 12:54:35 +02:00
|
|
|
func ErrorMsg(id i18n.Message, params ...interface{}) {
|
|
|
|
Error(i18n.Msg(id, params...))
|
|
|
|
}
|
|
|
|
|
|
|
|
func SuccessMsg(id i18n.Message, params ...interface{}) {
|
|
|
|
Success(i18n.Msg(id, params...))
|
|
|
|
}
|
|
|
|
|
|
|
|
func InfoMsg(id i18n.Message, params ...interface{}) {
|
|
|
|
Info(i18n.Msg(id, params...))
|
|
|
|
}
|
|
|
|
|
|
|
|
func WarningMsg(id i18n.Message, params ...interface{}) {
|
|
|
|
Warning(i18n.Msg(id, params...))
|
|
|
|
}
|
|
|
|
|
2019-12-11 14:10:20 +01:00
|
|
|
func Publish(event string, data Data) {
|
2019-11-16 16:06:34 +01:00
|
|
|
SharedHub().Publish(Message{
|
|
|
|
Name: event,
|
|
|
|
Fields: data,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func Subscribe(topics ...string) hub.Subscription {
|
|
|
|
return SharedHub().Subscribe(channelCap, topics...)
|
|
|
|
}
|
|
|
|
|
|
|
|
func Unsubscribe(s hub.Subscription) {
|
|
|
|
SharedHub().Unsubscribe(s)
|
|
|
|
}
|