Skip to content

Commit 3486e0c

Browse files
committed
update search index decryption and reinitialization of search worker
1 parent a4ff153 commit 3486e0c

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

encryptcontent/decrypt-contents.tpl.js

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ function reload_js(src) {
136136
/* Decrypt part of the search index and refresh it for search engine */
137137
function decrypt_search(password_value, path_location) {
138138
sessionIndex = sessionStorage.getItem('encryptcontent-index');
139+
let could_decrypt = false;
139140
if (sessionIndex) {
140141
sessionIndex = JSON.parse(sessionIndex);
141142
for (var i=0; i < sessionIndex.docs.length; i++) {
@@ -144,6 +145,7 @@ function decrypt_search(password_value, path_location) {
144145
// grab the ciphertext bundle and try to decrypt it
145146
let title = decrypt_content_from_bundle(password_value, doc.title);
146147
if (title !== false) {
148+
could_decrypt = true;
147149
doc.title = title;
148150
// any post processing on the decrypted search index should be done here
149151
let content = decrypt_content_from_bundle(password_value, doc.text);
@@ -163,13 +165,16 @@ function decrypt_search(password_value, path_location) {
163165
}
164166
}
165167
}
166-
// force search index reloading on Worker
167-
if (!window.Worker) {
168-
console.log('Web Worker API not supported');
169-
} else {
168+
if (could_decrypt) {
169+
//save decrypted index
170170
sessionIndex = JSON.stringify(sessionIndex);
171171
sessionStorage.setItem('encryptcontent-index', sessionIndex);
172-
searchWorker.postMessage({init: true, sessionIndex: sessionIndex});
172+
// force search index reloading on Worker
173+
if (typeof searchWorker !== 'undefined') {
174+
searchWorker.postMessage({init: true, sessionIndex: sessionIndex});
175+
} else { //not default search plugin: reload whole page
176+
window.location.reload();
177+
}
173178
}
174179
}
175180
};

0 commit comments

Comments
 (0)