Skip to main content

Storage

Struct Storage 

Source
pub struct Storage { /* private fields */ }
Expand description

The storage facade: a service + connection + signer with high-level helpers.

Implementations§

Source§

impl Storage

Source

pub fn new( conn: DatabaseConnection, service: Arc<dyn Service>, signer: Signer, ) -> Self

Build a storage facade from an explicit service and signer.

Source

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.

Source

pub fn with_prefix(self, prefix: impl Into<String>) -> Self

Override the URL route prefix (default /doido/storage).

Source

pub fn with_expiry(self, expires_in: Duration) -> Self

Override how long generated URLs stay valid (default 5 minutes).

Source

pub fn conn(&self) -> &DatabaseConnection

The sea-orm connection.

Source

pub fn service(&self) -> &Arc<dyn Service>

The active storage service.

Source

pub fn prefix(&self) -> &str

The route prefix used by crate::serving::routes.

Source

pub async fn ensure_tables(&self) -> Result<()>

Create the metadata tables if they don’t exist (test/dev convenience).

Source

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.

Source

pub async fn find_blob(&self, key: &str) -> Result<Option<Blob>>

Find a blob by key.

Source

pub async fn download(&self, key: &str) -> Result<Vec<u8>>

Download a blob’s bytes.

Source

pub async fn purge(&self, key: &str) -> Result<()>

Delete a blob everywhere: the service object, its attachment rows, and the metadata row.

Source

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.

Source

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).

Source

pub async fn one( &self, record_type: &str, record_id: &str, name: &str, ) -> Result<Option<Blob>>

has_one_attached: the attached blob, if any.

Source

pub async fn many( &self, record_type: &str, record_id: &str, name: &str, ) -> Result<Vec<Blob>>

has_many_attached: all attached blobs.

Source

pub async fn detach( &self, record_type: &str, record_id: &str, name: &str, ) -> Result<()>

Detach (but don’t purge) everything in the name slot.

Source

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.

Source

pub fn signed_id(&self, key: &str) -> String

A permanent signed id for a blob key (Rails blob.signed_id).

Source

pub fn verify_signed_id(&self, signed_id: &str) -> Result<String>

Resolve a signed id back to a blob key, erroring if tampered/expired.

Source

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).

Source

pub fn proxy_path(&self, blob: &Blob) -> String

The proxy URL for a blob (streams through the app).

Source

pub async fn url_for( &self, blob: &Blob, disposition: Disposition, ) -> Result<String>

A URL a client can GET to fetch the object: the service’s native (presigned/public) URL if it has one, else the proxy route.

Trait Implementations§

Source§

impl Clone for Storage

Source§

fn clone(&self) -> Storage

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> FromRef<T> for T
where T: Clone,

Source§

fn from_ref(input: &T) -> T

Converts to this type from a reference to the input type.
Source§

impl<A, B, T> HttpServerConnExec<A, B> for T
where B: Body,

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more