mirror of
https://github.com/opencloud-eu/opencloud.git
synced 2026-03-14 02:10:05 -05:00
@@ -28,6 +28,8 @@ type Config struct {
|
||||
Events Events `yaml:"events"`
|
||||
Persistence Persistence `yaml:"persistence"`
|
||||
|
||||
DisableSSE bool `yaml:"disable_sse" env:"USERLOG_DISABLE_SSE" desc:"Disables server-sent events. Clients will no longer be able to connect to the sse endpoint."`
|
||||
|
||||
Context context.Context `yaml:"-"`
|
||||
}
|
||||
|
||||
|
||||
@@ -68,10 +68,13 @@ func NewUserlogService(opts ...Option) (*UserlogService, error) {
|
||||
historyClient: o.HistoryClient,
|
||||
gatewaySelector: o.GatewaySelector,
|
||||
valueClient: o.ValueClient,
|
||||
sse: sse.New(),
|
||||
registeredEvents: make(map[string]events.Unmarshaller),
|
||||
}
|
||||
|
||||
if !ul.cfg.DisableSSE {
|
||||
ul.sse = sse.New()
|
||||
}
|
||||
|
||||
for _, e := range o.RegisteredEvents {
|
||||
typ := reflect.TypeOf(e)
|
||||
ul.registeredEvents[typ.String()] = e
|
||||
@@ -79,8 +82,11 @@ func NewUserlogService(opts ...Option) (*UserlogService, error) {
|
||||
|
||||
ul.m.Route("/ocs/v2.php/apps/notifications/api/v1/notifications", func(r chi.Router) {
|
||||
r.Get("/", ul.HandleGetEvents)
|
||||
r.Get("/sse", ul.HandleSSE)
|
||||
r.Delete("/", ul.HandleDeleteEvents)
|
||||
|
||||
if !ul.cfg.DisableSSE {
|
||||
r.Get("/sse", ul.HandleSSE)
|
||||
}
|
||||
})
|
||||
|
||||
go ul.MemorizeEvents(ch)
|
||||
@@ -230,8 +236,10 @@ func (ul *UserlogService) DeleteEvents(userid string, evids []string) error {
|
||||
}
|
||||
|
||||
func (ul *UserlogService) addEventToUser(userid string, event events.Event) error {
|
||||
if err := ul.sendSSE(userid, event); err != nil {
|
||||
ul.log.Error().Err(err).Str("userid", userid).Str("eventid", event.ID).Msg("cannot create sse event")
|
||||
if !ul.cfg.DisableSSE {
|
||||
if err := ul.sendSSE(userid, event); err != nil {
|
||||
ul.log.Error().Err(err).Str("userid", userid).Str("eventid", event.ID).Msg("cannot create sse event")
|
||||
}
|
||||
}
|
||||
return ul.alterUserEventList(userid, func(ids []string) []string {
|
||||
return append(ids, event.ID)
|
||||
|
||||
Reference in New Issue
Block a user