Add api-call to remove last follower

This commit is contained in:
Knut Ahlers 2020-11-23 10:02:08 +01:00
parent 0c41f447f7
commit 33480e92c6
Signed by: luzifer
GPG key ID: 0066F03ED215AD7D

15
api.go
View file

@ -92,10 +92,25 @@ var upgrader = websocket.Upgrader{
}
func registerAPI(r *mux.Router) {
r.HandleFunc("/api/follows/clear-last", handleClearLastFollower)
r.HandleFunc("/api/subscribe", handleUpdateSocket)
r.HandleFunc("/api/webhook/{type}", handleWebHookPush)
}
func handleClearLastFollower(w http.ResponseWriter, r *http.Request) {
store.Followers.Last = nil
if err := store.Save(cfg.StoreFile); err != nil {
log.WithError(err).Error("Unable to update persistent store")
}
if err := subscriptions.SendAllSockets(msgTypeStore, store); err != nil {
log.WithError(err).Error("Unable to send update to all sockets")
}
w.WriteHeader(http.StatusAccepted)
}
func handleUpdateSocket(w http.ResponseWriter, r *http.Request) {
// Upgrade connection to socket
conn, err := upgrader.Upgrade(w, r, nil)