Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
### Added

* `ResourceTable`
* "Select file" button to `DropImageFile` component
* `ImageUpload` helper struct to `DropImageFile`
* "Select file" button to `DropImageFile`

### Fixed

Expand Down
2 changes: 1 addition & 1 deletion src/form/data/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use vertigo::Value;
use crate::ValidationErrors;

mod data_field;
pub use data_field::{DataFieldValue, ImageValue, TextAreaValue};
pub use data_field::{CustomValue, DataFieldValue, ImageValue, TextAreaValue};

mod form_export;
pub use form_export::{FieldExport, FormExport};
Expand Down
33 changes: 33 additions & 0 deletions src/image_upload.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
use base64::{Engine as _, engine::general_purpose::STANDARD_NO_PAD as BASE_64};
use vertigo::DropFileItem;

use crate::name_to_mime;

#[derive(Clone, Debug, PartialEq, vertigo::AutoJsJson)]
pub struct ImageUpload {
pub name: String,
pub mime: Option<String>,
pub data: String, // base64
}

impl ImageUpload {
pub fn to_vec(&self) -> Result<Vec<u8>, base64::DecodeError> {
BASE_64.decode(&self.data)
}
}

impl From<DropFileItem> for ImageUpload {
fn from(item: DropFileItem) -> Self {
let mime_str = name_to_mime(&item.name);
let mime = if mime_str == "application/octet-stream" {
None
} else {
Some(mime_str.to_string())
};
Self {
name: item.name.clone(),
mime,
data: BASE_64.encode(&*item.data),
}
}
}
2 changes: 2 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use std::{collections::HashMap, fmt::Display, str::FromStr};
pub mod button;
mod drop_image_file;
pub mod form;
mod image_upload;
mod input;
pub mod login;
mod popup;
Expand All @@ -18,6 +19,7 @@ mod with_loader;
pub use {
button::{Button, ButtonColor, ButtonVariant, TableButton},
drop_image_file::{DropImageFile, DropImageFileParams, image_as_uri, name_to_mime},
image_upload::ImageUpload,
input::{Input, InputWithButton, InputWithButtonParams, ListInput},
popup::{Popup, PopupOnHover, PopupParams},
search_panel::{SearchPanel, SearchPanelParams, SearchResult},
Expand Down
Loading