diff --git a/static/index.html b/static/index.html index cb1d08b..9104509 100644 --- a/static/index.html +++ b/static/index.html @@ -107,6 +107,21 @@ + + +
+
Password does not exist
+ +

+ The password you requested may have expired, been viewed + before or never even existed in the first place. +

+ +
+ +
+
+
diff --git a/static/index.js b/static/index.js index 96c78e3..ee21acf 100644 --- a/static/index.js +++ b/static/index.js @@ -122,6 +122,7 @@ function showError(error) { errorMessage.value = error; errorDialog.showModal(); + console.error(error); } function init() { @@ -185,23 +186,51 @@ function init() { }); } -function confirmViewPassword() { +async function confirmViewPassword(params) { const confirmDialog = document.querySelector("dialog#confirm-view"); const confirm = document.querySelector("button#confirm-view"); + const loadingDialog = document.querySelector("dialog#loading"); + const passwordNEDialog = document.querySelector("dialog#password-ne"); + try { + loadingDialog.showModal(); + + const res = await fetch(`/api/password/${params.get("id")}`, { + method: "HEAD", + }); + console.log(res.status); + if (res.status == 404) { + loadingDialog.close(); + passwordNEDialog.showModal(); + console.log("Return"); + + return; + } + + if (!res.ok) { + const msg = await res.text(); + throw new Error( + `Failed to check if password exists: ${res.status}: ${msg}`, + ); + } + } catch (error) { + showError(error); + } finally { + } + + loadingDialog.close(); confirmDialog.showModal(); confirm.addEventListener("click", (ev) => { confirmDialog.close(); - viewPassword(); + viewPassword(params); }); } -async function viewPassword() { +async function viewPassword(params) { const viewDialog = document.querySelector("dialog#view"); const password = document.querySelector("textarea#password"); const loadingDialog = document.querySelector("dialog#loading"); - const params = new URLSearchParams(window.location.search); try { loadingDialog.showModal(); @@ -232,7 +261,8 @@ async function viewPassword() { window.addEventListener("load", () => { const query = window.location.search; if (query.trim() != "") { - confirmViewPassword(); + const params = new URLSearchParams(window.location.search); + confirmViewPassword(params); } init();