import { CustomHTMLElement } from "./lib/custom_html_element.mjs"
import { API } from 'api'
export class N2PageStorage extends CustomHTMLElement {
static {
this.tmpl = document.createElement('template')
this.tmpl.innerHTML = `
Local storage
Nodes
Local nodes
Queued to sync
History nodes
Files
Files on server
Files on device
Files to send
`
}
constructor() {
super(true)
window._mbus.subscribe('SHOW_PAGE', event => {
if (event.detail.data?.page == 'storage')
this.render()
})
}
async render() {
API.query('GET', '/file/count')
.then(res => {
this.elCountFilesOnServer.innerText = res.Count
})
.catch(err => {
this.elCountFilesOnServer.classList.add('error')
console.error(err)
this.elCountFilesOnServer.innerText = err.message
})
this.elCountNodes.innerText = await globalThis.nodeStore.nodeCount()
this.elCountQueuedNodes.innerText = await globalThis.nodeStore.sendQueue.count()
this.elCountHistoryNodes.innerText = await globalThis.nodeStore.nodesHistory.count()
this.elCountQueuedFiles.innerText = await globalThis.nodeStore.filesMetadata.countToUpload()
this.elCountFilesOnDevice.innerText = await globalThis.nodeStore.filesMetadata.count()
}
}
customElements.define('n2-pagestorage', N2PageStorage)