diff --git a/webui/src/main/java/com/muwire/webui/CertificateServlet.java b/webui/src/main/java/com/muwire/webui/CertificateServlet.java index 6dc9c26e..ac97dd59 100644 --- a/webui/src/main/java/com/muwire/webui/CertificateServlet.java +++ b/webui/src/main/java/com/muwire/webui/CertificateServlet.java @@ -136,6 +136,7 @@ public class CertificateServlet extends HttpServlet { } File file = Util.getFromPathElements(path); certificateManager.certify(file); + Util.pause(); } } diff --git a/webui/src/main/java/com/muwire/webui/FeedManager.java b/webui/src/main/java/com/muwire/webui/FeedManager.java index f5ed1b54..ed90a7c2 100644 --- a/webui/src/main/java/com/muwire/webui/FeedManager.java +++ b/webui/src/main/java/com/muwire/webui/FeedManager.java @@ -6,6 +6,7 @@ import java.util.concurrent.ConcurrentHashMap; import com.muwire.core.Core; import com.muwire.core.Persona; +import com.muwire.core.SharedFile; import com.muwire.core.filefeeds.Feed; import com.muwire.core.filefeeds.FeedFetchEvent; import com.muwire.core.filefeeds.FeedItem; @@ -15,14 +16,18 @@ import com.muwire.core.filefeeds.UIDownloadFeedItemEvent; import com.muwire.core.filefeeds.UIFeedConfigurationEvent; import com.muwire.core.filefeeds.UIFeedDeletedEvent; import com.muwire.core.filefeeds.UIFeedUpdateEvent; +import com.muwire.core.filefeeds.UIFilePublishedEvent; +import com.muwire.core.filefeeds.UIFileUnpublishedEvent; public class FeedManager { private final Core core; + private final FileManager fileManager; private final Map remoteFeeds = new ConcurrentHashMap<>(); - public FeedManager(Core core) { + public FeedManager(Core core, FileManager fileManager) { this.core = core; + this.fileManager = fileManager; } public Map getRemoteFeeds() { @@ -105,6 +110,39 @@ public class FeedManager { core.getEventBus().publish(event); } + void publish(File file) { + if (file.isFile()) { + SharedFile sf = core.getFileManager().getFileToSharedFile().get(file); + if (sf == null) + return; + sf.publish(System.currentTimeMillis()); + UIFilePublishedEvent event = new UIFilePublishedEvent(); + event.setSf(sf); + core.getEventBus().publish(event); + } else { + long now = System.currentTimeMillis(); + for (SharedFile sf : fileManager.getAllFiles(file)) { + if (!sf.isPublished()) + sf.publish(now); + UIFilePublishedEvent event = new UIFilePublishedEvent(); + event.setSf(sf); + core.getEventBus().publish(event); + } + } + } + + void unpublish(File file) { + if (!file.isFile()) + throw new UnsupportedOperationException(); + SharedFile sf = core.getFileManager().getFileToSharedFile().get(file); + if (sf == null) + return; + sf.unpublish(); + UIFileUnpublishedEvent event = new UIFileUnpublishedEvent(); + event.setSf(sf); + core.getEventBus().publish(event); + } + static class RemoteFeed { private final Feed feed; private volatile long revision; diff --git a/webui/src/main/java/com/muwire/webui/FeedServlet.java b/webui/src/main/java/com/muwire/webui/FeedServlet.java index 31858190..da5d0b11 100644 --- a/webui/src/main/java/com/muwire/webui/FeedServlet.java +++ b/webui/src/main/java/com/muwire/webui/FeedServlet.java @@ -223,6 +223,24 @@ public class FeedServlet extends HttpServlet { feedManager.configure(host, autoDownload, sequential, updateInterval, itemsToKeep); Util.pause(); resp.sendRedirect("/MuWire/Feeds"); + } else if (action.equals("publish")) { + String path = req.getParameter("file"); + if (path == null) { + resp.sendError(403, "Bad param"); + return; + } + File file = Util.getFromPathElements(path); + feedManager.publish(file); + Util.pause(); + } else if (action.equals("unpublish")) { + String path = req.getParameter("file"); + if (path == null) { + resp.sendError(403, "Bad param"); + return; + } + File file = Util.getFromPathElements(path); + feedManager.unpublish(file); + Util.pause(); } } diff --git a/webui/src/main/java/com/muwire/webui/FilesServlet.java b/webui/src/main/java/com/muwire/webui/FilesServlet.java index 00b13c10..fbc7a423 100644 --- a/webui/src/main/java/com/muwire/webui/FilesServlet.java +++ b/webui/src/main/java/com/muwire/webui/FilesServlet.java @@ -95,7 +95,8 @@ public class FilesServlet extends HttpServlet { sf.getCachedPath(), sf.getCachedLength(), comment, - core.getCertificateManager().hasLocalCertificate(ih)); + core.getCertificateManager().hasLocalCertificate(ih), + sf.isPublished()); entries.add(entry); }); @@ -187,14 +188,16 @@ public class FilesServlet extends HttpServlet { private final long size; private final String comment; private final boolean certified; + private final boolean published; - FilesTableEntry(String name, InfoHash infoHash, String path, long size, String comment, boolean certified) { + FilesTableEntry(String name, InfoHash infoHash, String path, long size, String comment, boolean certified, boolean published) { this.name = name; this.infoHash = infoHash; this.path = path; this.size = size; this.comment = comment; this.certified = certified; + this.published = published; } void toXML(StringBuilder sb) { @@ -207,6 +210,7 @@ public class FilesServlet extends HttpServlet { sb.append("").append(Util.escapeHTMLinXML(comment)).append(""); } sb.append("").append(certified).append(""); + sb.append("").append(published).append(""); sb.append(""); } } @@ -268,6 +272,7 @@ public class FilesServlet extends HttpServlet { } InfoHash ih = new InfoHash(sf.getRoot()); sb.append("").append(core.getCertificateManager().hasLocalCertificate(ih)).append(""); + sb.append("").append(sf.isPublished()).append(""); // TODO: other stuff sb.append(""); } diff --git a/webui/src/main/java/com/muwire/webui/MuWireClient.java b/webui/src/main/java/com/muwire/webui/MuWireClient.java index 39d4342a..4fc32ac7 100644 --- a/webui/src/main/java/com/muwire/webui/MuWireClient.java +++ b/webui/src/main/java/com/muwire/webui/MuWireClient.java @@ -167,7 +167,7 @@ public class MuWireClient { core.getEventBus().register(UploadEvent.class, uploadManager); core.getEventBus().register(UploadFinishedEvent.class, uploadManager); - FeedManager feedManager = new FeedManager(core); + FeedManager feedManager = new FeedManager(core, fileManager); core.getEventBus().register(FeedLoadedEvent.class, feedManager); core.getEventBus().register(UIFeedConfigurationEvent.class, feedManager); core.getEventBus().register(FeedFetchEvent.class, feedManager); diff --git a/webui/src/main/java/com/muwire/webui/Util.java b/webui/src/main/java/com/muwire/webui/Util.java index ffccbe15..8959ac64 100644 --- a/webui/src/main/java/com/muwire/webui/Util.java +++ b/webui/src/main/java/com/muwire/webui/Util.java @@ -108,6 +108,7 @@ public class Util { _x("Trust"), _x("Trusted"), _x("Trusted User"), + _x("Unpublish"), _x("Unshare"), _x("Unsubscribe"), _x("Update"), diff --git a/webui/src/main/js/files.js b/webui/src/main/js/files.js index c5068702..aa36ee10 100644 --- a/webui/src/main/js/files.js +++ b/webui/src/main/js/files.js @@ -1,6 +1,6 @@ class Node { - constructor(nodeId, parent, leaf, infoHash, path, size, comment, certified, shared, revision) { + constructor(nodeId, parent, leaf, infoHash, path, size, comment, certified, published, shared, revision) { this.nodeId = nodeId this.parent = parent this.leaf = leaf @@ -10,6 +10,7 @@ class Node { this.size = size this.comment = comment this.certified = certified + this.published = published this.revision = revision this.shared = shared } @@ -25,14 +26,23 @@ class Node { var certifyLink = "" + _t("Certify") + "" if (!this.shared) certifyLink = "" + var publishLink = "" + _t("Publish") + "" + if (!this.shared) + publishLink = "" if (this.leaf) { var certified = "" if (this.certified == "true") certified = _t("Certified") + var publish + if (this.published == "true") { + publish = new Link(_t("Unpublish"), "unpublish", [this.nodeId]) + } else { + publish = new Link(_t("Publish"), "publish", [this.nodeId]) + } var nameLink = "" + this.path + "" var html = "
  • " + nameLink - html += "
    " + unshareLink + " " + commentLink + " " + certifyLink + " " + certified + "
    " + html += "
    " + unshareLink + " " + commentLink + " " + certifyLink + " " + certified + " " + publish.render() +"
    " html += "
    " html += "
  • " @@ -150,16 +160,17 @@ function expand(nodeId) { else comment = null var certified = element.getElementsByTagName("Certified")[0].childNodes[0].nodeValue + var published = element.getElementsByTagName("Published")[0].childNodes[0].nodeValue var nodeId = node.nodeId + "_"+ Base64.encode(fileName) - var newFileNode = new Node(nodeId, node, true, infoHash, fileName, size, comment, certified, true, revision) + var newFileNode = new Node(nodeId, node, true, infoHash, fileName, size, comment, certified, published, true, revision) nodesById.set(nodeId, newFileNode) node.children.push(newFileNode) } else if (element.nodeName == "Directory") { var dirName = element.getElementsByTagName("Name")[0].childNodes[0].nodeValue var shared = parseBoolean(element.getElementsByTagName("Shared")[0].childNodes[0].nodeValue) var nodeId = node.nodeId + "_"+ Base64.encode(dirName) - var newDirNode = new Node(nodeId, node, false, null, dirName, -1, null, false, shared, revision) + var newDirNode = new Node(nodeId, node, false, null, dirName, -1, null, false, false, shared, revision) nodesById.set(nodeId, newDirNode) node.children.push(newDirNode) } @@ -258,3 +269,33 @@ function certify(nodeId) { xmlhttp.setRequestHeader('Content-type', 'application/x-www-form-urlencoded'); xmlhttp.send("action=certify&file=" + encodedPath) } + +function publish(nodeId) { + var node = nodesById.get(nodeId) + var encodedPath = encodedPathToRoot(node) + var xmlhttp = new XMLHttpRequest() + xmlhttp.onreadystatechange = function() { + if (this.readyState == 4 && this.status == 200) { + collapse(node.parent.nodeId) + expand(node.parent.nodeId) + } + } + xmlhttp.open("POST", "/MuWire/Feed", true) + xmlhttp.setRequestHeader('Content-type', 'application/x-www-form-urlencoded'); + xmlhttp.send("action=publish&file=" + encodedPath) +} + +function unpublish(nodeId) { + var node = nodesById.get(nodeId) + var encodedPath = encodedPathToRoot(node) + var xmlhttp = new XMLHttpRequest() + xmlhttp.onreadystatechange = function() { + if (this.readyState == 4 && this.status == 200) { + collapse(node.parent.nodeId) + expand(node.parent.nodeId) + } + } + xmlhttp.open("POST", "/MuWire/Feed", true) + xmlhttp.setRequestHeader('Content-type', 'application/x-www-form-urlencoded'); + xmlhttp.send("action=unpublish&file=" + encodedPath) +} \ No newline at end of file diff --git a/webui/src/main/js/filesTable.js b/webui/src/main/js/filesTable.js index 34bd74fb..93bb2547 100644 --- a/webui/src/main/js/filesTable.js +++ b/webui/src/main/js/filesTable.js @@ -1,11 +1,12 @@ class SharedFile { - constructor(name, infoHash, path, size, comment, certified) { + constructor(name, infoHash, path, size, comment, certified, published) { this.name = name this.infoHash = infoHash this.path = path this.size = size this.comment = comment this.certified = certified + this.published = published } getMapping() { @@ -16,13 +17,19 @@ class SharedFile { var certifyHtml = certifyLink.render() if (this.certified == "true") certifyHtml += " " + _t("Certified") + var publishLink + if (this.published == "true") + publishLink = new Link(_t("Unpublish"), "unpublish", [this.path]) + else + publishLink = new Link(_t("Publish"), "publish", [this.path]) + var showCommentHtml = "" var showCommentLink = new Link(_t("Comment"), "showCommentForm", [this.path]) showCommentHtml = "" + showCommentLink.render() + "" var commentDiv = "
    " var nameLink = "" + this.name + "" - var html = nameLink + "
    " + unshareLink.render() + " " + showCommentHtml + " " + certifyHtml + "
    " + var html = nameLink + "
    " + unshareLink.render() + " " + showCommentHtml + " " + certifyHtml + " " + publishLink.render()+ "
    " html += "
    " + commentDiv mapping.set("File", html) @@ -90,9 +97,10 @@ function refreshTable() { else comment = null var certified = files[i].getElementsByTagName("Certified")[0].childNodes[0].nodeValue + var published = files[i].getElementsByTagName("Published")[0].childNodes[0].nodeValue var path = Base64.encode(fileName) - var newSharedFile = new SharedFile(fileName, infoHash, path, size, comment, certified) + var newSharedFile = new SharedFile(fileName, infoHash, path, size, comment, certified, published) filesByPath.set(path, newSharedFile) filesList.push(newSharedFile) } @@ -194,3 +202,27 @@ function certify(path) { xmlhttp.setRequestHeader('Content-type', 'application/x-www-form-urlencoded'); xmlhttp.send("action=certify&file=" + path) } + +function publish(path) { + var xmlhttp = new XMLHttpRequest() + xmlhttp.onreadystatechange = function() { + if (this.readyState == 4 && this.status == 200) { + refreshTable() + } + } + xmlhttp.open("POST", "/MuWire/Feed", true) + xmlhttp.setRequestHeader('Content-type', 'application/x-www-form-urlencoded'); + xmlhttp.send("action=publish&file=" + path) +} + +function unpublish(path) { + var xmlhttp = new XMLHttpRequest() + xmlhttp.onreadystatechange = function() { + if (this.readyState == 4 && this.status == 200) { + refreshTable() + } + } + xmlhttp.open("POST", "/MuWire/Feed", true) + xmlhttp.setRequestHeader('Content-type', 'application/x-www-form-urlencoded'); + xmlhttp.send("action=unpublish&file=" + path) +}