From c5c8f08a9a8bd058a85cccc83dca62af9a8b9949 Mon Sep 17 00:00:00 2001
From: Maxime Cannoodt
Date: Mon, 4 Jul 2022 20:32:28 +0200
Subject: [PATCH] new download button
---
webapp/src/routes/note/[id].svelte | 22 ++++++++++++++--------
1 file changed, 14 insertions(+), 8 deletions(-)
diff --git a/webapp/src/routes/note/[id].svelte b/webapp/src/routes/note/[id].svelte
index 166b0d8..420b1fa 100644
--- a/webapp/src/routes/note/[id].svelte
+++ b/webapp/src/routes/note/[id].svelte
@@ -29,7 +29,8 @@
let plaintext: string;
let timeString: string;
let decryptFailed = false;
- let downloadUrl: string;
+ // let downloadUrl: string;
+ let downloadRef: HTMLAnchorElement;
onMount(() => {
if (browser) {
@@ -46,18 +47,22 @@
timeString = msToString(diff_ms);
}
- $: if (plaintext) {
- downloadUrl = getDownloadUrl(plaintext);
- }
+ // $: if (plaintext) {
+ // downloadUrl = downloadMd(plaintext);
+ // }
// https://stackoverflow.com/questions/19327749/javascript-blob-filename-without-link
- function getDownloadUrl(text: string): string {
+ function downloadMd() {
+ if (plaintext === undefined) return;
// Make sure the browser reads the data as UTF-8
// https://stackoverflow.com/questions/6672834/specifying-blob-encoding-in-google-chrome
const BOM = new Uint8Array([0xef, 0xbb, 0xbf]);
- const blob = new Blob([BOM, text], { type: 'text/plain' });
+ const blob = new Blob([BOM, plaintext], { type: 'text/plain' });
const url = window.URL.createObjectURL(blob);
console.log(url);
+ downloadRef.href = url;
+ downloadRef.click();
+ window.URL.revokeObjectURL(blob);
return url;
}
@@ -86,10 +91,11 @@
e2e encrypted | Shared {timeString} ago
-
+
+ .
+