diff --git a/common/media_kinds.go b/common/LEGACY_media_kinds.go similarity index 100% rename from common/media_kinds.go rename to common/LEGACY_media_kinds.go diff --git a/common/rcontext/request_context.go b/common/rcontext/request_context.go index d5e151d846e56b2c1bb94ecb728bb0cfd5bcd7cf..9965e3bc3a52d6fb059164531975ce0dbd33c635 100644 --- a/common/rcontext/request_context.go +++ b/common/rcontext/request_context.go @@ -35,20 +35,20 @@ type RequestContext struct { context.Context // These are also stored on the context object itself - Log *logrus.Entry // mr.logger - Config config.DomainRepoConfig // mr.serverConfig - Request *http.Request // mr.request + Log *logrus.Entry // mmr.logger + Config config.DomainRepoConfig // mmr.serverConfig + Request *http.Request // mmr.request } func (c RequestContext) populate() RequestContext { - c.Context = context.WithValue(c.Context, "mr.logger", c.Log) - c.Context = context.WithValue(c.Context, "mr.serverConfig", c.Config) - c.Context = context.WithValue(c.Context, "mr.request", c.Request) + c.Context = context.WithValue(c.Context, "mmr.logger", c.Log) + c.Context = context.WithValue(c.Context, "mmr.serverConfig", c.Config) + c.Context = context.WithValue(c.Context, "mmr.request", c.Request) return c } func (c RequestContext) ReplaceLogger(log *logrus.Entry) RequestContext { - ctx := context.WithValue(c.Context, "mr.logger", log) + ctx := context.WithValue(c.Context, "mmr.logger", log) return RequestContext{ Context: ctx, Log: log, diff --git a/homeserver_interop/synapse/db.go b/homeserver_interop/synapse/db.go index 7b03d0369ce6011552d29a2d28d32a5b9a2d7694..57494cec71025242ace5a5b7399e104afd9dfe1a 100644 --- a/homeserver_interop/synapse/db.go +++ b/homeserver_interop/synapse/db.go @@ -8,6 +8,16 @@ import ( const selectLocalMedia = "SELECT media_id, media_type, media_length, created_ts, upload_name, user_id, url_cache FROM local_media_repository;" +type LocalMedia struct { + MediaId string + ContentType string + SizeBytes int64 + CreatedTs int64 + UploadName string + UserId string + UrlCache string +} + type SynDatabase struct { db *sql.DB statements statements diff --git a/homeserver_interop/synapse/local_media.go b/homeserver_interop/synapse/local_media.go deleted file mode 100644 index 4842a3cd11edb4a4e172bcd6865ffda2b876afa0..0000000000000000000000000000000000000000 --- a/homeserver_interop/synapse/local_media.go +++ /dev/null @@ -1,11 +0,0 @@ -package synapse - -type LocalMedia struct { - MediaId string - ContentType string - SizeBytes int64 - CreatedTs int64 - UploadName string - UserId string - UrlCache string -} diff --git a/matrix/auth.go b/matrix/auth.go index 93889fd2b118c5d7582807b65a45691cfbf4eef3..e688ecde384fe7f2859a946aa84efa9e40fca7c7 100644 --- a/matrix/auth.go +++ b/matrix/auth.go @@ -35,7 +35,7 @@ func doBreakerRequest(ctx rcontext.RequestContext, serverName string, accessToke target.RawQuery = q.Encode() err := doRequest(ctx, method, target.String(), nil, resp, accessToken, ipAddr) if err != nil { - ctx.Log.Warn("Error from homeserver: ", err) + ctx.Log.Debug("Error from homeserver: ", err) err, authError = filterError(err) return err } diff --git a/matrix/client_server.go b/matrix/client_server.go index 640094ad62feee07ca4251bee3dbbe3a583b90d6..78b671607f96f6e9828db377f086590bd4d84c7d 100644 --- a/matrix/client_server.go +++ b/matrix/client_server.go @@ -8,13 +8,12 @@ import ( "net/http" "time" - "github.com/sirupsen/logrus" "github.com/turt2live/matrix-media-repo/common/rcontext" ) // Based in part on https://github.com/matrix-org/gomatrix/blob/072b39f7fa6b40257b4eead8c958d71985c28bdd/client.go#L180-L243 func doRequest(ctx rcontext.RequestContext, method string, urlStr string, body interface{}, result interface{}, accessToken string, ipAddr string) error { - logrus.Infof("Calling %s %s", method, urlStr) + ctx.Log.Debugf("Calling %s %s", method, urlStr) var bodyBytes []byte if body != nil { jsonStr, err := json.Marshal(body) diff --git a/matrix/matrix.go b/matrix/matrix.go index 4abf21d80fb5c3dba13138f08dd80177f5e1e6d9..0e5667d7f61451a4aa87cb2e0758a37c6efdf280 100644 --- a/matrix/matrix.go +++ b/matrix/matrix.go @@ -1,6 +1,7 @@ package matrix import ( + "errors" "sync" "github.com/rubyist/circuitbreaker" @@ -35,7 +36,8 @@ func filterError(err error) (error, error) { } // Unknown token errors should be filtered out explicitly to ensure we don't break on bad requests - if httpErr, ok := err.(*errorResponse); ok { + var httpErr *errorResponse + if errors.As(err, &httpErr) { // We send back our own version of errors to ensure we can filter them out elsewhere if httpErr.ErrorCode == common.ErrCodeUnknownToken { return nil, ErrInvalidToken