mirror of
https://github.com/FrankerFaceZ/FrankerFaceZ.git
synced 2025-07-29 22:18:31 +00:00
Move HandlePublishRequest to backend.go
This commit is contained in:
parent
0c9e7bb97d
commit
df7d607556
3 changed files with 28 additions and 26 deletions
|
@ -64,6 +64,32 @@ func getCacheKey(remoteCommand, data string) string {
|
||||||
return fmt.Sprintf("%s/%s", remoteCommand, data)
|
return fmt.Sprintf("%s/%s", remoteCommand, data)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func HandlePublishRequest(w http.ResponseWriter, r *http.Request) {
|
||||||
|
formData, err := UnsealRequest(r.Form)
|
||||||
|
if err != nil {
|
||||||
|
w.WriteHeader(403)
|
||||||
|
fmt.Fprintf(w, "Error: %v", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
cmd := formData.Get("cmd")
|
||||||
|
json := formData.Get("args")
|
||||||
|
chat := formData.Get("chat")
|
||||||
|
watchChannel := formData.Get("channel")
|
||||||
|
cm := ClientMessage{MessageID: -1, Command: Command(cmd), origArguments: json}
|
||||||
|
var count int
|
||||||
|
if chat != "" {
|
||||||
|
count = PublishToChat(chat, cm)
|
||||||
|
} else if watchChannel != "" {
|
||||||
|
count = PublishToWatchers(watchChannel, cm)
|
||||||
|
} else {
|
||||||
|
w.WriteHeader(400)
|
||||||
|
fmt.Fprint(w, "Need to specify either chat or channel")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
fmt.Fprint(w, count)
|
||||||
|
}
|
||||||
|
|
||||||
func RequestRemoteDataCached(remoteCommand, data string, auth AuthInfo) (string, error) {
|
func RequestRemoteDataCached(remoteCommand, data string, auth AuthInfo) (string, error) {
|
||||||
cached, ok := responseCache.Get(getCacheKey(remoteCommand, data))
|
cached, ok := responseCache.Get(getCacheKey(remoteCommand, data))
|
||||||
if ok {
|
if ok {
|
||||||
|
|
|
@ -31,6 +31,8 @@ func TestSealRequest(t *testing.T) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
// sealedValues.Encode()
|
||||||
|
// id=0&msg=KKtbng49dOLLyjeuX5AnXiEe6P0uZwgeP_7mMB5vhP-wMAAPZw%3D%3D&nonce=-wRbUnifscisWUvhm3gBEXHN5QzrfzgV
|
||||||
|
|
||||||
unsealedValues, err := UnsealRequest(sealedValues)
|
unsealedValues, err := UnsealRequest(sealedValues)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -50,32 +50,6 @@ func PublishToWatchers(channel string, msg ClientMessage) (count int) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func HandlePublishRequest(w http.ResponseWriter, r *http.Request) {
|
|
||||||
formData, err := UnsealRequest(r.Form)
|
|
||||||
if err != nil {
|
|
||||||
w.WriteHeader(403)
|
|
||||||
fmt.Fprintf(w, "Error: %v", err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
cmd := formData.Get("cmd")
|
|
||||||
json := formData.Get("args")
|
|
||||||
chat := formData.Get("chat")
|
|
||||||
watchChannel := formData.Get("channel")
|
|
||||||
cm := ClientMessage{MessageID: -1, Command: Command(cmd), origArguments: json}
|
|
||||||
var count int
|
|
||||||
if chat != "" {
|
|
||||||
count = PublishToChat(chat, cm)
|
|
||||||
} else if watchChannel != "" {
|
|
||||||
count = PublishToWatchers(watchChannel, cm)
|
|
||||||
} else {
|
|
||||||
w.WriteHeader(400)
|
|
||||||
fmt.Fprint(w, "Need to specify either chat or channel")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
fmt.Fprint(w, count)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Add a channel to the subscriptions while holding a read-lock to the map.
|
// Add a channel to the subscriptions while holding a read-lock to the map.
|
||||||
// Locks:
|
// Locks:
|
||||||
// - ALREADY HOLDING a read-lock to the 'which' top-level map via the rlocker object
|
// - ALREADY HOLDING a read-lock to the 'which' top-level map via the rlocker object
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue