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 Freeze for MediaLibrary
impl !RefUnwindSafe for MediaLibrary
impl Send for MediaLibrary
impl Sync for MediaLibrary
impl Unpin for MediaLibrary
impl UnsafeUnpin for MediaLibrary
impl !UnwindSafe 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