expand tabs
parent
1f024dd139
commit
c724f0ee0b
|
|
@ -1437,6 +1437,79 @@
|
|||
this.database.forEach((key) => {
|
||||
var k = this.deprefix(key);
|
||||
if (k)
|
||||
{
|
||||
console.log("parsed key", k);
|
||||
foo(k);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
class HTTPCRUD extends Database {
|
||||
encode(key)
|
||||
{
|
||||
return btoa(key);
|
||||
}
|
||||
|
||||
decode(key)
|
||||
{
|
||||
return atob(key);
|
||||
}
|
||||
|
||||
toPath(key)
|
||||
{
|
||||
return "api?key="+key;
|
||||
}
|
||||
|
||||
do(method, key, data)
|
||||
{
|
||||
var result = null;
|
||||
console.log("DO:", this.toPath(key), method, data);
|
||||
$.ajax({
|
||||
url: this.toPath(key),
|
||||
type: method,
|
||||
data: data,
|
||||
async: false,
|
||||
cache: false,
|
||||
processData: false,
|
||||
contentType: "application/json",
|
||||
success: (data, statusText, jqXHR) => {
|
||||
console.log(method, key, ": parsing: ", data);
|
||||
if (data)
|
||||
result = JSON.parse("" + data);
|
||||
console.log("parsed: ", result)
|
||||
},
|
||||
error: (jqXHR, statusText, err) => {
|
||||
if (jqXHR.status > 410)
|
||||
throw new Error("unexpected status: " + statusText + ": " + err);
|
||||
},
|
||||
});
|
||||
//console.log("DID:", this.toPath(key), method, data, result);
|
||||
return result;
|
||||
}
|
||||
|
||||
get(key)
|
||||
{
|
||||
return this.do("GET", this.encode(key), null);
|
||||
}
|
||||
|
||||
set(key, value)
|
||||
{
|
||||
return this.do("POST", this.encode(key), value);
|
||||
}
|
||||
|
||||
del(key)
|
||||
{
|
||||
return this.do("DELETE", this.encode(key), null);
|
||||
}
|
||||
|
||||
forEach(foo)
|
||||
{
|
||||
var result = this.do("GET", "", null);
|
||||
if (! result)
|
||||
result = [];
|
||||
result.forEach((k) => {
|
||||
k = this.decode(k);
|
||||
foo(k);
|
||||
});
|
||||
}
|
||||
|
|
@ -1505,22 +1578,23 @@
|
|||
|
||||
globalStorage = new MultiDatabase(
|
||||
new NamespacedDatabase("A", new Local()),
|
||||
new NamespacedDatabase("B", new Local()),
|
||||
//new NamespacedDatabase("8", new HTTPCRUD()),
|
||||
//new NamespacedDatabase("B", new Local()),
|
||||
//new Bomber(),
|
||||
);
|
||||
|
||||
/*
|
||||
* poor man's error handling -- $fixme
|
||||
* poor mans error handling -- $fixme
|
||||
*/
|
||||
window.onerror = function(message, file, line, col, e){
|
||||
var cb1;
|
||||
alert("Error occurred: " + e.message);
|
||||
console.log("Error occurred: " + e.message);
|
||||
return false;
|
||||
};
|
||||
|
||||
window.addEventListener("error", function(e) {
|
||||
var cb2;
|
||||
alert("Error occurred: " + e.error.message);
|
||||
console.log("Error occurred: " + e.error.message);
|
||||
return false;
|
||||
})
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue