implement closing browses

pull/34/head
Zlatin Balevsky 2019-12-15 19:02:51 +00:00
parent c4ea58c330
commit 7ec6257ac0
2 changed files with 34 additions and 2 deletions

View File

@ -188,8 +188,21 @@ public class BrowseServlet extends HttpServlet {
try {
Thread.sleep(100);
} catch (InterruptedException ignore) {}
} else if (action.equals("close")) {
String personaB64 = req.getParameter("host");
if (personaB64 == null) {
resp.sendError(403,"Bad param");
return;
}
Persona host;
try {
host = new Persona(new ByteArrayInputStream(Base64.decode(personaB64)));
} catch (Exception bad) {
resp.sendError(403,"Bad param");
return;
}
browseManager.getBrowses().remove(host);
}
// TODO: implement canceling of browse
}
@Override

View File

@ -42,6 +42,11 @@ class Browse {
return "<a href='#' onclick='window.showResults(\"" + this.host + "\",\"" + this.key + "\",\"" + this.descending +
"\");return false;'>" + this.host + "</a>"
}
getCloseLink() {
var link = new Link("[X]", "close", [this.hostB64])
return link.render()
}
}
function initBrowse() {
@ -55,6 +60,18 @@ var resultsByInfoHash = new Map()
var browseKey = null
var browseOrder = null
function close(b64) {
var xmlhttp = new XMLHttpRequest()
xmlhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
refreshActive()
}
}
xmlhttp.open("POST", "/MuWire/Browse", true)
xmlhttp.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
xmlhttp.send("action=close&host=" + b64)
}
function showCertificates(hostB64, infoHash) {
var fetch = new CertificateFetch(hostB64, infoHash)
certificateFetches.set(fetch.divId, fetch)
@ -128,9 +145,11 @@ function refreshActive() {
for (i = 0;i < activeBrowses.length; i++) {
var browse = activeBrowses[i]
var browseLink = browse.getBrowseLink()
var closeLink = browse.getCloseLink()
var nameHtml = "<table><tr><td>" + browseLink + "</td><td><p align='right'>" + closeLink + "</p></td></tr></table>"
var mapping = new Map()
mapping.set("Host", browseLink)
mapping.set("Host", nameHtml)
mapping.set("Status", browse.status)
var percent = browse.receivedResults + "/" + browse.totalResults