nipb0: Add authorization headers to Blossom downloads

This commit is contained in:
Daniel D’Aquino
2025-03-06 11:55:26 -08:00
committed by fiatjaf_
parent c9411a3c5b
commit 8140857879

View File

@@ -21,6 +21,12 @@ func (c *Client) Download(ctx context.Context, hash string) ([]byte, error) {
return nil, fmt.Errorf("failed to create request: %w", err)
}
authHeader := c.authorizationHeader(ctx, func(evt *nostr.Event) {
evt.Tags = append(evt.Tags, nostr.Tag{"t", "get"})
evt.Tags = append(evt.Tags, nostr.Tag{"x", hash})
})
req.Header.Add("Authorization", authHeader)
resp, err := http.DefaultClient.Do(req)
if err != nil {
return nil, fmt.Errorf("failed to call %s for %s: %w", c.mediaserver, hash, err)
@@ -45,6 +51,12 @@ func (c *Client) DownloadToFile(ctx context.Context, hash string, filePath strin
return fmt.Errorf("failed to create request: %w", err)
}
authHeader := c.authorizationHeader(ctx, func(evt *nostr.Event) {
evt.Tags = append(evt.Tags, nostr.Tag{"t", "get"})
evt.Tags = append(evt.Tags, nostr.Tag{"x", hash})
})
req.Header.Add("Authorization", authHeader)
resp, err := http.DefaultClient.Do(req)
if err != nil {
return fmt.Errorf("failed to call %s for %s: %w", c.mediaserver, hash, err)