mirror of
https://github.com/lnbits/lnbits.git
synced 2026-08-17 13:16:11 +02:00
feat: session storage
This commit is contained in:
parent
c59221448b
commit
eac64dc6de
3 changed files with 41 additions and 1 deletions
2
lnbits/static/bundle-components.min.js
vendored
2
lnbits/static/bundle-components.min.js
vendored
File diff suppressed because one or more lines are too long
|
|
@ -513,6 +513,26 @@ window.WasmExtensionComponent = {
|
|||
this.newTabPrompt = this.emptyNewTabPrompt()
|
||||
reject?.(new Error(message))
|
||||
},
|
||||
bridgeSessionStorageKey(rawKey) {
|
||||
const key = String(rawKey || '').trim()
|
||||
if (!key || key.length > 128 || !/^[A-Za-z0-9._:-]+$/.test(key)) {
|
||||
throw new Error('Invalid extension session key.')
|
||||
}
|
||||
return `lnbits.ext.session.${this.bridge.extensionId}.${key}`
|
||||
},
|
||||
getBridgeSessionValue(message) {
|
||||
const key = this.bridgeSessionStorageKey(message.key)
|
||||
return {value: window.sessionStorage.getItem(key) || ''}
|
||||
},
|
||||
setBridgeSessionValue(message) {
|
||||
const key = this.bridgeSessionStorageKey(message.key)
|
||||
const value = String(message.value || '')
|
||||
if (value.length > 4096) {
|
||||
throw new Error('Extension session value is too large.')
|
||||
}
|
||||
window.sessionStorage.setItem(key, value)
|
||||
return {ok: true}
|
||||
},
|
||||
async callApi(message) {
|
||||
const method = String(message.method || 'GET').toUpperCase()
|
||||
const path = String(message.path || '')
|
||||
|
|
@ -1234,6 +1254,22 @@ window.WasmExtensionComponent = {
|
|||
return
|
||||
}
|
||||
|
||||
if (message.action === 'storage.session.get') {
|
||||
this.sendResponse(reply, message.id, {
|
||||
ok: true,
|
||||
data: this.getBridgeSessionValue(message)
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
if (message.action === 'storage.session.set') {
|
||||
this.sendResponse(reply, message.id, {
|
||||
ok: true,
|
||||
data: this.setBridgeSessionValue(message)
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
if (message.action === 'ui.scan_qr') {
|
||||
this.sendResponse(reply, message.id, {
|
||||
ok: true,
|
||||
|
|
|
|||
|
|
@ -49,6 +49,10 @@ def test_wasm_frontend_bridge_restricts_api_routes_and_realtime_actions():
|
|||
assert "window.open(prompt.url, '_blank', 'noopener,noreferrer')" in bridge
|
||||
assert "Only HTTP and HTTPS links can be opened." in bridge
|
||||
assert "This link is not on the same domain as this LNbits page." in bridge
|
||||
assert "message.action === 'storage.session.get'" in bridge
|
||||
assert "message.action === 'storage.session.set'" in bridge
|
||||
assert "bridgeSessionStorageKey(rawKey)" in bridge
|
||||
assert "lnbits.ext.session.${this.bridge.extensionId}.${key}" in bridge
|
||||
assert "hasBridgePermission('websocket.subscribe')" in bridge
|
||||
assert "/api/v1/ext/ws/${encodeURIComponent(" in bridge
|
||||
assert "/api/v1/ws/${encodeURIComponent(paymentHash)}" in bridge
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue