diff --git a/main.go b/main.go index d788939..4724d7a 100644 --- a/main.go +++ b/main.go @@ -25,7 +25,7 @@ import ( "time" ) -const VERSION = "v31" +const VERSION = "v32" const CONTEXT_USER = 1 const SYNC_PAGINATION = 200 diff --git a/static/js/app.mjs b/static/js/app.mjs index e44eabd..2fc713b 100644 --- a/static/js/app.mjs +++ b/static/js/app.mjs @@ -221,7 +221,7 @@ export class App { const devPrefSet = localStorage.getItem('device_preference_set') || 'default' const userData = localStorage.getItem('user') || '{"default": {}}' const user = JSON.parse(userData) - return new N2PreferenceSet(devPrefSet, user.Preferences[devPrefSet]) + return new N2PreferenceSet(devPrefSet, user.Preferences[devPrefSet] || {}) }// }}} } diff --git a/static/js/node_store.mjs b/static/js/node_store.mjs index 531626b..a086d85 100644 --- a/static/js/node_store.mjs +++ b/static/js/node_store.mjs @@ -328,6 +328,52 @@ export class NodeStore { this.nodes[ORPHANED_NODE] = new Node({ UUID: ORPHANED_NODE, Name: 'Orphaned nodes', Special: true }, -1) }// }}} + deleteAll() {// {{{ + this.db.close() + + const req = indexedDB.deleteDatabase('notes') + + req.onsuccess = async () => { + try { + console.log('Database deleted successfully') + + // Deleting the storage will log out the user. + await this.deleteStorage() + await this.deleteCaches() + await this.deleteServiceWorkers() + + alert('Database deleted, will now log out.') + location.href = '/login' + } catch (e) { + console.error(e) + alert(e.message) + } + } + + req.onerror = (event) => { + console.error('Error deleting database:', event.target.errorCode) + } + + req.onblocked = () => { + console.warn('Deletion blocked. Close all other tabs/connections to this DB.') + } + }// }}} + async deleteStorage() {// {{{ + // Clearing local- and session-storage in case + // something of value to evil people gets stored there. + localStorage.clear() + sessionStorage.clear() + console.log('Local- and session-storage cleared.') + }// }}} + async deleteCaches() {// {{{ + const keys = await caches.keys() + return Promise.all(keys.map(key => caches.delete(key))) + }// }}} + async deleteServiceWorkers() {// {{{ + const registrations = await navigator.serviceWorker.getRegistrations() + await Promise.all(registrations.map(r => r.unregister())) + }// }}} + node(uuid, dataIfUndefined, newLevel) {//{{{ let n = this.nodes[uuid] if (n === undefined && dataIfUndefined !== undefined) diff --git a/static/js/page_preferences.mjs b/static/js/page_preferences.mjs index dd85ebf..2c44d55 100644 --- a/static/js/page_preferences.mjs +++ b/static/js/page_preferences.mjs @@ -238,6 +238,7 @@ export class N2PreferenceSet extends CustomHTMLElement { super(true) this.name = name this.data = data + this.validateDefaultProfile() this.render() // Enable the save button when settings are modified. @@ -248,6 +249,16 @@ export class N2PreferenceSet extends CustomHTMLElement { this.elName.addEventListener('click', () => this.updateName()) this.elDelete.addEventListener('click', () => this.deleteSet()) }// }}} + validateDefaultProfile() {// {{{ + if (!this.data.hasOwnProperty('default')) + this.data.default = {} + + if (!this.data.default.hasOwnProperty('DownloadFiles')) + this.data.default.DownloadFiles = false + + if (!this.data.default.hasOwnProperty('DownloadImages')) + this.data.default.DownloadImages = false + }// }}} updateName() {// {{{ if (this.name == 'default') { alert('Can not change name of the default profile.') diff --git a/static/js/page_storage.mjs b/static/js/page_storage.mjs index f6f562f..ed3970b 100644 --- a/static/js/page_storage.mjs +++ b/static/js/page_storage.mjs @@ -2,7 +2,7 @@ import { CustomHTMLElement } from "./lib/custom_html_element.mjs" import { API } from 'api' export class N2PageStorage extends CustomHTMLElement { - static { + static {// {{{ this.tmpl = document.createElement('template') this.tmpl.innerHTML = `