post3 0.1.0

Pluggable S3-compatible object storage — core library with PostgreSQL and filesystem backends
Documentation
use chrono::{DateTime, Utc};
use uuid::Uuid;

#[derive(Debug, Clone, sqlx::FromRow)]
pub struct BucketRow {
    pub id: Uuid,
    pub name: String,
    pub created_at: DateTime<Utc>,
}

#[derive(Debug, Clone, sqlx::FromRow)]
pub struct ObjectRow {
    pub id: Uuid,
    pub bucket_id: Uuid,
    pub key: String,
    pub size: i64,
    pub etag: String,
    pub content_type: String,
    pub created_at: DateTime<Utc>,
}

#[derive(Debug, Clone, sqlx::FromRow)]
pub struct BlockRow {
    pub id: Uuid,
    pub object_id: Uuid,
    pub block_index: i32,
    pub data: Vec<u8>,
    pub block_size: i32,
}

#[derive(Debug, Clone, sqlx::FromRow)]
pub struct MetadataEntry {
    pub id: Uuid,
    pub object_id: Uuid,
    pub meta_key: String,
    pub meta_value: String,
}

/// Backend-neutral bucket summary.
#[derive(Debug, Clone)]
pub struct BucketInfo {
    pub name: String,
    pub created_at: DateTime<Utc>,
}

/// Backend-neutral object metadata (no internal IDs).
#[derive(Debug, Clone)]
pub struct ObjectMeta {
    pub key: String,
    pub size: i64,
    pub etag: String,
    pub content_type: String,
    pub last_modified: DateTime<Utc>,
}

#[derive(Debug, Clone)]
pub struct ObjectInfo {
    pub key: String,
    pub size: i64,
    pub etag: String,
    pub last_modified: DateTime<Utc>,
}

#[derive(Debug, Clone)]
pub struct ListObjectsResult {
    pub objects: Vec<ObjectInfo>,
    pub is_truncated: bool,
    pub next_continuation_token: Option<String>,
    pub prefix: Option<String>,
    pub delimiter: Option<String>,
    pub common_prefixes: Vec<String>,
    pub key_count: usize,
}

#[derive(Debug)]
pub struct PutObjectResult {
    pub etag: String,
    pub size: i64,
}

#[derive(Debug)]
pub struct GetObjectResult {
    pub metadata: ObjectMeta,
    pub user_metadata: std::collections::HashMap<String, String>,
    pub body: bytes::Bytes,
}

#[derive(Debug)]
pub struct HeadObjectResult {
    pub object: ObjectMeta,
    pub user_metadata: std::collections::HashMap<String, String>,
}

// --- Multipart upload models ---

#[derive(Debug, Clone, sqlx::FromRow)]
pub struct MultipartUploadRow {
    pub id: Uuid,
    pub bucket_id: Uuid,
    pub key: String,
    pub upload_id: String,
    pub content_type: String,
    pub created_at: DateTime<Utc>,
}

#[derive(Debug, Clone, sqlx::FromRow)]
pub struct UploadPartRow {
    pub id: Uuid,
    pub upload_id: Uuid,
    pub part_number: i32,
    pub data: Vec<u8>,
    pub size: i64,
    pub etag: String,
    pub created_at: DateTime<Utc>,
}

#[derive(Debug, Clone, sqlx::FromRow)]
pub struct UploadPartInfo {
    pub part_number: i32,
    pub size: i64,
    pub etag: String,
    pub created_at: DateTime<Utc>,
}

#[derive(Debug)]
pub struct CreateMultipartUploadResult {
    pub bucket: String,
    pub key: String,
    pub upload_id: String,
}

#[derive(Debug)]
pub struct UploadPartResult {
    pub etag: String,
}

#[derive(Debug)]
pub struct CompleteMultipartUploadResult {
    pub bucket: String,
    pub key: String,
    pub etag: String,
    pub size: i64,
}

#[derive(Debug)]
pub struct ListPartsResult {
    pub bucket: String,
    pub key: String,
    pub upload_id: String,
    pub parts: Vec<UploadPartInfo>,
    pub is_truncated: bool,
    pub next_part_number_marker: Option<i32>,
}

#[derive(Debug)]
pub struct MultipartUploadInfo {
    pub key: String,
    pub upload_id: String,
    pub initiated: DateTime<Utc>,
}

#[derive(Debug)]
pub struct ListMultipartUploadsResult {
    pub bucket: String,
    pub uploads: Vec<MultipartUploadInfo>,
    pub is_truncated: bool,
    pub next_key_marker: Option<String>,
    pub next_upload_id_marker: Option<String>,
    pub prefix: Option<String>,
}