mirror of
https://github.com/FrankerFaceZ/FrankerFaceZ.git
synced 2025-09-18 18:56:56 +00:00
Add /all_topics endpoint
Temporarily not protected with sealing, we'll see how the performance is first.
This commit is contained in:
parent
b4f4a65a68
commit
b108177942
3 changed files with 35 additions and 0 deletions
|
@ -1,6 +1,7 @@
|
|||
package server
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
@ -10,6 +11,7 @@ import (
|
|||
|
||||
"github.com/FrankerFaceZ/FrankerFaceZ/socketserver/server/rate"
|
||||
"github.com/pkg/errors"
|
||||
"golang.org/x/sync/singleflight"
|
||||
)
|
||||
|
||||
// LastSavedMessage contains a reply to a command along with an expiration time.
|
||||
|
@ -25,6 +27,8 @@ type LastSavedMessage struct {
|
|||
var CachedLastMessages = make(map[Command]map[string]LastSavedMessage)
|
||||
var CachedLSMLock sync.RWMutex
|
||||
|
||||
var singleFlighter singleflight.Group
|
||||
|
||||
func cachedMessageJanitor() {
|
||||
for {
|
||||
time.Sleep(1 * time.Hour)
|
||||
|
@ -303,3 +307,19 @@ func HTTPGetSubscriberCount(w http.ResponseWriter, r *http.Request) {
|
|||
|
||||
fmt.Fprint(w, CountSubscriptions(strings.Split(channel, ",")))
|
||||
}
|
||||
|
||||
func HTTPListAllTopics(w http.ResponseWriter, r *http.Request) {
|
||||
r.ParseForm()
|
||||
_, err := Backend.secureForm.Unseal(r.Form)
|
||||
if err != nil {
|
||||
//w.WriteHeader(403)
|
||||
//fmt.Fprintf(w, "Error: %v", err)
|
||||
//return
|
||||
}
|
||||
|
||||
topicList, _, _ := singleFlighter.Do("/all_topics", func() (interface{}, error) {
|
||||
return GetAllTopics(), nil
|
||||
})
|
||||
w.WriteHeader(200)
|
||||
json.NewEncoder(w).Encode(topicList)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue