Documentation
¶
Index ¶
- Constants
- func BuildBlobURL(baseURL, sha256Hex, ext string) string
- func CalculateSHA256(data []byte) []byte
- func CalculateSHA256Hex(data []byte) string
- func DetectMimeType(contentType string, ext string) string
- func ExtractAuthEvent(r *http.Request) (ev *event.E, err error)
- func ExtractSHA256FromPath(path string) (sha256Hex string, ext string, err error)
- func ExtractSHA256FromURL(urlStr string) (sha256Hex string, err error)
- func GetExtensionFromMimeType(mimeType string) string
- func GetFileExtensionFromPath(path string) string
- func GetMimeTypeFromExtension(ext string) string
- func GetPubkeyFromRequest(r *http.Request) (pubkey []byte, err error)
- func OptimizeMedia(data []byte, mimeType string) (optimizedData []byte, optimizedMimeType string)
- func ParseRangeHeader(rangeHeader string, contentLength int64) (start, end int64, valid bool, err error)
- func SetPaymentRequired(w http.ResponseWriter, paymentHeaders map[string]string)
- func ValidateSHA256Hex(s string) bool
- func WriteRangeResponse(w http.ResponseWriter, data []byte, start, end, totalLength int64)
- type AuthEvent
- func ValidateAuthEvent(r *http.Request, verb string, sha256Hash []byte) (authEv *AuthEvent, err error)
- func ValidateAuthEventForGet(r *http.Request, serverURL string, sha256Hash []byte) (authEv *AuthEvent, err error)
- func ValidateAuthEventOptional(r *http.Request, verb string, sha256Hash []byte) (authEv *AuthEvent, err error)
- type BaseURLKey
- type BlobDescriptor
- type BlobMetadata
- type Config
- type PaymentChecker
- type Server
- type Storage
- func (s *Storage) DeleteBlob(sha256Hash []byte, pubkey []byte) (err error)
- func (s *Storage) GetBlob(sha256Hash []byte) (data []byte, metadata *BlobMetadata, err error)
- func (s *Storage) GetBlobMetadata(sha256Hash []byte) (metadata *BlobMetadata, err error)
- func (s *Storage) GetTotalStorageUsed(pubkey []byte) (totalMB int64, err error)
- func (s *Storage) HasBlob(sha256Hash []byte) (exists bool, err error)
- func (s *Storage) ListAllUserStats() (stats []*UserBlobStats, err error)
- func (s *Storage) ListBlobs(pubkey []byte, since, until int64) (descriptors []*BlobDescriptor, err error)
- func (s *Storage) SaveBlob(sha256Hash []byte, data []byte, pubkey []byte, mimeType string, ...) (err error)
- func (s *Storage) SaveReport(sha256Hash []byte, reportData []byte) (err error)
- type UserBlobStats
Constants ¶
const ( // BlossomAuthKind is the Nostr event kind for Blossom authorization events (BUD-01) BlossomAuthKind = 24242 // AuthorizationHeader is the HTTP header name for authorization AuthorizationHeader = "Authorization" // NostrAuthPrefix is the prefix for Nostr authorization scheme NostrAuthPrefix = "Nostr" )
Variables ¶
This section is empty.
Functions ¶
func BuildBlobURL ¶
BuildBlobURL builds a blob URL with optional extension
func CalculateSHA256 ¶
CalculateSHA256 calculates the SHA256 hash of data
func CalculateSHA256Hex ¶
CalculateSHA256Hex calculates the SHA256 hash and returns it as hex string
func DetectMimeType ¶
DetectMimeType detects MIME type from Content-Type header or file extension
func ExtractAuthEvent ¶
ExtractAuthEvent extracts and parses a kind 24242 authorization event from the Authorization header
func ExtractSHA256FromPath ¶
ExtractSHA256FromPath extracts SHA256 hash from URL path Supports both /<sha256> and /<sha256>.<ext> formats
func ExtractSHA256FromURL ¶
ExtractSHA256FromURL extracts SHA256 hash from a URL string Uses the last occurrence of a 64 char hex string (as per BUD-03)
func GetExtensionFromMimeType ¶
GetExtensionFromMimeType returns file extension based on MIME type
func GetFileExtensionFromPath ¶
GetFileExtensionFromPath extracts file extension from a path
func GetMimeTypeFromExtension ¶
GetMimeTypeFromExtension returns MIME type based on file extension
func GetPubkeyFromRequest ¶
GetPubkeyFromRequest extracts pubkey from Authorization header if present
func OptimizeMedia ¶
OptimizeMedia optimizes media content (BUD-05) This is a placeholder implementation - actual optimization would use libraries like image processing, video encoding, etc.
func ParseRangeHeader ¶
func ParseRangeHeader(rangeHeader string, contentLength int64) ( start, end int64, valid bool, err error, )
ParseRangeHeader parses HTTP Range header (RFC 7233) Returns start, end, and total length
func SetPaymentRequired ¶
func SetPaymentRequired(w http.ResponseWriter, paymentHeaders map[string]string)
SetPaymentRequired sets a 402 Payment Required response with payment headers
func ValidateSHA256Hex ¶
ValidateSHA256Hex validates that a string is a valid SHA256 hex string
func WriteRangeResponse ¶
func WriteRangeResponse( w http.ResponseWriter, data []byte, start, end, totalLength int64, )
WriteRangeResponse writes a partial content response (206)
Types ¶
type AuthEvent ¶
AuthEvent represents a validated authorization event
func ValidateAuthEvent ¶
func ValidateAuthEvent( r *http.Request, verb string, sha256Hash []byte, ) (authEv *AuthEvent, err error)
ValidateAuthEvent validates a kind 24242 authorization event according to BUD-01
func ValidateAuthEventForGet ¶
func ValidateAuthEventForGet( r *http.Request, serverURL string, sha256Hash []byte, ) (authEv *AuthEvent, err error)
ValidateAuthEventForGet validates authorization for GET requests (BUD-01) GET requests may have either: - A server tag matching the server URL - At least one x tag matching the blob hash
func ValidateAuthEventOptional ¶
func ValidateAuthEventOptional( r *http.Request, verb string, sha256Hash []byte, ) (authEv *AuthEvent, err error)
ValidateAuthEventOptional validates authorization but returns nil if no auth header is present This is used for endpoints where authorization is optional
type BaseURLKey ¶ added in v0.36.12
type BaseURLKey struct{}
BaseURLKey is the context key for the base URL (exported for use by app handler)
type BlobDescriptor ¶
type BlobDescriptor struct {
URL string `json:"url"`
SHA256 string `json:"sha256"`
Size int64 `json:"size"`
Type string `json:"type"`
Uploaded int64 `json:"uploaded"`
NIP94 [][]string `json:"nip94,omitempty"`
}
BlobDescriptor represents a blob descriptor as defined in BUD-02
type BlobMetadata ¶
type BlobMetadata struct {
Pubkey []byte `json:"pubkey"`
MimeType string `json:"mime_type"`
Uploaded int64 `json:"uploaded"`
Size int64 `json:"size"`
Extension string `json:"extension"` // File extension (e.g., ".png", ".pdf")
}
BlobMetadata stores metadata about a blob in the database
func DeserializeBlobMetadata ¶
func DeserializeBlobMetadata(data []byte) (bm *BlobMetadata, err error)
DeserializeBlobMetadata deserializes blob metadata from JSON
func NewBlobMetadata ¶
func NewBlobMetadata(pubkey []byte, mimeType string, size int64) *BlobMetadata
NewBlobMetadata creates a new blob metadata struct
func (*BlobMetadata) Serialize ¶
func (bm *BlobMetadata) Serialize() (data []byte, err error)
Serialize serializes blob metadata to JSON
type Config ¶
Config holds configuration for the Blossom server
type PaymentChecker ¶
type PaymentChecker struct {
}
PaymentChecker handles payment requirements (BUD-07)
func NewPaymentChecker ¶
func NewPaymentChecker() *PaymentChecker
NewPaymentChecker creates a new payment checker
func (*PaymentChecker) CheckPaymentRequired ¶
func (pc *PaymentChecker) CheckPaymentRequired( endpoint string, ) (required bool, paymentHeaders map[string]string)
CheckPaymentRequired checks if payment is required for an endpoint Returns payment method headers if payment is required
func (*PaymentChecker) ValidatePayment ¶
func (pc *PaymentChecker) ValidatePayment( paymentMethod, proof string, ) (valid bool, err error)
ValidatePayment validates a payment proof
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server provides a Blossom server implementation
func NewServer ¶
NewServer creates a new Blossom server instance
type Storage ¶
type Storage struct {
// contains filtered or unexported fields
}
Storage provides blob storage operations
func NewStorage ¶
NewStorage creates a new storage instance
func (*Storage) DeleteBlob ¶
DeleteBlob deletes a blob and its metadata
func (*Storage) GetBlob ¶
func (s *Storage) GetBlob(sha256Hash []byte) (data []byte, metadata *BlobMetadata, err error)
GetBlob retrieves blob data by SHA256 hash
func (*Storage) GetBlobMetadata ¶
func (s *Storage) GetBlobMetadata(sha256Hash []byte) (metadata *BlobMetadata, err error)
GetBlobMetadata retrieves only metadata for a blob
func (*Storage) GetTotalStorageUsed ¶
GetTotalStorageUsed calculates total storage used by a pubkey in MB
func (*Storage) HasBlob ¶
HasBlob checks if a blob exists
func (*Storage) ListAllUserStats ¶ added in v0.36.21
func (s *Storage) ListAllUserStats() (stats []*UserBlobStats, err error)
ListAllUserStats returns storage statistics for all users who have uploaded blobs
func (*Storage) ListBlobs ¶
func (s *Storage) ListBlobs( pubkey []byte, since, until int64, ) (descriptors []*BlobDescriptor, err error)
ListBlobs lists all blobs for a given pubkey
Source Files
¶
- auth.go
- blob.go
- handlers.go
- media.go
- payment.go
- server.go
- storage.go
- utils.go