From 91d70b97db0e58bfd45932732e3f2e31d08236b3 Mon Sep 17 00:00:00 2001
From: phoebus-84
Date: Tue, 6 Aug 2024 12:32:35 +0200
Subject: [PATCH 1/2] feat: directory picker
---
golang/wasm/wasm_exec.html | 219 ++++++++++++++++++---------------
golang/wasm/wasm_exec_es6.html | 100 +++++++++++++++
2 files changed, 217 insertions(+), 102 deletions(-)
create mode 100644 golang/wasm/wasm_exec_es6.html
diff --git a/golang/wasm/wasm_exec.html b/golang/wasm/wasm_exec.html
index 19debfd..edaf521 100644
--- a/golang/wasm/wasm_exec.html
+++ b/golang/wasm/wasm_exec.html
@@ -1,103 +1,118 @@
-
-
- Go<>JS Demo
-
-
-
-
-
- DNS Keys
- List Keystore
-
-
-
-
-
- Request
-
-
-
-
- Search Keystore for Key to sign update for a given Subdomain
-
-
-
-
-
- Find DOH Endpoint for a given Subdomain
-
-
-
-
-
- Import Key pair files from filesystem into Browser Keystore
-
-
-
-
-
-
-
+
+
+
+
+
+ Go<>JS Demo
+
+
+
+
+ DNS
+ DOH Resolver
+
+
+
+
+
+
+
+ DNS Keys
+ List Keystore
+
+
+
+
+ Request
+
+
+
+
+
+ Search Keystore for Key to sign update for a given Subdomain
+
+
+
+
+
+
+ Find DOH Endpoint for a given Subdomain
+
+
+
+
+
+
+ Import Key pair files from filesystem into Browser Keystore
+
+
+
+
+
+
+
+
diff --git a/golang/wasm/wasm_exec_es6.html b/golang/wasm/wasm_exec_es6.html
new file mode 100644
index 0000000..94eef46
--- /dev/null
+++ b/golang/wasm/wasm_exec_es6.html
@@ -0,0 +1,100 @@
+
+
+
+
+
+ Go<>JS Demo
+
+
+
+
+ DNS
+ DOH Resolver
+
+
+
+
+
+
+
+ DNS Keys
+ List Keystore
+
+
+
+
+ Request
+
+
+
+
+
+ Search Keystore for Key to sign update for a given Subdomain
+
+
+
+
+
+
+ Find DOH Endpoint for a given Subdomain
+
+
+
+
+
+
+ Import Key pair files from filesystem into Browser Keystore
+
+
+
+
+
+
+
+
+
From 95ac124b845bd3e798ba207ddeb9769fe985ad91 Mon Sep 17 00:00:00 2001
From: phoebus-84
Date: Tue, 6 Aug 2024 13:05:38 +0200
Subject: [PATCH 2/2] refactor: put dirctory handler in pure.js
---
golang/wasm/pure.js | 46 ++++++++++++++++++++++++++++++
golang/wasm/wasm_exec_es6.html | 51 ++--------------------------------
2 files changed, 48 insertions(+), 49 deletions(-)
diff --git a/golang/wasm/pure.js b/golang/wasm/pure.js
index ae28bc2..b49e678 100644
--- a/golang/wasm/pure.js
+++ b/golang/wasm/pure.js
@@ -211,3 +211,49 @@ async function findDOHEndpoint() {
return
}
+
+async function handleFileSelection(event) {
+ const files = Array.from(event.target.files);
+ const fileList = document.getElementById('fileList');
+ fileList.innerHTML = ''; // Clear any existing list items
+
+ const filePairs = {};
+
+ files.forEach(file => {
+ const fileName = file.name;
+ const fileExt = fileName.split('.').pop().toLowerCase();
+ const baseName = fileName.slice(0, fileName.lastIndexOf('.'));
+
+ if (fileExt === 'key' || fileExt === 'private') {
+ if (!filePairs[baseName]) {
+ filePairs[baseName] = {};
+ }
+ if (fileExt === 'key') {
+ filePairs[baseName].keyFile = file;
+ } else if (fileExt === 'private') {
+ filePairs[baseName].privateFile = file;
+ }
+ }
+ });
+
+ for (const [baseName, pair] of Object.entries(filePairs)) {
+ if (pair.keyFile && pair.privateFile) {
+ if (localStorage.getItem(baseName)) {
+ const li = document.createElement('li');
+ li.textContent = `${baseName}: Already registered`;
+ fileList.appendChild(li);
+ } else {
+ const keyContent = await pair.keyFile.text();
+ const privateContent = await pair.privateFile.text();
+ const jsonString = JSON.stringify({ key: keyContent, private: privateContent });
+
+ localStorage.setItem(baseName, jsonString);
+
+ const li = document.createElement('li');
+ li.textContent = `${baseName}: Saved to localStorage`;
+ fileList.appendChild(li);
+ }
+ }
+ }
+}
+
diff --git a/golang/wasm/wasm_exec_es6.html b/golang/wasm/wasm_exec_es6.html
index 94eef46..022c37b 100644
--- a/golang/wasm/wasm_exec_es6.html
+++ b/golang/wasm/wasm_exec_es6.html
@@ -43,58 +43,11 @@ Find DOH Endpoint for a given Subdomain
- Import Key pair files from filesystem into Browser Keystore
+ Import Key pair files from filesystem into Browser Keystore
-
+
-
-