Change storage abstraction to use a new key

pull/1/head
Alex Beregszaszi 8 years ago
parent a451c5f380
commit 47667fa58e
  1. 21
      src/app/storage.js

@ -6,20 +6,24 @@ function Storage () {
} }
this.get = function (name) { this.get = function (name) {
return window.localStorage.getItem(name) return window.localStorage.getItem('sol:' + name)
} }
this.set = function (name, content) { this.set = function (name, content) {
window.localStorage.setItem(name, content) window.localStorage.setItem('sol:' + name, content)
} }
this.keys = function () { function safeKeys () {
// NOTE: this is a workaround for some browsers // NOTE: this is a workaround for some browsers
return Object.keys(window.localStorage).filter(function (item) { return item !== null && item !== undefined }) return Object.keys(window.localStorage).filter(function (item) { return item !== null && item !== undefined })
} }
this.keys = function () {
return safeKeys().filter(function (item) { return item.replace('sol:', '') })
}
this.remove = function (name) { this.remove = function (name) {
window.localStorage.removeItem(name) window.localStorage.removeItem('sol:' + name)
} }
this.rename = function (originalName, newName) { this.rename = function (originalName, newName) {
@ -36,6 +40,15 @@ function Storage () {
} }
this.set(filename, content) this.set(filename, content)
} }
// on startup, upgrade the old storage layout
safeKeys().forEach(function (name) {
if (name.indexOf('sol-cache-file-', 0) === 0) {
var content = window.localStorage.getItem(name)
window.localStorage.setItem('sol:' + name.replace('sol-cache-file-', ''), content)
window.localStorage.removeItem(name)
}
})
} }
module.exports = Storage module.exports = Storage

Loading…
Cancel
Save