Compare commits
No commits in common. "4c59ef4cda0fe047db72e8889549ed7d9bdca852" and "da8256f002dd54b37c7552628e7310d9a282c741" have entirely different histories.
4c59ef4cda
...
da8256f002
6 changed files with 15 additions and 90 deletions
2
main.go
2
main.go
|
|
@ -25,7 +25,7 @@ import (
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
const VERSION = "v32"
|
const VERSION = "v31"
|
||||||
const CONTEXT_USER = 1
|
const CONTEXT_USER = 1
|
||||||
const SYNC_PAGINATION = 200
|
const SYNC_PAGINATION = 200
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -221,7 +221,7 @@ export class App {
|
||||||
const devPrefSet = localStorage.getItem('device_preference_set') || 'default'
|
const devPrefSet = localStorage.getItem('device_preference_set') || 'default'
|
||||||
const userData = localStorage.getItem('user') || '{"default": {}}'
|
const userData = localStorage.getItem('user') || '{"default": {}}'
|
||||||
const user = JSON.parse(userData)
|
const user = JSON.parse(userData)
|
||||||
return new N2PreferenceSet(devPrefSet, user.Preferences[devPrefSet] || {})
|
return new N2PreferenceSet(devPrefSet, user.Preferences[devPrefSet])
|
||||||
}// }}}
|
}// }}}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -328,52 +328,6 @@ export class NodeStore {
|
||||||
this.nodes[ORPHANED_NODE] = new Node({ UUID: ORPHANED_NODE, Name: 'Orphaned nodes', Special: true }, -1)
|
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) {//{{{
|
node(uuid, dataIfUndefined, newLevel) {//{{{
|
||||||
let n = this.nodes[uuid]
|
let n = this.nodes[uuid]
|
||||||
if (n === undefined && dataIfUndefined !== undefined)
|
if (n === undefined && dataIfUndefined !== undefined)
|
||||||
|
|
|
||||||
|
|
@ -238,7 +238,6 @@ export class N2PreferenceSet extends CustomHTMLElement {
|
||||||
super(true)
|
super(true)
|
||||||
this.name = name
|
this.name = name
|
||||||
this.data = data
|
this.data = data
|
||||||
this.validateDefaultProfile()
|
|
||||||
this.render()
|
this.render()
|
||||||
|
|
||||||
// Enable the save button when settings are modified.
|
// Enable the save button when settings are modified.
|
||||||
|
|
@ -249,16 +248,6 @@ export class N2PreferenceSet extends CustomHTMLElement {
|
||||||
this.elName.addEventListener('click', () => this.updateName())
|
this.elName.addEventListener('click', () => this.updateName())
|
||||||
this.elDelete.addEventListener('click', () => this.deleteSet())
|
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() {// {{{
|
updateName() {// {{{
|
||||||
if (this.name == 'default') {
|
if (this.name == 'default') {
|
||||||
alert('Can not change name of the default profile.')
|
alert('Can not change name of the default profile.')
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@ import { CustomHTMLElement } from "./lib/custom_html_element.mjs"
|
||||||
import { API } from 'api'
|
import { API } from 'api'
|
||||||
|
|
||||||
export class N2PageStorage extends CustomHTMLElement {
|
export class N2PageStorage extends CustomHTMLElement {
|
||||||
static {// {{{
|
static {
|
||||||
this.tmpl = document.createElement('template')
|
this.tmpl = document.createElement('template')
|
||||||
this.tmpl.innerHTML = `
|
this.tmpl.innerHTML = `
|
||||||
<style>
|
<style>
|
||||||
|
|
@ -25,24 +25,20 @@ export class N2PageStorage extends CustomHTMLElement {
|
||||||
margin-top: 24px;
|
margin-top: 24px;
|
||||||
margin-bottom: 8px;
|
margin-bottom: 8px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.el-btn-clear-all {
|
|
||||||
margin-top: 16px;
|
|
||||||
}
|
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
<h1>Local storage</h1>
|
<h1>Local storage</h1>
|
||||||
|
|
||||||
<h2>Notes</h2>
|
<h2>Nodes</h2>
|
||||||
<div class="table">
|
<div class="table">
|
||||||
<div>Local notes</div>
|
<div>Local nodes</div>
|
||||||
<div data-el="count-nodes"></div>
|
<div data-el="count-nodes"></div>
|
||||||
|
|
||||||
<div>History notes</div>
|
<div>Queued to sync</div>
|
||||||
<div data-el="count-history-nodes"></div>
|
|
||||||
|
|
||||||
<div>Notes to send</div>
|
|
||||||
<div data-el="count-queued-nodes"></div>
|
<div data-el="count-queued-nodes"></div>
|
||||||
|
|
||||||
|
<div>History nodes</div>
|
||||||
|
<div data-el="count-history-nodes"></div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<h2>Files</h2>
|
<h2>Files</h2>
|
||||||
|
|
@ -56,24 +52,17 @@ export class N2PageStorage extends CustomHTMLElement {
|
||||||
<div>Files to send</div>
|
<div>Files to send</div>
|
||||||
<div data-el="count-queued-files"></div>
|
<div data-el="count-queued-files"></div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<h2>Clear storage</h2>
|
|
||||||
<div>Remove all data from this device (not server) and logout the session.</div>
|
|
||||||
<div>This ensures that no notes or files is left on the browser.</div>
|
|
||||||
<button data-el="btn-clear-all">Clear and logout</button>
|
|
||||||
`
|
`
|
||||||
}// }}}
|
}
|
||||||
constructor() {// {{{
|
constructor() {
|
||||||
super(true)
|
super(true)
|
||||||
|
|
||||||
.elBtnClearAll.addEventListener('click', ()=>this.clearAll())
|
|
||||||
|
|
||||||
window._mbus.subscribe('SHOW_PAGE', event => {
|
window._mbus.subscribe('SHOW_PAGE', event => {
|
||||||
if (event.detail.data?.page == 'storage')
|
if (event.detail.data?.page == 'storage')
|
||||||
this.render()
|
this.render()
|
||||||
})
|
})
|
||||||
}// }}}
|
}
|
||||||
async render() {// {{{
|
async render() {
|
||||||
API.query('GET', '/file/count')
|
API.query('GET', '/file/count')
|
||||||
.then(res => {
|
.then(res => {
|
||||||
this.elCountFilesOnServer.innerText = res.Count
|
this.elCountFilesOnServer.innerText = res.Count
|
||||||
|
|
@ -91,12 +80,6 @@ export class N2PageStorage extends CustomHTMLElement {
|
||||||
this.elCountQueuedFiles.innerText = await globalThis.nodeStore.filesMetadata.countToUpload()
|
this.elCountQueuedFiles.innerText = await globalThis.nodeStore.filesMetadata.countToUpload()
|
||||||
|
|
||||||
this.elCountFilesOnDevice.innerText = await globalThis.nodeStore.filesMetadata.count()
|
this.elCountFilesOnDevice.innerText = await globalThis.nodeStore.filesMetadata.count()
|
||||||
}// }}}
|
}
|
||||||
clearAll() {// {{{
|
|
||||||
if (!confirm('Do you want to remove ALL data from this device and logout?'))
|
|
||||||
return
|
|
||||||
|
|
||||||
globalThis.nodeStore.deleteAll()
|
|
||||||
}// }}}
|
|
||||||
}
|
}
|
||||||
customElements.define('n2-pagestorage', N2PageStorage)
|
customElements.define('n2-pagestorage', N2PageStorage)
|
||||||
|
|
|
||||||
|
|
@ -20,8 +20,7 @@
|
||||||
<script>
|
<script>
|
||||||
globalThis._VERSION = "{{ .VERSION }}"
|
globalThis._VERSION = "{{ .VERSION }}"
|
||||||
|
|
||||||
const token = localStorage.getItem('token')
|
if (navigator.serviceWorker)
|
||||||
if (token && navigator.serviceWorker)
|
|
||||||
navigator.serviceWorker.register('/service_worker.js', { type: 'module' })
|
navigator.serviceWorker.register('/service_worker.js', { type: 'module' })
|
||||||
</script>
|
</script>
|
||||||
<script type="module" defer>
|
<script type="module" defer>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue