Skip to content

Commit

Permalink
Add generating banner to website
Browse files Browse the repository at this point in the history
  • Loading branch information
liameno committed Jun 17, 2022
1 parent 65c9bea commit 563f824
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 22 deletions.
43 changes: 23 additions & 20 deletions website/frontend/js/search_encrypt.js
Original file line number Diff line number Diff line change
@@ -1,33 +1,35 @@
let rsa = new JSEncrypt({default_key_size: 1024});
let is_started = true;
let is_generating = true;

let public_key = get_with_expiry("public_key");
let private_key = get_with_expiry("private_key");

if (public_key == null || private_key == null) {
rsa.getKey(function() {
let public_key = get_with_expiry("public_key");
let private_key = get_with_expiry("private_key");

if (public_key == null) {
set_with_expiry("public_key", rsa.getPublicKey(), 3600 * 1000); //1 hour
}
if (private_key == null) {
set_with_expiry("private_key", rsa.getPrivateKey(), 3600 * 1000); //1 hour
}
function load() {
var title = document.getElementsByClassName("title")[0];
title.innerHTML = "GENERATING...";

set_with_expiry("public_key", rsa.getPublicKey(), 3600 * 1000); //1 hour
set_with_expiry("private_key", rsa.getPrivateKey(), 3600 * 1000); //1 hour
if (public_key == null || private_key == null) {
rsa.getKey(function() {
const expire_time = 3600 * 1000; //1 hour

is_started = false;
set_with_expiry("public_key", rsa.getPublicKey(), expire_time);
set_with_expiry("private_key", rsa.getPrivateKey(), expire_time);

title.innerHTML = "librengine";
is_generating = false;
});
} else {
is_started = false;
} else {
title.innerHTML = "librengine";
is_generating = false;
}
}

function submit_form() {
if (is_started) return false;
is_started = true;
if (is_generating) {
return false;
}

is_generating = true;

let form = document.getElementById("search_widget");
let query = document.getElementById("q");
Expand All @@ -47,5 +49,6 @@ function submit_form() {
key.value = btoa(public_key);

form.submit();

return false;
}
}
4 changes: 2 additions & 2 deletions website/frontend/src/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<script src="../js/localstorage.js"></script>
<script src="../js/search_encrypt.js"></script>
</head>
<body>
<body onload="load()">
<div class="background"></div>
<div class="container">
<header class="top_container">
Expand Down Expand Up @@ -50,4 +50,4 @@
</div>
</div>
</body>
</html>
</html>

0 comments on commit 563f824

Please sign in to comment.