Skip to main content

Crate doido_storage

Crate doido_storage 

Source
Expand description

§doido-storage

Attached-file storage for the Doido framework — the ActiveStorage analogue.

It stores file bytes through a pluggable Service (disk by default, plus in-memory, S3, Cloudflare R2 and Azure Blob behind features) and keeps metadata (blobs, polymorphic attachments, variant records) in the database. The Storage facade ties a service, a connection and a Signer together and offers Rails-like operations; serving::routes mounts the blob-serving and direct-upload endpoints on axum.

use doido_storage::{Storage, MemoryService, Signer};
use std::sync::Arc;

let storage = Storage::new(conn, Arc::new(MemoryService::default()), Signer::from_env());
storage.ensure_tables().await?;
let blob = storage.create_and_upload("hello.txt", b"hi".to_vec(), None).await?;
let bytes = storage.download(&blob.key).await?;
assert_eq!(bytes, b"hi");

Re-exports§

pub use blob::Blob;
pub use client::Storage;
pub use config::ServiceBackend;
pub use config::ServiceConfig;
pub use config::StorageConfig;
pub use error::StorageError;
pub use providers::disk::DiskService;
pub use providers::memory::MemoryService;
pub use registry::register_adapter;
pub use registry::registered_adapters;
pub use registry::ServiceFactory;
pub use schema::ensure_tables;
pub use service::Service;
pub use service::UrlOptions;
pub use signing::Disposition;
pub use signing::Signer;

Modules§

attachments
Polymorphic attachments — the has_one_attached / has_many_attached analogue, exposed as helper functions over (record_type, record_id, name).
blob
Blob metadata records and their database operations.
checksum
Integrity helpers: the base64-encoded MD5 checksum ActiveStorage stores on each blob, plus byte size.
client
Storage — the ergonomic facade over a service + database + signer.
config
Per-environment storage configuration, loaded from the storage section of config/<env>.yml — the analogue of Rails’ config/storage.yml plus config.active_storage.service.
content_type
Content-type detection — a compact, dependency-free analogue of Rails’ Marcel.
error
Typed storage errors (thiserror per crate, per the framework convention).
providers
Storage provider drivers — every concrete Service backend kept together in one isolated module.
registry
Custom storage adapters — the first-class extension point for integrating an external file service.
schema
Metadata tables for blobs, attachments and variant records.
service
The pluggable storage backend trait — the storage layer’s analogue of [doido_cache::CacheStore].
serving
Axum handlers that serve blobs and accept direct uploads — the analogue of ActiveStorage’s blobs/disk/direct_uploads controllers.
signing
HMAC-SHA256 signed ids and signed URLs — the analogue of Rails’ message verifier used by ActiveStorage signed_ids and disk-service URLs.