Add Blossom package with core functionalities for blob storage and authorization
- Introduced the Blossom package, implementing essential features for handling blob storage, including upload, retrieval, and deletion of blobs. - Added authorization mechanisms for secure access to blob operations, validating authorization events based on Nostr standards. - Implemented various HTTP handlers for managing blob interactions, including GET, HEAD, PUT, and DELETE requests. - Developed utility functions for SHA256 hash calculations, MIME type detection, and range request handling. - Established a storage layer using Badger database for efficient blob data management and metadata storage. - Included placeholder implementations for media optimization and payment handling, setting the groundwork for future enhancements. - Documented the new functionalities and usage patterns in the codebase for better maintainability and understanding.
This commit is contained in:
65
pkg/blossom/blob.go
Normal file
65
pkg/blossom/blob.go
Normal file
@@ -0,0 +1,65 @@
|
||||
package blossom
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"time"
|
||||
)
|
||||
|
||||
// BlobDescriptor represents a blob descriptor as defined in BUD-02
|
||||
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"`
|
||||
}
|
||||
|
||||
// BlobMetadata stores metadata about a blob in the database
|
||||
type BlobMetadata struct {
|
||||
Pubkey []byte `json:"pubkey"`
|
||||
MimeType string `json:"mime_type"`
|
||||
Uploaded int64 `json:"uploaded"`
|
||||
Size int64 `json:"size"`
|
||||
}
|
||||
|
||||
// NewBlobDescriptor creates a new blob descriptor
|
||||
func NewBlobDescriptor(
|
||||
url, sha256 string, size int64, mimeType string, uploaded int64,
|
||||
) *BlobDescriptor {
|
||||
if mimeType == "" {
|
||||
mimeType = "application/octet-stream"
|
||||
}
|
||||
return &BlobDescriptor{
|
||||
URL: url,
|
||||
SHA256: sha256,
|
||||
Size: size,
|
||||
Type: mimeType,
|
||||
Uploaded: uploaded,
|
||||
}
|
||||
}
|
||||
|
||||
// NewBlobMetadata creates a new blob metadata struct
|
||||
func NewBlobMetadata(pubkey []byte, mimeType string, size int64) *BlobMetadata {
|
||||
if mimeType == "" {
|
||||
mimeType = "application/octet-stream"
|
||||
}
|
||||
return &BlobMetadata{
|
||||
Pubkey: pubkey,
|
||||
MimeType: mimeType,
|
||||
Uploaded: time.Now().Unix(),
|
||||
Size: size,
|
||||
}
|
||||
}
|
||||
|
||||
// Serialize serializes blob metadata to JSON
|
||||
func (bm *BlobMetadata) Serialize() (data []byte, err error) {
|
||||
return json.Marshal(bm)
|
||||
}
|
||||
|
||||
// DeserializeBlobMetadata deserializes blob metadata from JSON
|
||||
func DeserializeBlobMetadata(data []byte) (bm *BlobMetadata, err error) {
|
||||
bm = &BlobMetadata{}
|
||||
err = json.Unmarshal(data, bm)
|
||||
return
|
||||
}
|
||||
Reference in New Issue
Block a user