Skip to content

Commit

Permalink
Add support for getting authenticated federation media
Browse files Browse the repository at this point in the history
  • Loading branch information
S7evinK committed Jun 18, 2024
1 parent c2391f7 commit ba4c499
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions fclient/federationclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ type FederationClient interface {
ctx context.Context, origin, s spec.ServerName, userID string, field string,
) (res RespProfile, err error)

DownloadMedia(ctx context.Context, origin, destination spec.ServerName, mediaID string) (res *http.Response, err error)

P2PSendTransactionToRelay(ctx context.Context, u spec.UserID, t gomatrixserverlib.Transaction, forwardingServer spec.ServerName) (res EmptyResp, err error)
P2PGetTransactionFromRelay(ctx context.Context, u spec.UserID, prev RelayEntry, relayServer spec.ServerName) (res RespGetRelayTransaction, err error)
}
Expand Down Expand Up @@ -736,3 +738,31 @@ func (ac *federationClient) RoomHierarchy(
}
return
}

func (ac *federationClient) DownloadMedia(
ctx context.Context, origin, destination spec.ServerName, mediaID string,
) (res *http.Response, err error) {
var identity *SigningIdentity
for _, id := range ac.identities {
if id.ServerName == origin {
identity = id
break
}
}
if identity == nil {
return nil, fmt.Errorf("no signing identity for server name %q", origin)
}

path := federationPathPrefixV1 + "/media/download/" + url.PathEscape(mediaID)
req := NewFederationRequest("GET", origin, destination, path)

if err := req.Sign(identity.ServerName, identity.KeyID, identity.PrivateKey); err != nil {
return nil, err
}

httpReq, err := req.HTTPRequest()
if err != nil {
return nil, err
}
return ac.DoHTTPRequest(ctx, httpReq)
}

0 comments on commit ba4c499

Please sign in to comment.