Skip to main content

BucketModule

Struct BucketModule 

Source
pub struct BucketModule {
    pub locking_service: Arc<LockingService>,
    pub deduplication_service: Arc<DeduplicationService>,
    pub multipart_upload_service: Arc<MultipartUploadService>,
    pub conversion_service: Arc<ConversionService>,
    pub cdn_service: Arc<CdnService>,
    pub video_thumbnail_service: Arc<VideoThumbnailService>,
    pub document_preview_service: Arc<DocumentPreviewService>,
    pub storage: Option<Arc<dyn ObjectStorage>>,
    pub bucket_config: Option<Arc<BucketConfig>>,
    pub file_service: Option<Arc<FileService>>,
    pub stored_file_repository: Arc<StoredFileRepository>,
    /* private fields */
}
Expand description

Bucket module configuration

Use the builder pattern to configure and register this module:

let bucket = BucketModule::builder()
    .with_database(pool.clone())
    .build()?;

// Unguarded full CRUD (trusted/admin); compose a guarded router for production.
let router = bucket.all_crud_routes();

Fields§

§locking_service: Arc<LockingService>§deduplication_service: Arc<DeduplicationService>§multipart_upload_service: Arc<MultipartUploadService>§conversion_service: Arc<ConversionService>§cdn_service: Arc<CdnService>§video_thumbnail_service: Arc<VideoThumbnailService>§document_preview_service: Arc<DocumentPreviewService>§storage: Option<Arc<dyn ObjectStorage>>

Storage backend (mode-B serving + uploads). None until .with_storage() is called.

§bucket_config: Option<Arc<BucketConfig>>

Bucket-module config (storage + serving). None until .with_config() is called.

§file_service: Option<Arc<FileService>>

High-level file operations service, wired when both storage and bucket_config are set.

§stored_file_repository: Arc<StoredFileRepository>

Direct handle to the StoredFile repository — used by the mode-B serving handler to look up files by storage_key.

Implementations§

Source§

impl BucketModule

Source

pub fn http_routes(&self) -> Router

HTTP routes for the 10 active CRUD stacks.

Excludes Thumbnail, FileVersion, AccessLog — child entities managed through their parent (StoredFile/Bucket) and not exposed as independent endpoints.

Source

pub fn crud_router(&self) -> Router

The 10 generated CRUD routers, composed.

Alias for Self::http_routes. Returns the existing /api/v1/bucket/* router — unchanged from before the serving handler was added. Named to pair symmetrically with Self::serving_router.

Source

pub fn serving_router<A>( &self, authz: ArcAuthzPolicy<A>, ) -> BucketResult<Router>
where A: AuthExtractor<()> + HasOwnerId + Clone + 'static, A::Rejection: IntoResponse,

Build the mode-B serving router.

A is the consumer’s AuthExtractor — and, since Axum extractors yield themselves, also the identity type the crate::auth::AuthzPolicy decides on.

Returns Err when .with_storage() / .with_config() were not called on the builder — the serving handler can’t operate without both.

Source

pub fn upload_router<A>(&self, config: UploadConfig) -> BucketResult<Router>
where A: AuthExtractor<()> + HasOwnerId + Clone + 'static, A::Rejection: IntoResponse,

Build the multipart upload router.

Mounts five routes (see crate::presentation::http::upload): single-shot POST /uploads, and the resumable session lifecycle under /uploads/sessions. The consumer’s AuthExtractor A must also implement HasOwnerId so owner_id is derived from the authenticated identity instead of being trusted from input.

Returns Err when .with_storage() / .with_config() were not configured — uploads cannot run without an [ObjectStorage] backend and the wired-up crate::FileService.

Source

pub fn router<A>(&self, opts: RouterOptions<A>) -> BucketResult<Router>
where A: AuthExtractor<()> + HasOwnerId + Clone + 'static, A::Rejection: IntoResponse,

One-call composition: CRUD + upload + serving routers merged.

Pick this when the consumer just wants “everything the module exposes” under a single nest point. Each sub-router is still reachable individually via Self::crud_router / Self::upload_router / Self::serving_router for advanced composition.

The merged router pairs CRUD endpoints with the upload surface at the same prefix the consumer chooses (e.g. /api/v1/bucket), and nests the serving handler under serving_prefix (default /cdn). Passing RouterOptions::default() plus a configured BucketModule is the smallest possible wiring:

ⓘ
let app = Router::new()
    .nest("/api/v1/bucket", bucket.router::<MyUser>(opts)?);

Returns Err for the same reasons Self::serving_router and Self::upload_router do — .with_storage() and .with_config() are required on the builder.

Source§

impl BucketModule

Source

pub fn builder() -> BucketModuleBuilder

Create a new module builder

Source

pub fn all_crud_routes(&self) -> Router

Mount ALL generated CRUD endpoints (12 per entity) with NO domain validation — the fully unguarded surface. A well-formed request can create invalid rows or soft-delete a referenced master out from under its dependents. Prefer a guarded composition (read + validated writes) for any real deployment; use this only in trusted/admin/seeding contexts.

Source

pub fn routes(&self) -> Router

👎Deprecated:

mounts unvalidated generic CRUD; prefer readonly_routes() + validated writes, or all_crud_routes() for the full/unguarded surface

Deprecated alias for Self::all_crud_routes. routes() reads like “the routes” but mounts UNVALIDATED generic CRUD on every entity — a naive mount exposes unguarded writes. Compose a guarded router (read + validated writes) for production, or call all_crud_routes() to opt into the full unguarded surface explicitly.

Source

pub fn readonly_routes(&self) -> Router

Read-only routes for every entity (GET endpoints only) — the safe base.

Generic mutation can’t reach here, so this surface cannot bypass a validated write service’s invariants. Use this as the production base and merge validated write routes (or a write service’s HTTP layer) onto it.

Source

pub fn upload_context(&self) -> Option<UploadContext>

What upload_router needs, built from this module’s own services.

None until the module has both a storage backend and a config (the file service is wired only then). A host mounts uploads with upload_router::<I>(bucket.upload_context()?, config) and never holds the generic bucket service itself.

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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<Unshared, Shared> IntoShared<Shared> for Unshared
where Shared: FromUnshared<Unshared>,

Source§

fn into_shared(self) -> Shared

Creates a shared type from an unshared type.
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

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