pub struct MediaLibrary {
pub backend: Arc<dyn StorageBackend>,
pub max_size: Option<usize>,
pub allowed_types: Vec<String>,
}Fields§
§backend: Arc<dyn StorageBackend>§max_size: Option<usize>§allowed_types: Vec<String>Implementations§
Source§impl MediaLibrary
impl MediaLibrary
pub fn new(backend: Arc<dyn StorageBackend>) -> Self
Sourcepub fn allow_mime(self, mime: impl Into<String>) -> Self
pub fn allow_mime(self, mime: impl Into<String>) -> Self
Mendaftarkan MIME type yang diizinkan (misal “image/png”)
Sourcepub fn upload(
&self,
original_name: &str,
mime_type: &str,
data: &[u8],
) -> Result<MediaFile, String>
pub fn upload( &self, original_name: &str, mime_type: &str, data: &[u8], ) -> Result<MediaFile, String>
Melakukan upload berkas mentah (raw bytes) dengan validasi lengkap
Sourcepub fn delete(&self, file: &MediaFile) -> Result<(), String>
pub fn delete(&self, file: &MediaFile) -> Result<(), String>
Menghapus file media dari penyimpanan backend
Sourcepub fn create_thumbnail(
&self,
source_file: &MediaFile,
width: u32,
height: u32,
) -> Result<MediaFile, String>
pub fn create_thumbnail( &self, source_file: &MediaFile, width: u32, height: u32, ) -> Result<MediaFile, String>
Mengubah ukuran gambar (resize & crop) menjadi thumbnail kotak/persegi
Sourcepub fn convert_to_webp(
&self,
source_file: &MediaFile,
) -> Result<MediaFile, String>
pub fn convert_to_webp( &self, source_file: &MediaFile, ) -> Result<MediaFile, String>
Mengkonversi gambar PNG/JPEG menjadi format WebP modern ultra-ringan
Sourcepub fn get_category(mime_type: &str) -> String
pub fn get_category(mime_type: &str) -> String
Mengkategorikan tipe file secara otomatis berdasarkan MIME type
Auto Trait Implementations§
impl !RefUnwindSafe for MediaLibrary
impl !UnwindSafe for MediaLibrary
impl Forget for MediaLibrary
impl Freeze for MediaLibrary
impl Send for MediaLibrary
impl Sync for MediaLibrary
impl Unpin for MediaLibrary
impl UnsafeUnpin for MediaLibrary
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
Mutably borrows from an owned value. Read more
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> ⓘ
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 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> ⓘ
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