Skip to content
Snippets Groups Projects
Commit d11cbaa2 authored by Travis Ralston's avatar Travis Ralston
Browse files

Require Matrix 1.1 servers

parent 49fe78ed
No related branches found
No related tags found
No related merge requests found
......@@ -97,6 +97,7 @@ path/server, for example, then you can simply update the path in the config for
* Per-user upload quotas now do not allow users to exceed the maximum values, even by 1 byte. Previously, users could exceed the limits by a little bit.
* Updated to Go 1.19
* Logs are now less noisy by default.
* Connected homeservers must support at least Matrix 1.1 on the Client-Server API.
### Fixed
......
package matrix
import (
"errors"
"fmt"
"net/url"
"time"
"github.com/turt2live/matrix-media-repo/common/rcontext"
......@@ -16,12 +19,12 @@ func IsUserAdmin(ctx rcontext.RequestContext, serverName string, accessToken str
replyError = cb.CallContext(ctx, func() error {
response := &whoisResponse{}
path := "/_matrix/client/unstable/admin/whois/"
path := fmt.Sprintf("/_matrix/client/v3/admin/whois/%s", url.PathEscape(fakeUser))
if hs.AdminApiKind == "synapse" {
path = "/_synapse/admin/v1/whois/"
path = fmt.Sprintf("/_synapse/admin/v1/whois/%s", url.PathEscape(fakeUser))
}
url := util.MakeUrl(hs.ClientServerApi, path, fakeUser)
err := doRequest(ctx, "GET", url, nil, response, accessToken, ipAddr)
urlStr := util.MakeUrl(hs.ClientServerApi, path)
err := doRequest(ctx, "GET", urlStr, nil, response, accessToken, ipAddr)
if err != nil {
err, replyError = filterError(err)
return err
......@@ -40,12 +43,15 @@ func ListMedia(ctx rcontext.RequestContext, serverName string, accessToken strin
response := &mediaListResponse{}
var replyError error
replyError = cb.CallContext(ctx, func() error {
path := "/_matrix/client/unstable/admin/room/"
path := ""
if hs.AdminApiKind == "synapse" {
path = "/_synapse/admin/v1/room/"
path = fmt.Sprintf("/_synapse/admin/v1/room/%s/media", url.PathEscape(roomId))
}
url := util.MakeUrl(hs.ClientServerApi, path, roomId, "/media")
err := doRequest(ctx, "GET", url, nil, response, accessToken, ipAddr)
if path == "" {
return errors.New("unable to query media for homeserver: wrong or incompatible adminApiKind")
}
urlStr := util.MakeUrl(hs.ClientServerApi, path)
err := doRequest(ctx, "GET", urlStr, nil, response, accessToken, ipAddr)
if err != nil {
err, replyError = filterError(err)
return err
......
......@@ -9,8 +9,8 @@ import (
"github.com/turt2live/matrix-media-repo/util"
)
var ErrInvalidToken = errors.New("Missing or invalid access token")
var ErrGuestToken = errors.New("Token belongs to a guest")
var ErrInvalidToken = errors.New("missing or invalid access token")
var ErrGuestToken = errors.New("token belongs to a guest")
func doBreakerRequest(ctx rcontext.RequestContext, serverName string, accessToken string, appserviceUserId string, ipAddr string, method string, path string, resp interface{}) error {
if accessToken == "" {
......@@ -50,7 +50,7 @@ func doBreakerRequest(ctx rcontext.RequestContext, serverName string, accessToke
func GetUserIdFromToken(ctx rcontext.RequestContext, serverName string, accessToken string, appserviceUserId string, ipAddr string) (string, error) {
response := &userIdResponse{}
err := doBreakerRequest(ctx, serverName, accessToken, appserviceUserId, ipAddr, "GET", "/_matrix/client/r0/account/whoami", response)
err := doBreakerRequest(ctx, serverName, accessToken, appserviceUserId, ipAddr, "GET", "/_matrix/client/v3/account/whoami", response)
if err != nil {
return "", err
}
......@@ -62,7 +62,7 @@ func GetUserIdFromToken(ctx rcontext.RequestContext, serverName string, accessTo
func Logout(ctx rcontext.RequestContext, serverName string, accessToken string, appserviceUserId string, ipAddr string) error {
response := &emptyResponse{}
err := doBreakerRequest(ctx, serverName, accessToken, appserviceUserId, ipAddr, "POST", "/_matrix/client/r0/logout", response)
err := doBreakerRequest(ctx, serverName, accessToken, appserviceUserId, ipAddr, "POST", "/_matrix/client/v3/logout", response)
if err != nil {
return err
}
......@@ -71,7 +71,7 @@ func Logout(ctx rcontext.RequestContext, serverName string, accessToken string,
func LogoutAll(ctx rcontext.RequestContext, serverName string, accessToken string, appserviceUserId string, ipAddr string) error {
response := &emptyResponse{}
err := doBreakerRequest(ctx, serverName, accessToken, appserviceUserId, ipAddr, "POST", "/_matrix/client/r0/logout/all", response)
err := doBreakerRequest(ctx, serverName, accessToken, appserviceUserId, ipAddr, "POST", "/_matrix/client/v3/logout/all", response)
if err != nil {
return err
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment