link_common/models/
file_upload.rs1#[derive(Debug, Clone, PartialEq, Eq)]
5pub struct FileUpload {
6 pub placeholder: String,
8 pub filename: String,
10 pub data: Vec<u8>,
12 pub mime: Option<String>,
14}
15
16impl FileUpload {
17 pub fn new(placeholder: impl Into<String>, filename: impl Into<String>, data: Vec<u8>) -> Self {
19 Self {
20 placeholder: placeholder.into(),
21 filename: filename.into(),
22 data,
23 mime: None,
24 }
25 }
26
27 pub fn with_mime(mut self, mime: impl Into<String>) -> Self {
29 self.mime = Some(mime.into());
30 self
31 }
32}
33
34impl FileUpload {
35 pub(crate) fn into_owned_tuple(self) -> (String, String, Vec<u8>, Option<String>) {
36 (self.placeholder, self.filename, self.data, self.mime)
37 }
38}
39
40pub(crate) fn uploads_to_owned(
41 files: Option<Vec<FileUpload>>,
42) -> Option<Vec<(String, String, Vec<u8>, Option<String>)>> {
43 files.map(|items| items.into_iter().map(FileUpload::into_owned_tuple).collect())
44}