From ecdb6c7db16406a20b56e7bb6e73d4c59ee246f1 Mon Sep 17 00:00:00 2001 From: Vika Date: Thu, 21 Jul 2022 13:03:37 +0300 Subject: media: improve Metadata typing content_type is now optional; if not specified, it will remain empty. `application/octet-stream` will be put on read in the frontend. Length is now represented as NonZeroUsize - why would you upload a zero-byte file when you can just conjure one from the void whenever you need one? This should save me a little bit of memory. Representing content_type as a typed MIME value would be the next logical step. --- kittybox-rs/src/media/storage/mod.rs | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) (limited to 'kittybox-rs/src/media/storage/mod.rs') diff --git a/kittybox-rs/src/media/storage/mod.rs b/kittybox-rs/src/media/storage/mod.rs index 5614437..b34da88 100644 --- a/kittybox-rs/src/media/storage/mod.rs +++ b/kittybox-rs/src/media/storage/mod.rs @@ -5,22 +5,24 @@ use bytes::Bytes; use serde::{Deserialize, Serialize}; use std::pin::Pin; use std::fmt::Debug; +use std::num::NonZeroUsize; pub mod file; #[derive(Debug, Deserialize, Serialize)] pub struct Metadata { - pub(super) content_type: String, - pub(super) filename: Option, - pub(super) length: Option + /// Content type of the file. If None, the content-type is considered undefined. + pub content_type: Option, + /// The original filename that was passed. + pub filename: Option, + /// The recorded length of the file. + pub length: Option, } impl From<&Field<'_>> for Metadata { fn from(field: &Field<'_>) -> Self { Self { content_type: field.content_type() - .map(|i| i.to_owned()) - .or_else(|| Some("application/octet-stream".to_owned())) - .unwrap(), + .map(|i| i.to_owned()), filename: field.file_name() .map(|i| i.to_owned()), length: None -- cgit 1.4.1