rev115, Stats for total number of objects in memory, Peers in memory, Memory dump displays the total content on hover, Add http cache to js, css and image files, Allow query file status with SiteInfo websocket command to fix index.html loaded before websocket connection made problem, Fix bigsites reload problem

This commit is contained in:
HelloZeroNet 2015-04-20 22:31:29 +02:00
parent 8d5a72f0b5
commit dc4292e1e3
9 changed files with 64 additions and 26 deletions

View file

@ -4,7 +4,7 @@ import ConfigParser
class Config(object):
def __init__(self):
self.version = "0.2.9"
self.rev = 110
self.rev = 115
self.parser = self.createArguments()
argv = sys.argv[:] # Copy command line arguments
argv = self.parseConfig(argv) # Add arguments from config file

View file

@ -69,6 +69,10 @@ class UiRequest(object):
return self.env["PATH_INFO"].startswith("http://")
def isAjaxRequest(self):
return self.env.get("HTTP_X_REQUESTED_WITH") == "XMLHttpRequest"
# Get mime by filename
def getContentType(self, file_name):
content_type = mimetypes.guess_type(file_name)[0]
@ -104,8 +108,13 @@ class UiRequest(object):
headers = []
headers.append(("Version", "HTTP/1.1"))
headers.append(("Access-Control-Allow-Origin", "*")) # Allow json access
headers.append(("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept")) # Allow json access
headers.append(("Cache-Control", "no-cache, no-store, private, must-revalidate, max-age=0")) # No caching at all
if self.env["REQUEST_METHOD"] == "OPTIONS":
headers.append(("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept")) # Allow json access
if (self.env["REQUEST_METHOD"] == "OPTIONS" or not self.isAjaxRequest()) and status == 200 and (content_type == "text/css" or content_type == "application/javascript" or self.env["REQUEST_METHOD"] == "OPTIONS" or content_type.startswith("image")): # Cache Css, Js, Image files for 10min
headers.append(("Cache-Control", "public, max-age=600")) # Cache 10 min
else: # Images, Css, Js
headers.append(("Cache-Control", "no-cache, no-store, private, must-revalidate, max-age=0")) # No caching at all
#headers.append(("Cache-Control", "public, max-age=604800")) # Cache 1 week
headers.append(("Content-Type", content_type))
for extra_header in extra_headers:
@ -190,6 +199,7 @@ class UiRequest(object):
return self.render("src/Ui/template/wrapper.html",
server_url=server_url,
inner_path=inner_path,
file_inner_path=file_inner_path,
address=address,
title=title,
body_style=body_style,

View file

@ -199,8 +199,11 @@ class UiWebsocket(object):
# Send site details
def actionSiteInfo(self, to):
def actionSiteInfo(self, to, file_status = None):
ret = self.formatSiteInfo(self.site)
if file_status: # Client queries file status
if self.site.storage.isFile(file_status): # File exits, add event done
ret["event"] = ("file_done", file_status)
self.response(to, ret)

View file

@ -31,6 +31,7 @@ class Loading
# We dont need loadingscreen anymore
hideScreen: ->
console.log "hideScreen"
if not $(".loadingscreen").hasClass("done") # Only if its not animating already
if @screen_visible # Hide with animate
$(".loadingscreen").addClass("done").removeLater(2000)

View file

@ -223,7 +223,12 @@ class Wrapper
# Get site info from UiServer
reloadSiteInfo: ->
@ws.cmd "siteInfo", {}, (site_info) =>
if @loading.screen_visible # Loading screen visible
params = {"file_status": window.file_inner_path} # Query the current required file status
else
params = {}
@ws.cmd "siteInfo", params, (site_info) =>
@address = site_info.address
@setSiteInfo site_info
@ -244,12 +249,12 @@ class Wrapper
# File finished downloading
else if site_info.event[0] == "file_done"
@loading.printLine("#{site_info.event[1]} downloaded")
if site_info.event[1] == window.inner_path # File downloaded we currently on
if site_info.event[1] == window.file_inner_path # File downloaded we currently on
@loading.hideScreen()
if not @site_info then @reloadSiteInfo()
if site_info.content
window.document.title = site_info.content.title+" - ZeroNet"
@log "Setting title to", window.document.title
@log "Required file done, setting title to", window.document.title
if not $(".loadingscreen").length # Loading screen already removed (loaded +2sec)
@notifications.add("modified", "info", "New version of this page has just released.<br>Reload to see the modified content.")
# File failed downloading
@ -304,7 +309,7 @@ class Wrapper
@loading.printLine res
@inner_loaded = false # Inner frame not loaded, just a 404 page displayed
if reload
$("iframe").attr "src", $("iframe").attr("src")+"?"+(+new Date) # Reload iframe
$("iframe").attr "src", $("iframe").attr("src")+"&"+(+new Date) # Reload iframe
return false

View file

@ -506,6 +506,7 @@ jQuery.extend( jQuery.easing,
};
Loading.prototype.hideScreen = function() {
console.log("hideScreen");
if (!$(".loadingscreen").hasClass("done")) {
if (this.screen_visible) {
$(".loadingscreen").addClass("done").removeLater(2000);
@ -1047,7 +1048,15 @@ jQuery.extend( jQuery.easing,
};
Wrapper.prototype.reloadSiteInfo = function() {
return this.ws.cmd("siteInfo", {}, (function(_this) {
var params;
if (this.loading.screen_visible) {
params = {
"file_status": window.file_inner_path
};
} else {
params = {};
}
return this.ws.cmd("siteInfo", params, (function(_this) {
return function(site_info) {
_this.address = site_info.address;
_this.setSiteInfo(site_info);
@ -1068,14 +1077,14 @@ jQuery.extend( jQuery.easing,
this.loading.printLine(site_info.bad_files + " files needs to be downloaded");
} else if (site_info.event[0] === "file_done") {
this.loading.printLine(site_info.event[1] + " downloaded");
if (site_info.event[1] === window.inner_path) {
if (site_info.event[1] === window.file_inner_path) {
this.loading.hideScreen();
if (!this.site_info) {
this.reloadSiteInfo();
}
if (site_info.content) {
window.document.title = site_info.content.title + " - ZeroNet";
this.log("Setting title to", window.document.title);
this.log("Required file done, setting title to", window.document.title);
}
if (!$(".loadingscreen").length) {
this.notifications.add("modified", "info", "New version of this page has just released.<br>Reload to see the modified content.");
@ -1147,7 +1156,7 @@ jQuery.extend( jQuery.easing,
_this.loading.printLine(res);
_this.inner_loaded = false;
if (reload) {
return $("iframe").attr("src", $("iframe").attr("src") + "?" + (+(new Date)));
return $("iframe").attr("src", $("iframe").attr("src") + "&" + (+(new Date)));
}
};
})(this));

View file

@ -45,7 +45,7 @@
<!-- Site info -->
<script>address = "{address}"</script>
<script>wrapper_key = "{wrapper_key}"</script>
<script>inner_path = "{inner_path}"</script>
<script>file_inner_path = "{file_inner_path}"</script>
<script>permissions = {permissions}</script>
<script>show_loadingscreen = {show_loadingscreen}</script>
<script>server_url = '{server_url}'</script>