Commit 0b8d2257 authored by Romain Courteaud's avatar Romain Courteaud

Display the list of keys in localstorage

parent 1c69f917
......@@ -6,13 +6,24 @@
$.ajax({
method: 'GET',
// XXX Hardcoded
url: "browser://browser/ls/",
url: "browser://browse/ls/",
context: $('body'),
error: function (jqXHR, textStatus, errorThrown) {
$(this).text(errorThrown);
},
success: function (value, textStatus, jqXHR) {
$(this).text(value);
var content_type = jqXHR.getResponseHeader("Content-Type") || "";
// XXX Hardcoded mime type
if (content_type.split(';')[0] === "application/hal+json") {
// XXX Will fail if response does not send expected links...
$(this).html("<ul>");
for (var i in value._links.contents){
$(this).append("<li>" + value._links.contents[i].href + "</li>");
}
$(this).append("</ul>");
} else {
$(this).text("Unsupported content type " + content_type);
};
},
});
});
......
......@@ -1053,7 +1053,8 @@
dispatch = function () {
// XXX Local hack
var ls_regexp = /browser:\/\/localstorage\/([\w\W]+)/,
browse_regexp = /browser:\/\/browse\/ls\/([\w\W]+)/,
browse_file_regexp = /browser:\/\/browse\/ls\/([\w\W]+)/,
browse_directory_regexp = /browser:\/\/browse\/ls\//,
key;
if (ls_regexp.test(this.url)) {
key = ls_regexp.exec(this.url)[1];
......@@ -1070,16 +1071,31 @@
} else {
this.respond(405, {}, "");
}
} else if (browse_regexp.test(this.url)) {
key = browse_regexp.exec(this.url)[1];
} else if (browse_file_regexp.test(this.url)) {
key = browse_file_regexp.exec(this.url)[1];
this.respond(200, {
'Content-Type': 'application/hal+json'
}, JSON.stringify({
_links: {
self: {href: 'browser://browse/ls/' + key},
self: {href: this.url},
enclosure: {href: 'browser://localstorage/' + key},
}
}));
} else if (browse_directory_regexp.test(this.url)) {
var response = {
_links: {
self: {href: this.url},
contents: [],
}
};
for (var key in localStorage){
response._links.contents.push({href: 'browser://browse/ls/' + key});
}
this.respond(200, {
'Content-Type': 'application/hal+json'
}, JSON.stringify(response));
} else {
this.respond(404, {}, "");
}
......
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