summaryrefslogtreecommitdiff
path: root/src/model/utility.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/model/utility.rs')
-rw-r--r--src/model/utility.rs45
1 files changed, 45 insertions, 0 deletions
diff --git a/src/model/utility.rs b/src/model/utility.rs
new file mode 100644
index 0000000..617ee45
--- /dev/null
+++ b/src/model/utility.rs
@@ -0,0 +1,45 @@
+#[derive(Clone)]
+pub struct Download {
+ pub file_name: String,
+ pub content: String,
+ pub mime_type: MimeType,
+}
+
+impl Download {
+ pub fn as_data_link(&self) -> String {
+ let data = base64::encode(&*self.content);
+ let uri_component: String = js_sys::encode_uri_component(&data).into();
+
+ format!("data:{};base64,{}", self.mime_type.as_text(), uri_component)
+ }
+}
+
+#[derive(Clone, Copy)]
+pub enum MimeType {
+ PDF,
+ VCard,
+ SVG,
+}
+
+impl MimeType {
+ pub fn as_text(&self) -> &str {
+ match self {
+ MimeType::PDF => "application/pdf",
+ MimeType::VCard => "text/vcard",
+ MimeType::SVG => "image/svg+xml",
+ }
+ }
+}
+
+#[derive(Clone, Copy, PartialEq)]
+pub enum DownloadOption {
+ PDF,
+ VCard,
+ QrCode,
+}
+
+#[derive(Clone, Debug, PartialEq)]
+pub struct File {
+ pub name: String,
+ pub content: String,
+}