Fix topic handling for websocket with namespace
This commit is contained in:
parent
222091b68c
commit
33875105b6
|
@ -93,7 +93,7 @@ func (h *Handler) SendJson(v *Message) error {
|
|||
|
||||
// If the user does not have permission to see backup events, do not emit
|
||||
// them over the socket.
|
||||
if v.Event == server.BackupCompletedEvent {
|
||||
if strings.HasPrefix(v.Event, server.BackupCompletedEvent) {
|
||||
if h.JWT != nil && !h.JWT.HasPermission(PermissionReceiveBackups) {
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -172,7 +172,7 @@ func (b *Backup) BackupAndNotify() error {
|
|||
|
||||
// Emit an event over the socket so we can update the backup in realtime on
|
||||
// the frontend for the server.
|
||||
b.server.Events().PublishJson(BackupCompletedEvent, map[string]interface{}{
|
||||
b.server.Events().PublishJson(BackupCompletedEvent+":"+b.Uuid, map[string]interface{}{
|
||||
"uuid": b.Uuid,
|
||||
"sha256_hash": resp.Sha256Hash,
|
||||
"file_size": resp.FileSize,
|
||||
|
|
|
@ -2,6 +2,7 @@ package server
|
|||
|
||||
import (
|
||||
"encoding/json"
|
||||
"strings"
|
||||
"sync"
|
||||
)
|
||||
|
||||
|
@ -42,7 +43,21 @@ func (e *EventBus) Publish(topic string, data string) {
|
|||
e.mu.Lock()
|
||||
defer e.mu.Unlock()
|
||||
|
||||
if ch, ok := e.subscribers[topic]; ok {
|
||||
t := topic
|
||||
// Some of our topics for the socket support passing a more specific namespace,
|
||||
// such as "backup completed:1234" to indicate which specific backup was completed.
|
||||
//
|
||||
// In these cases, we still need to the send the event using the standard listener
|
||||
// name of "backup completed".
|
||||
if strings.Contains(topic, ":") {
|
||||
parts := strings.SplitN(topic, ":", 2)
|
||||
|
||||
if len(parts) == 2 {
|
||||
t = parts[0]
|
||||
}
|
||||
}
|
||||
|
||||
if ch, ok := e.subscribers[t]; ok {
|
||||
go func(data Event, cs []chan Event) {
|
||||
for _, channel := range cs {
|
||||
channel <- data
|
||||
|
|
Loading…
Reference in New Issue
Block a user