From 57d595a5b4c7de562160b944d983586ec71bbae4 Mon Sep 17 00:00:00 2001 From: fiatjaf Date: Sun, 18 Jan 2026 14:30:02 -0300 Subject: [PATCH] nipb0/blossom: mirror. --- nipb0/blossom/mirror.go | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 nipb0/blossom/mirror.go diff --git a/nipb0/blossom/mirror.go b/nipb0/blossom/mirror.go new file mode 100644 index 0000000..be11a6d --- /dev/null +++ b/nipb0/blossom/mirror.go @@ -0,0 +1,35 @@ +package blossom + +import ( + "bytes" + "context" + "encoding/json" + "fmt" + "strings" + + "fiatjaf.com/nostr" +) + +// MirrorBlob mirrors a blob from a remote URL to the media server +func (c *Client) MirrorBlob(ctx context.Context, remoteBlobURL string) (*BlobDescriptor, error) { + bodyBytes, err := json.Marshal(struct{ URL string }{URL: remoteBlobURL}) + if err != nil { + return nil, fmt.Errorf("failed to marshal mirror request: %w", err) + } + + spl := strings.Split(remoteBlobURL, "/") + hhash := strings.Split(spl[len(spl)-1], ".")[0] + + bd := BlobDescriptor{} + err = c.httpCall(ctx, "PUT", "mirror", "application/json", func() string { + return c.authorizationHeader(ctx, func(evt *nostr.Event) { + evt.Tags = append(evt.Tags, nostr.Tag{"t", "upload"}) + evt.Tags = append(evt.Tags, nostr.Tag{"x", hhash}) + }) + }, bytes.NewReader(bodyBytes), int64(len(bodyBytes)), &bd) + if err != nil { + return nil, fmt.Errorf("failed to mirror blob: %w", err) + } + + return &bd, nil +}