Commit 47667fa5 authored by Alex Beregszaszi's avatar Alex Beregszaszi

Change storage abstraction to use a new key

parent a451c5f3
......@@ -6,20 +6,24 @@ function Storage () {
}
this.get = function (name) {
return window.localStorage.getItem(name)
return window.localStorage.getItem('sol:' + name)
}
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
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) {
window.localStorage.removeItem(name)
window.localStorage.removeItem('sol:' + name)
}
this.rename = function (originalName, newName) {
......@@ -36,6 +40,15 @@ function Storage () {
}
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
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment