summaryrefslogtreecommitdiff
path: root/src/viewmodel/utility.rs
diff options
context:
space:
mode:
authorjelemux <jeremias.weber@protonmail.com>2020-11-25 10:31:04 +0100
committerjelemux <jeremias.weber@protonmail.com>2020-11-25 10:31:04 +0100
commitb1ba906491a1ed396d47b0751f080fef991ea344 (patch)
treec8e306c217dbdc352e66000822d8fc7e4cdc55fb /src/viewmodel/utility.rs
parent5a03734b6767fed04c0913384584d8f59dc597ea (diff)
downloadwasm-card-b1ba906491a1ed396d47b0751f080fef991ea344.tar.gz
wasm-card-b1ba906491a1ed396d47b0751f080fef991ea344.tar.bz2
Struktur umbauen
Diffstat (limited to 'src/viewmodel/utility.rs')
-rw-r--r--src/viewmodel/utility.rs39
1 files changed, 39 insertions, 0 deletions
diff --git a/src/viewmodel/utility.rs b/src/viewmodel/utility.rs
new file mode 100644
index 0000000..a296c1e
--- /dev/null
+++ b/src/viewmodel/utility.rs
@@ -0,0 +1,39 @@
+#[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)]
+pub enum DownloadOption {
+ PDF,
+ VCard,
+ QrCode,
+} \ No newline at end of file