progressive publish timeout based on filesize, better tracker error log, content.json viewport support, wrapperSetViewport wrapperapi command support, escape wrapper notification
This commit is contained in:
parent
3b22be5091
commit
bccd246f71
5 changed files with 65 additions and 18 deletions
|
@ -150,13 +150,14 @@ class Site:
|
|||
return changed
|
||||
|
||||
|
||||
def publisher(self,inner_path, peers, published, limit):
|
||||
def publisher(self, inner_path, peers, published, limit):
|
||||
timeout = 5+int(os.path.getsize(self.getPath(inner_path))/1024) # Timeout: 5sec + size in kb
|
||||
while 1:
|
||||
if not peers or len(published) >= limit: break # All peers done, or published engouht
|
||||
peer = peers.pop(0)
|
||||
result = {"exception": "Timeout"}
|
||||
try:
|
||||
with gevent.Timeout(60, False): # 60 sec timeout
|
||||
with gevent.Timeout(timeout, False):
|
||||
result = peer.sendCmd("update", {
|
||||
"site": self.address,
|
||||
"inner_path": inner_path,
|
||||
|
@ -240,11 +241,11 @@ class Site:
|
|||
def announce(self, force=False):
|
||||
if time.time() < self.last_announce+15 and not force: return # No reannouncing within 15 secs
|
||||
self.last_announce = time.time()
|
||||
error = 0
|
||||
errors = []
|
||||
|
||||
for protocol, ip, port in SiteManager.TRACKERS:
|
||||
if protocol == "udp":
|
||||
self.log.debug("Announcing to %s://%s:%s..." % (protocol, ip, port))
|
||||
# self.log.debug("Announcing to %s://%s:%s..." % (protocol, ip, port))
|
||||
tracker = UdpTrackerClient(ip, port)
|
||||
tracker.peer_port = config.fileserver_port
|
||||
try:
|
||||
|
@ -254,7 +255,7 @@ class Site:
|
|||
back = tracker.poll_once()
|
||||
peers = back["response"]["peers"]
|
||||
except Exception, err:
|
||||
error += 1
|
||||
errors.append("%s://%s:%s" % (protocol, ip, port))
|
||||
continue
|
||||
|
||||
added = 0
|
||||
|
@ -269,8 +270,8 @@ class Site:
|
|||
else:
|
||||
pass # TODO: http tracker support
|
||||
|
||||
if error < len(SiteManager.TRACKERS): # Less errors than total tracker nums
|
||||
self.log.debug("Announced to %s trackers, error: %s" % (len(SiteManager.TRACKERS), error))
|
||||
if len(errors) < len(SiteManager.TRACKERS): # Less errors than total tracker nums
|
||||
self.log.debug("Announced to %s trackers, errors: %s" % (len(SiteManager.TRACKERS), errors))
|
||||
else:
|
||||
self.log.error("Announced to %s trackers, failed" % len(SiteManager.TRACKERS))
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import time, re, os, mimetypes, json
|
||||
import time, re, os, mimetypes, json, cgi
|
||||
from Config import config
|
||||
from Site import SiteManager
|
||||
from User import UserManager
|
||||
|
@ -124,18 +124,24 @@ class UiRequest:
|
|||
self.sendHeader(extra_headers=[("X-Frame-Options", "DENY")])
|
||||
|
||||
# Wrapper variable inits
|
||||
if self.env.get("QUERY_STRING"):
|
||||
query_string = "?"+self.env["QUERY_STRING"]
|
||||
else:
|
||||
query_string = ""
|
||||
query_string = ""
|
||||
body_style = ""
|
||||
if site.content_manager.contents.get("content.json") and site.content_manager.contents["content.json"].get("background-color"): body_style += "background-color: "+site.content_manager.contents["content.json"]["background-color"]+";"
|
||||
meta_tags = ""
|
||||
|
||||
if self.env.get("QUERY_STRING"): query_string = "?"+self.env["QUERY_STRING"]
|
||||
if site.content_manager.contents.get("content.json") : # Got content.json
|
||||
content = site.content_manager.contents["content.json"]
|
||||
if content.get("background-color"):
|
||||
body_style += "background-color: "+cgi.escape(site.content_manager.contents["content.json"]["background-color"], True)+";"
|
||||
if content.get("viewport"):
|
||||
meta_tags += '<meta name="viewport" id="viewport" content="%s">' % cgi.escape(content["viewport"], True)
|
||||
|
||||
return self.render("src/Ui/template/wrapper.html",
|
||||
inner_path=inner_path,
|
||||
address=match.group("site"),
|
||||
title=title,
|
||||
body_style=body_style,
|
||||
meta_tags=meta_tags,
|
||||
query_string=query_string,
|
||||
wrapper_key=site.settings["wrapper_key"],
|
||||
permissions=json.dumps(site.settings["permissions"]),
|
||||
|
|
|
@ -67,6 +67,8 @@ class Wrapper
|
|||
@actionWrapperConfirm(message)
|
||||
else if cmd == "wrapperPrompt" # Prompt input
|
||||
@actionWrapperPrompt(message)
|
||||
else if cmd == "wrapperSetViewport" # Set the viewport
|
||||
@actionSetViewport(message)
|
||||
else # Send to websocket
|
||||
@ws.send(message) # Pass message to websocket
|
||||
|
||||
|
@ -108,10 +110,20 @@ class Wrapper
|
|||
return false
|
||||
body.append(button)
|
||||
|
||||
|
||||
@notifications.add("notification-#{message.id}", "ask", body)
|
||||
|
||||
|
||||
actionSetViewport: (message) ->
|
||||
@log "actionSetViewport", message
|
||||
if $("#viewport").length > 0
|
||||
$("#viewport").attr("content", @toHtmlSafe message.params)
|
||||
else
|
||||
$('<meta name="viewport" id="viewport">').attr("content", @toHtmlSafe message.params).appendTo("head")
|
||||
|
||||
|
||||
# EOF actions
|
||||
|
||||
|
||||
onOpenWebsocket: (e) =>
|
||||
@ws.cmd "channelJoin", {"channel": "siteChanged"} # Get info on modifications
|
||||
@log "onOpenWebsocket", @inner_ready, @wrapperWsInited
|
||||
|
@ -200,8 +212,14 @@ class Wrapper
|
|||
@site_info = site_info
|
||||
|
||||
|
||||
toHtmlSafe: (unsafe) ->
|
||||
return unsafe
|
||||
toHtmlSafe: (values) ->
|
||||
if values not instanceof Array then values = [values] # Convert to array if its not
|
||||
for value, i in values
|
||||
value = String(value).replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>').replace(/"/g, '"') # Escape
|
||||
value = value.replace(/<([\/]{0,1}(br|b|u|i))>/g, "<$1>") # Unescape b, i, u, br tags
|
||||
values[i] = value
|
||||
return values
|
||||
|
||||
|
||||
|
||||
log: (args...) ->
|
||||
|
|
|
@ -799,6 +799,8 @@ jQuery.extend( jQuery.easing,
|
|||
return this.actionWrapperConfirm(message);
|
||||
} else if (cmd === "wrapperPrompt") {
|
||||
return this.actionWrapperPrompt(message);
|
||||
} else if (cmd === "wrapperSetViewport") {
|
||||
return this.actionSetViewport(message);
|
||||
} else {
|
||||
return this.ws.send(message);
|
||||
}
|
||||
|
@ -862,6 +864,15 @@ jQuery.extend( jQuery.easing,
|
|||
return this.notifications.add("notification-" + message.id, "ask", body);
|
||||
};
|
||||
|
||||
Wrapper.prototype.actionSetViewport = function(message) {
|
||||
this.log("actionSetViewport", message);
|
||||
if ($("#viewport").length > 0) {
|
||||
return $("#viewport").attr("content", this.toHtmlSafe(message.params));
|
||||
} else {
|
||||
return $('<meta name="viewport" id="viewport">').attr("content", this.toHtmlSafe(message.params)).appendTo("head");
|
||||
}
|
||||
};
|
||||
|
||||
Wrapper.prototype.onOpenWebsocket = function(e) {
|
||||
this.ws.cmd("channelJoin", {
|
||||
"channel": "siteChanged"
|
||||
|
@ -974,8 +985,18 @@ jQuery.extend( jQuery.easing,
|
|||
return this.site_info = site_info;
|
||||
};
|
||||
|
||||
Wrapper.prototype.toHtmlSafe = function(unsafe) {
|
||||
return unsafe;
|
||||
Wrapper.prototype.toHtmlSafe = function(values) {
|
||||
var i, value, _i, _len;
|
||||
if (!(values instanceof Array)) {
|
||||
values = [values];
|
||||
}
|
||||
for (i = _i = 0, _len = values.length; _i < _len; i = ++_i) {
|
||||
value = values[i];
|
||||
value = String(value).replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>').replace(/"/g, '"');
|
||||
value = value.replace(/<([\/]{0,1}(br|b|u|i))>/g, "<$1>");
|
||||
values[i] = value;
|
||||
}
|
||||
return values;
|
||||
};
|
||||
|
||||
Wrapper.prototype.log = function() {
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
<meta charset="utf-8">
|
||||
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
|
||||
<link rel="stylesheet" href="/uimedia/all.css" />
|
||||
{meta_tags}
|
||||
</head>
|
||||
<body style="{body_style}">
|
||||
|
||||
|
|
Loading…
Reference in a new issue