mirror of https://github.com/zlatinb/muwire
browse and subscribe actions from upload table for plugin
parent
5a94d14b8e
commit
2c7cf24942
|
@ -349,9 +349,15 @@ div#uploads table thead th:nth-child(3) {
|
|||
width: 120px;
|
||||
}
|
||||
div#uploads table thead th:nth-child(4) {
|
||||
width: 120px;
|
||||
width: 70px;
|
||||
}
|
||||
div#uploads table thead th:nth-child(5) {
|
||||
width: 70px;
|
||||
}
|
||||
div#uploads table thead th:nth-child(6) {
|
||||
width: 120px;
|
||||
}
|
||||
div#uploads table thead th:nth-child(7) {
|
||||
width: 120px;
|
||||
}
|
||||
div#uploads table tbody td:nth-child(1) {
|
||||
|
@ -363,11 +369,11 @@ div#uploads table tbody td:nth-child(2) {
|
|||
div#uploads table tbody td:nth-child(3) {
|
||||
text-overflow: ellipsis;
|
||||
}
|
||||
div#uploads table tbody td:nth-child(4) {
|
||||
div#uploads table tbody td:nth-child(6) {
|
||||
padding-right: 40px;
|
||||
text-align: right;
|
||||
}
|
||||
div#uploads table tbody td:nth-child(5) {
|
||||
div#uploads table tbody td:nth-child(7) {
|
||||
padding-right: 25px;
|
||||
text-align: right;
|
||||
}
|
||||
|
|
|
@ -12,24 +12,35 @@ import javax.servlet.http.HttpServlet;
|
|||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import com.muwire.core.Core;
|
||||
import com.muwire.core.Persona;
|
||||
|
||||
import net.i2p.data.DataHelper;
|
||||
|
||||
public class UploadServlet extends HttpServlet {
|
||||
|
||||
private UploadManager uploadManager;
|
||||
private BrowseManager browseManager;
|
||||
private Core core;
|
||||
|
||||
@Override
|
||||
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
|
||||
List<UploadEntry> entries = new ArrayList<>();
|
||||
synchronized(uploadManager.getUploads()) {
|
||||
for(UploadManager.UploaderWrapper wrapper : uploadManager.getUploads()) {
|
||||
Persona downloader = wrapper.getUploader().getDownloaderPersona();
|
||||
UploadEntry entry = new UploadEntry(
|
||||
wrapper.getUploader().getName(),
|
||||
wrapper.getUploader().getProgress(),
|
||||
wrapper.getUploader().getDownloader(),
|
||||
wrapper.getUploader().getDownloaderPersona().toBase64(),
|
||||
wrapper.getUploader().getDonePieces(),
|
||||
wrapper.getUploader().getTotalPieces(),
|
||||
wrapper.getUploader().speed()
|
||||
wrapper.getUploader().speed(),
|
||||
wrapper.getUploader().isBrowseEnabled(),
|
||||
wrapper.getUploader().isFeedEnabled(),
|
||||
browseManager.isBrowsing(downloader),
|
||||
core.getFeedManager().getFeed(downloader) != null
|
||||
);
|
||||
entries.add(entry);
|
||||
}
|
||||
|
@ -55,6 +66,8 @@ public class UploadServlet extends HttpServlet {
|
|||
@Override
|
||||
public void init(ServletConfig config) throws ServletException {
|
||||
uploadManager = (UploadManager) config.getServletContext().getAttribute("uploadManager");
|
||||
browseManager = (BrowseManager) config.getServletContext().getAttribute("browseManager");
|
||||
core = (Core) config.getServletContext().getAttribute("core");
|
||||
}
|
||||
|
||||
|
||||
|
@ -72,18 +85,26 @@ public class UploadServlet extends HttpServlet {
|
|||
private static class UploadEntry {
|
||||
private final String name;
|
||||
private final int progress;
|
||||
private final String downloader;
|
||||
private final String downloader, b64;
|
||||
private final int remotePieces;
|
||||
private final int totalPieces;
|
||||
private final int speed;
|
||||
private final boolean browse, feed;
|
||||
private final boolean browsing, subscribed;
|
||||
|
||||
UploadEntry(String name, int progress, String downloader, int remotePieces, int totalPieces, int speed) {
|
||||
UploadEntry(String name, int progress, String downloader, String b64, int remotePieces, int totalPieces, int speed,
|
||||
boolean browse, boolean feed, boolean browsing, boolean subscribed) {
|
||||
this.name = name;
|
||||
this.progress = progress;
|
||||
this.downloader = downloader;
|
||||
this.b64 = b64;
|
||||
this.remotePieces = progress == 100 ? remotePieces + 1 : remotePieces;
|
||||
this.totalPieces = totalPieces;
|
||||
this.speed = speed;
|
||||
this.browse = browse;
|
||||
this.feed = feed;
|
||||
this.browsing = browsing;
|
||||
this.subscribed = subscribed;
|
||||
}
|
||||
|
||||
void toXML(StringBuilder sb) {
|
||||
|
@ -91,8 +112,13 @@ public class UploadServlet extends HttpServlet {
|
|||
sb.append("<Name>").append(Util.escapeHTMLinXML(name)).append("</Name>");
|
||||
sb.append("<Progress>").append(Util._t("{0}% of piece", String.valueOf(progress))).append("</Progress>");
|
||||
sb.append("<Downloader>").append(Util.escapeHTMLinXML(downloader)).append("</Downloader>");
|
||||
sb.append("<DownloaderB64>").append(b64).append("</DownloaderB64>");
|
||||
sb.append("<RemotePieces>").append(remotePieces).append("/").append(totalPieces).append("</RemotePieces>");
|
||||
sb.append("<Speed>").append(DataHelper.formatSize2Decimal(speed, false)).append("B/sec").append("</Speed>");
|
||||
sb.append("<Browse>").append(browse).append("</Browse>");
|
||||
sb.append("<Browsing>").append(browsing).append("</Browsing>");
|
||||
sb.append("<Feed>").append(feed).append("</Feed>");
|
||||
sb.append("<Subscribed>").append(subscribed).append("</Subscribed>");
|
||||
sb.append("</Upload>");
|
||||
}
|
||||
}
|
||||
|
@ -119,6 +145,14 @@ public class UploadServlet extends HttpServlet {
|
|||
return Integer.compare(l.speed, r.speed);
|
||||
};
|
||||
|
||||
private static final Comparator<UploadEntry> BY_BROWSE = (l, r) -> {
|
||||
return Boolean.compare(l.browse, r.browse);
|
||||
};
|
||||
|
||||
private static final Comparator<UploadEntry> BY_FEED = (l, r) -> {
|
||||
return Boolean.compare(l.feed, r.feed);
|
||||
};
|
||||
|
||||
private static final ColumnComparators<UploadEntry> COMPARATORS = new ColumnComparators<>();
|
||||
static {
|
||||
COMPARATORS.add("Name", BY_NAME);
|
||||
|
@ -126,6 +160,8 @@ public class UploadServlet extends HttpServlet {
|
|||
COMPARATORS.add("Downloader", BY_DOWNLOADER);
|
||||
COMPARATORS.add("Remote Pieces", BY_REMOTE_PIECES);
|
||||
COMPARATORS.add("Speed", BY_SPEED);
|
||||
COMPARATORS.add("Browse", BY_BROWSE);
|
||||
COMPARATORS.add("Feed", BY_FEED);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -4,7 +4,12 @@ class Upload {
|
|||
this.progress = xmlNode.getElementsByTagName("Progress")[0].childNodes[0].nodeValue;
|
||||
this.speed = xmlNode.getElementsByTagName("Speed")[0].childNodes[0].nodeValue;
|
||||
this.downloader = xmlNode.getElementsByTagName("Downloader")[0].childNodes[0].nodeValue
|
||||
this.downloaderB64 = xmlNode.getElementsByTagName("DownloaderB64")[0].childNodes[0].nodeValue
|
||||
this.remotePieces = xmlNode.getElementsByTagName("RemotePieces")[0].childNodes[0].nodeValue
|
||||
this.browse = xmlNode.getElementsByTagName("Browse")[0].childNodes[0].nodeValue
|
||||
this.browsing = xmlNode.getElementsByTagName("Browsing")[0].childNodes[0].nodeValue
|
||||
this.feed = xmlNode.getElementsByTagName("Feed")[0].childNodes[0].nodeValue
|
||||
this.subscribed = xmlNode.getElementsByTagName("Subscribed")[0].childNodes[0].nodeValue
|
||||
}
|
||||
|
||||
getMapping() {
|
||||
|
@ -14,8 +19,29 @@ class Upload {
|
|||
mapping.set("Progress", this.progress)
|
||||
mapping.set("Downloader", this.downloader)
|
||||
mapping.set("Remote Pieces", this.remotePieces)
|
||||
mapping.set("Browse", this.getBrowseBlock())
|
||||
mapping.set("Feed", this.getFeedBlock())
|
||||
return mapping
|
||||
}
|
||||
|
||||
getBrowseBlock() {
|
||||
if (this.browse == "false")
|
||||
return ""
|
||||
if (this.browsing == "true")
|
||||
return "<a href='/MuWire/BrowseHost?currentHost=" + this.downloaderB64 + "'>" + _t("Browsing") + "</a>"
|
||||
var link = new Link(_t("Browse"), "browse", [this.downloaderB64])
|
||||
var block = "<span id='browse-link-" + this.downloaderB64 + "'>" + link.render() + "</span>"
|
||||
return block
|
||||
}
|
||||
|
||||
getFeedBlock() {
|
||||
if (this.feed == "false")
|
||||
return ""
|
||||
if (this.subscribed == "true")
|
||||
return "<a href='/MuWire/Feeds'>" + _t("Subscribed") + "</a>"
|
||||
var link = new Link(_t("Subscribe"), "subscribe", [this.downloaderB64])
|
||||
return "<span id='subscribe-link-" + this.downloaderB64 + "'>" + link.render() + "</span>"
|
||||
}
|
||||
}
|
||||
|
||||
function refreshUploads() {
|
||||
|
@ -37,7 +63,7 @@ function refreshUploads() {
|
|||
newOrder = "ascending"
|
||||
else if (uploadsSortOrder == "ascending")
|
||||
newOrder = "descending"
|
||||
var table = new Table(["Name","Progress","Downloader","Remote Pieces","Speed"], "sortUploads", uploadsSortKey, newOrder, null)
|
||||
var table = new Table(["Name","Progress","Downloader","Browse","Feed","Remote Pieces","Speed"], "sortUploads", uploadsSortKey, newOrder, null)
|
||||
|
||||
for(i = 0; i < uploaderList.length; i++) {
|
||||
table.addRow(uploaderList[i].getMapping())
|
||||
|
@ -60,6 +86,32 @@ function refreshUploads() {
|
|||
xmlhttp.send();
|
||||
}
|
||||
|
||||
function browse(host) {
|
||||
var xmlhttp = new XMLHttpRequest()
|
||||
xmlhttp.onreadystatechange = function() {
|
||||
if (this.readyState == 4 && this.status == 200) {
|
||||
var linkSpan = document.getElementById("browse-link-"+host)
|
||||
linkSpan.innerHTML = "<a href='/MuWire/BrowseHost?currentHost=" + host+ "'>" + _t("Browsing") + "</a>"
|
||||
}
|
||||
}
|
||||
xmlhttp.open("POST", "/MuWire/Browse", true)
|
||||
xmlhttp.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
|
||||
xmlhttp.send("action=browse&host="+host)
|
||||
}
|
||||
|
||||
function subscribe(host) {
|
||||
var xmlhttp = new XMLHttpRequest()
|
||||
xmlhttp.onreadystatechange = function() {
|
||||
if (this.readyState == 4 && this.status == 200) {
|
||||
var linkSpan = document.getElementById("subscribe-link-" + host)
|
||||
linkSpan.innerHTML = "<a href='/MuWire/Feeds'>" + _t("Subscribed") + "</a>"
|
||||
}
|
||||
}
|
||||
xmlhttp.open("POST", "/MuWire/Feed", true)
|
||||
xmlhttp.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
|
||||
xmlhttp.send("action=subscribe&host=" + host)
|
||||
}
|
||||
|
||||
function clear(ignored) {
|
||||
var xmlhttp = new XMLHttpRequest()
|
||||
xmlhttp.onreadystatechange = function() {
|
||||
|
|
Loading…
Reference in New Issue