-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathbackuptools.js
41 lines (40 loc) · 1.43 KB
/
backuptools.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
// Functions for manual storage backup and restoration
function dumpStorage({asFile=true}={}) {
let dump = JSON.stringify(store.getState().storage, null, 2)
if (asFile) {
const dataUrl = "data:text/json;charset=utf-8," + window.escape(dump)
var link = document.createElement("a")
link.download = 'webmemex-backup.json'
link.href = dataUrl
document.body.appendChild(link)
link.click()
document.body.removeChild(link)
}
else {
return dump
}
}
function importFromDump({storageDump, deleteCurrent=false}={}) {
if (storageDump === undefined)
storageDump = prompt('Paste your JSON storage dump here (obtained from dumpStorage())')
if (typeof storageDump === 'string') {
if (storageDump === '') {
storageDump = '{"docs": {}, "links": {}}'
}
storageDump = JSON.parse(storageDump)
}
let docCount = Object.keys(storageDump.docs).length
let message = deleteCurrent
? 'Delete all, then import ' + docCount + ' docs?'
: 'Load ' + docCount + ' docs?'
if (confirm(message)) {
store.dispatch(storage.importFromDump({storageDump, deleteCurrent}))
}
}
function deleteAllDocs() {
const cleanState = {docs: {}, links: {}}
importFromDump({storageDump: cleanState, deleteCurrent: true})
}
window.dumpStorage = dumpStorage
window.importFromDump = importFromDump
window.deleteAllDocs = deleteAllDocs