mirror of
https://github.com/matrix-org/dendrite.git
synced 2026-01-20 04:23:09 -06:00
Use single function to get protocols
This commit is contained in:
parent
e62c745995
commit
4d4978b1ae
|
|
@ -843,17 +843,17 @@ func Setup(
|
||||||
|
|
||||||
v3mux.Handle("/thirdparty/protocols",
|
v3mux.Handle("/thirdparty/protocols",
|
||||||
httputil.MakeAuthAPI("thirdparty_protocols", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
httputil.MakeAuthAPI("thirdparty_protocols", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
||||||
return Protocols(req, asAPI, device)
|
return Protocols(req, asAPI, device, "")
|
||||||
}),
|
}),
|
||||||
).Methods(http.MethodGet, http.MethodOptions)
|
).Methods(http.MethodGet, http.MethodOptions)
|
||||||
|
|
||||||
v3mux.Handle("/thirdparty/protocol/{protocolID}",
|
v3mux.Handle("/thirdparty/protocol/{protocolID}",
|
||||||
httputil.MakeAuthAPI("thirdparty_protocol", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
httputil.MakeAuthAPI("thirdparty_protocols", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
||||||
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return util.ErrorResponse(err)
|
return util.ErrorResponse(err)
|
||||||
}
|
}
|
||||||
return Protocol(req, asAPI, device, vars["protocolID"])
|
return Protocols(req, asAPI, device, vars["protocolID"])
|
||||||
}),
|
}),
|
||||||
).Methods(http.MethodGet, http.MethodOptions)
|
).Methods(http.MethodGet, http.MethodOptions)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -27,30 +27,9 @@ import (
|
||||||
|
|
||||||
// Protocols implements
|
// Protocols implements
|
||||||
//
|
//
|
||||||
// GET /_matrix/client/v3/thirdparty/protocols
|
|
||||||
func Protocols(req *http.Request, asAPI appserviceAPI.AppServiceInternalAPI, device *api.Device) util.JSONResponse {
|
|
||||||
resp := &appserviceAPI.ProtocolResponse{}
|
|
||||||
|
|
||||||
if err := asAPI.Protocols(req.Context(), &appserviceAPI.ProtocolRequest{Protocol: ""}, resp); err != nil {
|
|
||||||
return jsonerror.InternalServerError()
|
|
||||||
}
|
|
||||||
if !resp.Exists {
|
|
||||||
return util.JSONResponse{
|
|
||||||
Code: http.StatusNotFound,
|
|
||||||
JSON: jsonerror.NotFound("No protocols registered"),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return util.JSONResponse{
|
|
||||||
Code: http.StatusOK,
|
|
||||||
JSON: resp.Protocols,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Protocol implements
|
|
||||||
//
|
|
||||||
// GET /_matrix/client/v3/thirdparty/protocols/{protocol}
|
// GET /_matrix/client/v3/thirdparty/protocols/{protocol}
|
||||||
func Protocol(req *http.Request, asAPI appserviceAPI.AppServiceInternalAPI, device *api.Device, protocol string) util.JSONResponse {
|
// GET /_matrix/client/v3/thirdparty/protocols
|
||||||
|
func Protocols(req *http.Request, asAPI appserviceAPI.AppServiceInternalAPI, device *api.Device, protocol string) util.JSONResponse {
|
||||||
resp := &appserviceAPI.ProtocolResponse{}
|
resp := &appserviceAPI.ProtocolResponse{}
|
||||||
|
|
||||||
if err := asAPI.Protocols(req.Context(), &appserviceAPI.ProtocolRequest{Protocol: protocol}, resp); err != nil {
|
if err := asAPI.Protocols(req.Context(), &appserviceAPI.ProtocolRequest{Protocol: protocol}, resp); err != nil {
|
||||||
|
|
@ -62,9 +41,15 @@ func Protocol(req *http.Request, asAPI appserviceAPI.AppServiceInternalAPI, devi
|
||||||
JSON: jsonerror.NotFound("The protocol is unknown."),
|
JSON: jsonerror.NotFound("The protocol is unknown."),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if protocol != "" {
|
||||||
|
return util.JSONResponse{
|
||||||
|
Code: http.StatusOK,
|
||||||
|
JSON: resp.Protocols[protocol],
|
||||||
|
}
|
||||||
|
}
|
||||||
return util.JSONResponse{
|
return util.JSONResponse{
|
||||||
Code: http.StatusOK,
|
Code: http.StatusOK,
|
||||||
JSON: resp.Protocols[protocol],
|
JSON: resp.Protocols,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue