use chrono::Utc;
use serde::{Deserialize, Serialize};
pub mod id;
pub mod service;
pub use id::BlobId;
pub use service::BlobStorageService;
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct BlobMetadata {
pub id: BlobId,
pub size: i64,
pub content_type: String,
pub created_at: chrono::DateTime<Utc>,
pub metadata: Option<serde_json::Value>,
}
impl BlobMetadata {
pub fn new(id: BlobId, size: i64, content_type: String) -> Self {
Self { id, size, content_type, created_at: Utc::now(), metadata: None }
}
pub fn with_metadata(mut self, metadata: serde_json::Value) -> Self {
self.metadata = Some(metadata);
self
}
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct BlobStorageConfig {
pub backend: String,
pub config: serde_json::Value,
}
impl Default for BlobStorageConfig {
fn default() -> Self {
Self {
backend: "fs".to_string(),
config: serde_json::json!({
"root": "/var/vibesql/storage"
}),
}
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_blob_id_creation() {
let id = BlobId::new();
assert!(!id.to_string().is_empty());
}
#[test]
fn test_blob_metadata_creation() {
let id = BlobId::new();
let meta = BlobMetadata::new(id.clone(), 1024, "text/plain".to_string());
assert_eq!(meta.size, 1024);
assert_eq!(meta.content_type, "text/plain");
}
}