pub struct BucketModule {
pub locking_service: Arc<LockingService>,
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>§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
impl BucketModule
Sourcepub fn http_routes(&self) -> Router
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.
Sourcepub fn crud_router(&self) -> Router
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.
Sourcepub fn serving_router<A>(
&self,
authz: ArcAuthzPolicy<A>,
) -> BucketResult<Router>
pub fn serving_router<A>( &self, authz: ArcAuthzPolicy<A>, ) -> BucketResult<Router>
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.
Sourcepub fn upload_router<A>(&self, config: UploadConfig) -> BucketResult<Router>
pub fn upload_router<A>(&self, config: UploadConfig) -> BucketResult<Router>
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.
Sourcepub fn router<A>(&self, opts: RouterOptions<A>) -> BucketResult<Router>
pub fn router<A>(&self, opts: RouterOptions<A>) -> BucketResult<Router>
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
impl BucketModule
Sourcepub fn builder() -> BucketModuleBuilder
pub fn builder() -> BucketModuleBuilder
Create a new module builder
Sourcepub fn all_crud_routes(&self) -> Router
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.
Sourcepub fn routes(&self) -> Router
👎Deprecated: mounts unvalidated generic CRUD; prefer readonly_routes() + validated writes, or all_crud_routes() for the full/unguarded surface
pub fn routes(&self) -> Router
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.
Sourcepub fn readonly_routes(&self) -> Router
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.
Sourcepub fn upload_context(&self) -> Option<UploadContext>
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§
impl !RefUnwindSafe for BucketModule
impl !UnwindSafe for BucketModule
impl Freeze for BucketModule
impl Send for BucketModule
impl Sync for BucketModule
impl Unpin for BucketModule
impl UnsafeUnpin for BucketModule
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
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