Skip to main content

MediaLibrary

Struct MediaLibrary 

Source
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

Source

pub fn new(backend: Arc<dyn StorageBackend>) -> Self

Source

pub fn max_size(self, size: usize) -> Self

Menetapkan batas ukuran file maksimal (Bytes)

Source

pub fn allow_mime(self, mime: impl Into<String>) -> Self

Mendaftarkan MIME type yang diizinkan (misal “image/png”)

Source

pub fn upload( &self, original_name: &str, mime_type: &str, data: &[u8], ) -> Result<MediaFile, String>

Melakukan upload berkas mentah (raw bytes) dengan validasi lengkap

Source

pub fn delete(&self, file: &MediaFile) -> Result<(), String>

Menghapus file media dari penyimpanan backend

Source

pub fn create_thumbnail( &self, source_file: &MediaFile, width: u32, height: u32, ) -> Result<MediaFile, String>

Mengubah ukuran gambar (resize & crop) menjadi thumbnail kotak/persegi

Source

pub fn convert_to_webp( &self, source_file: &MediaFile, ) -> Result<MediaFile, String>

Mengkonversi gambar PNG/JPEG menjadi format WebP modern ultra-ringan

Source

pub fn get_category(mime_type: &str) -> String

Mengkategorikan tipe file secara otomatis berdasarkan MIME type

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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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