mirror of
https://github.com/FrankerFaceZ/FrankerFaceZ.git
synced 2025-09-15 17:46:55 +00:00
rework /pubmsg to use MessageTargetType
This commit is contained in:
parent
ae1306387e
commit
898057cc20
3 changed files with 58 additions and 27 deletions
|
@ -76,17 +76,38 @@ func HBackendPublishRequest(w http.ResponseWriter, r *http.Request) {
|
||||||
json := formData.Get("args")
|
json := formData.Get("args")
|
||||||
channel := formData.Get("channel")
|
channel := formData.Get("channel")
|
||||||
scope := formData.Get("scope")
|
scope := formData.Get("scope")
|
||||||
|
|
||||||
|
target := MessageTargetTypeByName(scope)
|
||||||
|
|
||||||
|
if cmd == "" {
|
||||||
|
w.WriteHeader(422)
|
||||||
|
fmt.Fprintf(w, "Error: cmd cannot be blank")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if channel == "" && (target == MsgTargetTypeChat || target == MsgTargetTypeMultichat || target == MsgTargetTypeWatching) {
|
||||||
|
w.WriteHeader(422)
|
||||||
|
fmt.Fprintf(w, "Error: channel must be specified")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
cm := ClientMessage{MessageID: -1, Command: Command(cmd), origArguments: json}
|
cm := ClientMessage{MessageID: -1, Command: Command(cmd), origArguments: json}
|
||||||
var count int
|
var count int
|
||||||
if scope == "chat" {
|
|
||||||
|
switch target {
|
||||||
|
case MsgTargetTypeSingle:
|
||||||
|
// TODO
|
||||||
|
case MsgTargetTypeChat:
|
||||||
count = PublishToChat(channel, cm)
|
count = PublishToChat(channel, cm)
|
||||||
} else if scope == "channel" {
|
case MsgTargetTypeMultichat:
|
||||||
|
// TODO
|
||||||
|
case MsgTargetTypeWatching:
|
||||||
count = PublishToWatchers(channel, cm)
|
count = PublishToWatchers(channel, cm)
|
||||||
} else if scope == "global" {
|
case MsgTargetTypeGlobal:
|
||||||
count = PublishToAll(cm)
|
count = PublishToAll(cm)
|
||||||
} else {
|
case MsgTargetTypeInvalid:
|
||||||
w.WriteHeader(400)
|
default:
|
||||||
fmt.Fprint(w, "Need to specify either chat or channel")
|
w.WriteHeader(422)
|
||||||
|
fmt.Fprint(w, "Invalid 'scope'. must be single, chat, multichat, channel, or global")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
fmt.Fprint(w, count)
|
fmt.Fprint(w, count)
|
||||||
|
|
|
@ -6,33 +6,37 @@ import (
|
||||||
"net/http"
|
"net/http"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type PushCommandCacheInfo struct {
|
||||||
|
Caching BacklogCacheType
|
||||||
|
Target MessageTargetType
|
||||||
|
}
|
||||||
|
|
||||||
// this value is just docs right now
|
// this value is just docs right now
|
||||||
var ServerInitiatedCommands = []string{
|
var ServerInitiatedCommands = map[string]PushCommandCacheInfo{
|
||||||
/// Global updates & notices
|
/// Global updates & notices
|
||||||
"update_news", // timecache:global
|
"update_news": {CacheTypeTimestamps, MsgTargetTypeGlobal}, // timecache:global
|
||||||
"message", // timecache:global
|
"message": {CacheTypeTimestamps, MsgTargetTypeGlobal}, // timecache:global
|
||||||
"reload_ff", // timecache:global
|
"reload_ff": {CacheTypeTimestamps, MsgTargetTypeGlobal}, // timecache:global
|
||||||
|
|
||||||
/// Emote updates
|
/// Emote updates
|
||||||
"reload_badges", // timecache:global
|
"reload_badges": {CacheTypeTimestamps, MsgTargetTypeGlobal}, // timecache:global
|
||||||
"set_badge", // timecache:multichat
|
"set_badge": {CacheTypeTimestamps, MsgTargetTypeMultichat}, // timecache:multichat
|
||||||
"reload_set", // timecache:multichat
|
"reload_set": {CacheTypeTimestamps, MsgTargetTypeMultichat}, // timecache:multichat
|
||||||
"load_set", // TODO what are the semantics of this?
|
"load_set": {}, // TODO what are the semantics of this?
|
||||||
|
|
||||||
/// User auth
|
/// User auth
|
||||||
"do_authorize", // nocache:single
|
"do_authorize": {CacheTypeNever, MsgTargetTypeSingle}, // nocache:single
|
||||||
|
|
||||||
/// Channel data
|
/// Channel data
|
||||||
// extra emote sets included in the chat
|
// follow_sets: extra emote sets included in the chat
|
||||||
"follow_sets", // mustcache:chat
|
// follow_buttons: extra follow buttons below the stream
|
||||||
// extra follow buttons below the stream
|
"follow_sets": {CacheTypePersistent, MsgTargetTypeChat}, // mustcache:chat
|
||||||
"follow_buttons", // mustcache:watching
|
"follow_buttons": {CacheTypePersistent, MsgTargetTypeWatching}, // mustcache:watching
|
||||||
// SRL race data
|
"srl_race": {CacheTypeLastOnly, MsgTargetTypeWatching}, // cachelast:watching
|
||||||
"srl_race", // cachelast:watching
|
|
||||||
|
|
||||||
/// Chatter/viewer counts
|
/// Chatter/viewer counts
|
||||||
"chatters", // cachelast:watching
|
"chatters": {CacheTypeLastOnly, MsgTargetTypeWatching}, // cachelast:watching
|
||||||
"viewers", // cachelast:watching
|
"viewers": {CacheTypeLastOnly, MsgTargetTypeWatching}, // cachelast:watching
|
||||||
}
|
}
|
||||||
var _ = ServerInitiatedCommands
|
var _ = ServerInitiatedCommands
|
||||||
|
|
||||||
|
@ -70,15 +74,15 @@ const (
|
||||||
MsgTargetTypeGlobal
|
MsgTargetTypeGlobal
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// note: see types.go for methods on these
|
||||||
|
|
||||||
// Returned by BacklogCacheType.UnmarshalJSON()
|
// Returned by BacklogCacheType.UnmarshalJSON()
|
||||||
var ErrorUnrecognizedCacheType = errors.New("Invalid value for cachetype")
|
var ErrorUnrecognizedCacheType = errors.New("Invalid value for cachetype")
|
||||||
|
|
||||||
// Returned by MessageTargetType.UnmarshalJSON()
|
// Returned by MessageTargetType.UnmarshalJSON()
|
||||||
var ErrorUnrecognizedTargetType = errors.New("Invalid value for message target")
|
var ErrorUnrecognizedTargetType = errors.New("Invalid value for message target")
|
||||||
|
|
||||||
// note: see types.go for methods on these
|
func HBackendUpdateAndPublish(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
func HBackendSaveBacklog(w http.ResponseWriter, r *http.Request) {
|
|
||||||
formData, err := UnsealRequest(r.Form)
|
formData, err := UnsealRequest(r.Form)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
w.WriteHeader(403)
|
w.WriteHeader(403)
|
||||||
|
@ -86,4 +90,9 @@ func HBackendSaveBacklog(w http.ResponseWriter, r *http.Request) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
cmd := formData.Get("command")
|
||||||
|
cacheinfo, ok := ServerInitiatedCommands[cmd]
|
||||||
|
if !ok {
|
||||||
|
w.WriteHeader(422)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -127,7 +127,8 @@ func SetupServerAndHandle(config *Config, tlsConfig *tls.Config, serveMux *http.
|
||||||
serveMux = http.DefaultServeMux
|
serveMux = http.DefaultServeMux
|
||||||
}
|
}
|
||||||
serveMux.HandleFunc("/", sockServer.ServeHTTP)
|
serveMux.HandleFunc("/", sockServer.ServeHTTP)
|
||||||
serveMux.HandleFunc("/pub", HBackendPublishRequest)
|
serveMux.HandleFunc("/pubmsg", HBackendPublishRequest)
|
||||||
|
serveMux.HandleFunc("/updatepub", HBackendUpdateAndPublish)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Handle a new websocket connection from a FFZ client.
|
// Handle a new websocket connection from a FFZ client.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue