pub struct Storage { /* private fields */ }Expand description
The storage facade: a service + connection + signer with high-level helpers.
Implementations§
Source§impl Storage
impl Storage
Sourcepub fn new(
conn: DatabaseConnection,
service: Arc<dyn Service>,
signer: Signer,
) -> Self
pub fn new( conn: DatabaseConnection, service: Arc<dyn Service>, signer: Signer, ) -> Self
Build a storage facade from an explicit service and signer.
Sourcepub async fn from_config(conn: DatabaseConnection) -> Result<Self>
pub async fn from_config(conn: DatabaseConnection) -> Result<Self>
Build from the storage config section (current environment) plus a signer
read from DOIDO_SECRET_KEY_BASE.
Sourcepub fn with_prefix(self, prefix: impl Into<String>) -> Self
pub fn with_prefix(self, prefix: impl Into<String>) -> Self
Override the URL route prefix (default /doido/storage).
Sourcepub fn with_expiry(self, expires_in: Duration) -> Self
pub fn with_expiry(self, expires_in: Duration) -> Self
Override how long generated URLs stay valid (default 5 minutes).
Sourcepub fn conn(&self) -> &DatabaseConnection
pub fn conn(&self) -> &DatabaseConnection
The sea-orm connection.
Sourcepub fn prefix(&self) -> &str
pub fn prefix(&self) -> &str
The route prefix used by crate::serving::routes.
Sourcepub async fn ensure_tables(&self) -> Result<()>
pub async fn ensure_tables(&self) -> Result<()>
Create the metadata tables if they don’t exist (test/dev convenience).
Sourcepub async fn create_and_upload(
&self,
filename: &str,
data: Vec<u8>,
metadata: Option<Value>,
) -> Result<Blob>
pub async fn create_and_upload( &self, filename: &str, data: Vec<u8>, metadata: Option<Value>, ) -> Result<Blob>
Upload data to the service and record a blob. Detects content type,
computes the MD5 checksum and byte size.
Sourcepub async fn purge(&self, key: &str) -> Result<()>
pub async fn purge(&self, key: &str) -> Result<()>
Delete a blob everywhere: the service object, its attachment rows, and the metadata row.
Sourcepub async fn attach_upload(
&self,
record_type: &str,
record_id: &str,
name: &str,
filename: &str,
data: Vec<u8>,
) -> Result<Blob>
pub async fn attach_upload( &self, record_type: &str, record_id: &str, name: &str, filename: &str, data: Vec<u8>, ) -> Result<Blob>
Upload a file and attach it to record under name (append — for
has_many). Returns the new blob.
Sourcepub async fn attach(
&self,
record_type: &str,
record_id: &str,
name: &str,
blob_key: &str,
) -> Result<()>
pub async fn attach( &self, record_type: &str, record_id: &str, name: &str, blob_key: &str, ) -> Result<()>
Attach an existing blob to record under name (append).
Sourcepub async fn one(
&self,
record_type: &str,
record_id: &str,
name: &str,
) -> Result<Option<Blob>>
pub async fn one( &self, record_type: &str, record_id: &str, name: &str, ) -> Result<Option<Blob>>
has_one_attached: the attached blob, if any.
Sourcepub async fn many(
&self,
record_type: &str,
record_id: &str,
name: &str,
) -> Result<Vec<Blob>>
pub async fn many( &self, record_type: &str, record_id: &str, name: &str, ) -> Result<Vec<Blob>>
has_many_attached: all attached blobs.
Sourcepub async fn detach(
&self,
record_type: &str,
record_id: &str,
name: &str,
) -> Result<()>
pub async fn detach( &self, record_type: &str, record_id: &str, name: &str, ) -> Result<()>
Detach (but don’t purge) everything in the name slot.
Sourcepub async fn purge_for_record(
&self,
record_type: &str,
record_id: &str,
) -> Result<()>
pub async fn purge_for_record( &self, record_type: &str, record_id: &str, ) -> Result<()>
Purge every blob attached to a record (the dependent: :purge default),
then remove the attachment rows. Call from a model’s after-destroy hook.
Sourcepub fn signed_id(&self, key: &str) -> String
pub fn signed_id(&self, key: &str) -> String
A permanent signed id for a blob key (Rails blob.signed_id).
Sourcepub fn verify_signed_id(&self, signed_id: &str) -> Result<String>
pub fn verify_signed_id(&self, signed_id: &str) -> Result<String>
Resolve a signed id back to a blob key, erroring if tampered/expired.
Sourcepub fn redirect_path(&self, blob: &Blob) -> String
pub fn redirect_path(&self, blob: &Blob) -> String
The redirect URL for a blob ({prefix}/blobs/redirect/{signed_id}/{filename})
— the stable URL to put in HTML. The redirect handler 302s to the service’s
native URL (S3/Azure) or to the proxy route (disk/memory).
Sourcepub fn proxy_path(&self, blob: &Blob) -> String
pub fn proxy_path(&self, blob: &Blob) -> String
The proxy URL for a blob (streams through the app).
Trait Implementations§
Auto Trait Implementations§
impl !RefUnwindSafe for Storage
impl !UnwindSafe for Storage
impl Freeze for Storage
impl Send for Storage
impl Sync for Storage
impl Unpin for Storage
impl UnsafeUnpin for Storage
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<A, B, T> HttpServerConnExec<A, B> for Twhere
B: Body,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more