Enhance blob storage functionality with file extension support
- Added an `Extension` field to `BlobMetadata` to store file extensions alongside existing metadata. - Updated the `SaveBlob` method to handle file extensions, ensuring they are stored and retrieved correctly. - Modified the `GetBlob` method to read blob data from the filesystem based on the stored extension. - Enhanced the `Storage` struct to manage blob files in a specified directory, improving organization and access. - Introduced utility functions for determining file extensions from MIME types, facilitating better file handling. - Added comprehensive tests for new functionalities, ensuring robust behavior across blob operations.
This commit is contained in:
@@ -17,10 +17,11 @@ type BlobDescriptor struct {
|
||||
|
||||
// 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"`
|
||||
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")
|
||||
}
|
||||
|
||||
// NewBlobDescriptor creates a new blob descriptor
|
||||
@@ -45,10 +46,11 @@ func NewBlobMetadata(pubkey []byte, mimeType string, size int64) *BlobMetadata {
|
||||
mimeType = "application/octet-stream"
|
||||
}
|
||||
return &BlobMetadata{
|
||||
Pubkey: pubkey,
|
||||
MimeType: mimeType,
|
||||
Uploaded: time.Now().Unix(),
|
||||
Size: size,
|
||||
Pubkey: pubkey,
|
||||
MimeType: mimeType,
|
||||
Uploaded: time.Now().Unix(),
|
||||
Size: size,
|
||||
Extension: "", // Will be set by SaveBlob
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user