wip on showing certificates

pull/34/head
Zlatin Balevsky 2019-12-10 08:12:45 +00:00
parent 10fab2b47f
commit 117c5eaf67
3 changed files with 56 additions and 2 deletions

View File

@ -113,6 +113,7 @@ public class SearchServlet extends HttpServlet {
.append(Util.escapeHTMLinXML(result.getComment()))
.append("</Comment>");
}
sb.append("<Certificates>").append(result.getCertificates()).append("</Certificates>");
sb.append("</Result>");
});
sb.append("</ResultsFromSender>");
@ -157,6 +158,7 @@ public class SearchServlet extends HttpServlet {
.append(Util.escapeHTMLinXML(result.getComment()))
.append("</Comment>");
}
sb.append("<Certificates>").append(result.getCertificates()).append("</Certificates>");
sb.append("</Result>");
});
sb.append("</ResultsForFile>");

View File

@ -22,7 +22,10 @@ public class Util {
// if we had a lot of these we could scan for them in the build and generate
// a file, but it's not worth it for just a handful.
private static final String[] jsStrings = {
_x("View Certificates"),
_x("Fetching Certificates"),
_x("Hide Certificates"),
_x("Results For {0}"),
_x("View {0} Certificates"),
_x("Certify"),
_x("Certified"),
_x("Import"),

View File

@ -106,6 +106,7 @@ class ResultBySender {
var comment = xmlNode.getElementsByTagName("Comment")
if (comment.length == 1)
this.comment = comment[0].childNodes[0].nodeValue;
this.certificates = xmlNode.getElementsByTagName("Certificates")[0].childNodes[0].nodeValue
}
}
@ -120,6 +121,17 @@ class ResultByFile {
var comment = xmlNode.getElementsByTagName("Comment")
if (comment.length == 1)
this.comment = comment[0].childNodes[0].nodeValue;
this.certificates = xmlNode.getElementsByTagName("Certificates")[0].childNodes[0].nodeValue
}
getCertificatesBlock() {
if (this.certificates == "0")
return ""
var linkText = _t("View {0} Certificates", this.certificates)
var link = "<a href='#' onclick='window.viewCertificatesByFile(\"" + this.senderB64 + "\",\"" + this.certificates + "\");return false;'>" + linkText + "</a>"
var id = this.senderB64 + "_" + infoHash
var html = " <div id='certificates-link-" + id +"'>" + link + "</div><div id='certificates-" + id +"'></div> "
return html
}
getTrustLinks() {
@ -150,10 +162,21 @@ class ResultByFile {
}
}
class CertificateFetch {
constructor(senderB64, fileInfoHash) {
this.senderB64 = senderB64
this.fileInfoHash = fileInfoHash
this.divId = senderB64 + "_" + fileInfoHash
}
}
var statusByUUID = new Map()
var currentSearchBySender = null
var currentSearchByFile = null
var currentSender = null
var currentFile = null
var expandedComments = new Map();
var certificateFetches = new Map()
var uuid = null;
var sender = null;
@ -360,6 +383,7 @@ function updateFile(fileInfoHash) {
table += "<div id='"+divId+"'></div>";
}
}
table += result.getCertificatesBlock()
table += "</td>";
if (result.browse == "true") {
if (result.browsing == "true")
@ -413,7 +437,7 @@ function updateUUIDByFile(resultUUID) {
var currentStatus = statusByUUID.get(uuid)
var currentSearchSpan = document.getElementById("currentSearch");
currentSearchSpan.innerHTML = currentStatus.query + " Results";
currentSearchSpan.innerHTML = _t("Results for {0}", currentStatus.query)
var topTableDiv = document.getElementById("topTable");
var table = "<table><thead><tr><th>" + _t("Name") + "</th><th>" + _t("Size") + "</th><th>" + _t("Download") + "</th></tr></thead><tbody>";
@ -483,6 +507,31 @@ function browse(host) {
xmlhttp.send("action=browse&host="+host)
}
function viewCertificatesByFile(senderB64, count) {
var fetch = new CertificateFetch(senderB64, infoHash)
certificateFetches.set(fetch.divId, fetch)
var linkSpan = document.getElementById("certificates-link-" + fetch.divId)
var hideLink = "<a href='#' onclick='window.hideCertificatesByFile(\"" + senderB64 + "\",\"" + count + "\");return false;'>" + _t("Hide Certificates") + "</a>"
linkSpan.innerHTML = hideLink
var fetchSpan = document.getElementById("certificates-" + fetch.divId)
fetchSpan.innerHTML = _t("Fetching Certificates")
}
function hideCertificatesByFile(senderB64, count) {
var id = senderB64 + "_" + infoHash
certificateFetches.delete(id) // TODO: propagate cancel to core
var fetchSpan = document.getElementById("certificates-" + id)
fetchSpan.innerHTML = ""
var linkSpan = document.getElementById("certificates-link-" + id)
var linkText = _t("View {0} Certificates", count)
var showLink = "<a href='#' onclick='window.viewCertificatesByFile(\"" + senderB64 + "\",\"" + count + "\");return false;'>" + linkText + "</a>"
linkSpan.innerHTML = showLink
}
function refreshStatus() {
var xmlhttp = new XMLHttpRequest()
xmlhttp.onreadystatechange = function() {