mirror of
https://github.com/matrix-org/dendrite.git
synced 2025-12-12 01:13:10 -06:00
Use single route for both cases
This commit is contained in:
parent
397d590a27
commit
472defbfe6
|
|
@ -17,6 +17,7 @@ package routing
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/gorilla/mux"
|
"github.com/gorilla/mux"
|
||||||
"github.com/matrix-org/dendrite/clientapi/auth/authtypes"
|
"github.com/matrix-org/dendrite/clientapi/auth/authtypes"
|
||||||
|
|
@ -93,18 +94,16 @@ func Setup(
|
||||||
return writers.SendEvent(req, device, vars["roomID"], vars["eventType"], vars["txnID"], nil, cfg, queryAPI, producer)
|
return writers.SendEvent(req, device, vars["roomID"], vars["eventType"], vars["txnID"], nil, cfg, queryAPI, producer)
|
||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
r0mux.Handle("/rooms/{roomID}/state/{eventType}",
|
r0mux.Handle("/rooms/{roomID}/state/{eventType:[a-z._-]+(?:\\/)?}",
|
||||||
common.MakeAuthAPI("send_message", deviceDB, func(req *http.Request, device *authtypes.Device) util.JSONResponse {
|
common.MakeAuthAPI("send_message", deviceDB, func(req *http.Request, device *authtypes.Device) util.JSONResponse {
|
||||||
vars := mux.Vars(req)
|
vars := mux.Vars(req)
|
||||||
emptyString := ""
|
emptyString := ""
|
||||||
return writers.SendEvent(req, device, vars["roomID"], vars["eventType"], vars["txnID"], &emptyString, cfg, queryAPI, producer)
|
eventType := vars["eventType"]
|
||||||
}),
|
// If there's a trailing slash, remove it
|
||||||
)
|
if strings.HasSuffix(eventType, "/") {
|
||||||
r0mux.Handle("/rooms/{roomID}/state/{eventType}/",
|
eventType = eventType[:len(eventType)-1]
|
||||||
common.MakeAuthAPI("send_message", deviceDB, func(req *http.Request, device *authtypes.Device) util.JSONResponse {
|
}
|
||||||
vars := mux.Vars(req)
|
return writers.SendEvent(req, device, vars["roomID"], eventType, vars["txnID"], &emptyString, cfg, queryAPI, producer)
|
||||||
emptyString := ""
|
|
||||||
return writers.SendEvent(req, device, vars["roomID"], vars["eventType"], vars["txnID"], &emptyString, cfg, queryAPI, producer)
|
|
||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
r0mux.Handle("/rooms/{roomID}/state/{eventType}/{stateKey}",
|
r0mux.Handle("/rooms/{roomID}/state/{eventType}/{stateKey}",
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue