From 49adea1654e3f6060fccc922c0221f242228f0aa Mon Sep 17 00:00:00 2001 From: shortcutme Date: Wed, 12 Apr 2017 17:36:50 +0200 Subject: [PATCH] siteSetLimit returns with ok on success --- plugins/Sidebar/media/Sidebar.coffee | 5 +-- plugins/Sidebar/media/all.js | 42 +++++++++++----------- src/Ui/UiWebsocket.py | 2 +- src/Ui/media/Wrapper.coffee | 8 +++-- src/Ui/media/all.js | 54 +++++++++++++++------------- 5 files changed, 62 insertions(+), 49 deletions(-) diff --git a/plugins/Sidebar/media/Sidebar.coffee b/plugins/Sidebar/media/Sidebar.coffee index 44af3e3f..db0bfb5e 100644 --- a/plugins/Sidebar/media/Sidebar.coffee +++ b/plugins/Sidebar/media/Sidebar.coffee @@ -260,8 +260,9 @@ class Sidebar extends Class # Site limit button @tag.find("#button-sitelimit").off("click").on "click", => - wrapper.ws.cmd "siteSetLimit", $("#input-sitelimit").val(), => - wrapper.notifications.add "done-sitelimit", "done", "Site storage limit modified!", 5000 + wrapper.ws.cmd "siteSetLimit", $("#input-sitelimit").val(), (res) => + if res == "ok" + wrapper.notifications.add "done-sitelimit", "done", "Site storage limit modified!", 5000 @updateHtmlTag() return false diff --git a/plugins/Sidebar/media/all.js b/plugins/Sidebar/media/all.js index c995a02e..bf05eb49 100644 --- a/plugins/Sidebar/media/all.js +++ b/plugins/Sidebar/media/all.js @@ -187,21 +187,21 @@ window.initScrollable = function () { (function() { var Sidebar, - __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; }, - __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }, - __hasProp = {}.hasOwnProperty; + bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; }, + extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }, + hasProp = {}.hasOwnProperty; - Sidebar = (function(_super) { - __extends(Sidebar, _super); + Sidebar = (function(superClass) { + extend(Sidebar, superClass); function Sidebar() { - this.unloadGlobe = __bind(this.unloadGlobe, this); - this.displayGlobe = __bind(this.displayGlobe, this); - this.loadGlobe = __bind(this.loadGlobe, this); - this.animDrag = __bind(this.animDrag, this); - this.setHtmlTag = __bind(this.setHtmlTag, this); - this.waitMove = __bind(this.waitMove, this); - this.resized = __bind(this.resized, this); + this.unloadGlobe = bind(this.unloadGlobe, this); + this.displayGlobe = bind(this.displayGlobe, this); + this.loadGlobe = bind(this.loadGlobe, this); + this.animDrag = bind(this.animDrag, this); + this.setHtmlTag = bind(this.setHtmlTag, this); + this.waitMove = bind(this.waitMove, this); + this.resized = bind(this.resized, this); this.tag = null; this.container = null; this.opened = false; @@ -482,8 +482,10 @@ window.initScrollable = function () { })(this)); this.tag.find("#button-sitelimit").off("click").on("click", (function(_this) { return function() { - wrapper.ws.cmd("siteSetLimit", $("#input-sitelimit").val(), function() { - wrapper.notifications.add("done-sitelimit", "done", "Site storage limit modified!", 5000); + wrapper.ws.cmd("siteSetLimit", $("#input-sitelimit").val(), function(res) { + if (res === "ok") { + wrapper.notifications.add("done-sitelimit", "done", "Site storage limit modified!", 5000); + } return _this.updateHtmlTag(); }); return false; @@ -664,7 +666,7 @@ window.initScrollable = function () { return img.onload = (function(_this) { return function() { return wrapper.ws.cmd("sidebarGetPeers", [], function(globe_data) { - var e, _ref, _ref1; + var e, ref, ref1; if (_this.globe) { _this.globe.scene.remove(_this.globe.points); _this.globe.addData(globe_data, { @@ -684,15 +686,15 @@ window.initScrollable = function () { }); _this.globe.createPoints(); _this.globe.animate(); - } catch (_error) { - e = _error; + } catch (error) { + e = error; console.log("WebGL error", e); - if ((_ref = _this.tag) != null) { - _ref.find(".globe").addClass("error").text("WebGL not supported"); + if ((ref = _this.tag) != null) { + ref.find(".globe").addClass("error").text("WebGL not supported"); } } } - return (_ref1 = _this.tag) != null ? _ref1.find(".globe").removeClass("loading") : void 0; + return (ref1 = _this.tag) != null ? ref1.find(".globe").removeClass("loading") : void 0; }); }; })(this); diff --git a/src/Ui/UiWebsocket.py b/src/Ui/UiWebsocket.py index 1a07e075..35b8ce1c 100644 --- a/src/Ui/UiWebsocket.py +++ b/src/Ui/UiWebsocket.py @@ -771,7 +771,7 @@ class UiWebsocket(object): def actionSiteSetLimit(self, to, size_limit): self.site.settings["size_limit"] = int(size_limit) self.site.saveSettings() - self.response(to, _["Site size limit changed to {0}MB"].format(size_limit)) + self.response(to, "ok") self.site.download(blind_includes=True) def actionServerUpdate(self, to): diff --git a/src/Ui/media/Wrapper.coffee b/src/Ui/media/Wrapper.coffee index 5648080e..d755b108 100644 --- a/src/Ui/media/Wrapper.coffee +++ b/src/Ui/media/Wrapper.coffee @@ -402,7 +402,8 @@ class Wrapper else @displayConfirm "Site is larger than allowed: #{(site_info.settings.size/1024/1024).toFixed(1)}MB/#{site_info.size_limit}MB", "Set limit to #{site_info.next_size_limit}MB", => @ws.cmd "siteSetLimit", [site_info.next_size_limit], (res) => - @notifications.add("size_limit", "done", res, 5000) + if res == "ok" + @notifications.add("size_limit", "done", "Site storage limit modified!", 5000) if site_info.content window.document.title = site_info.content.title+" - ZeroNet" @@ -449,7 +450,8 @@ class Wrapper if site_info.size_limit*1.1 < site_info.next_size_limit # Need upgrade soon @displayConfirm "Running out of size limit (#{(site_info.settings.size/1024/1024).toFixed(1)}MB/#{site_info.size_limit}MB)", "Set limit to #{site_info.next_size_limit}MB", => @ws.cmd "siteSetLimit", [site_info.next_size_limit], (res) => - @notifications.add("size_limit", "done", res, 5000) + if res == "ok" + @notifications.add("size_limit", "done", "Site storage limit modified!", 5000) return false if @loading.screen_visible and @inner_loaded and site_info.settings.size < site_info.size_limit*1024*1024 and site_info.settings.size > 0 # Loading screen still visible, but inner loaded @@ -476,6 +478,8 @@ class Wrapper setSizeLimit: (size_limit, reload=true) => @ws.cmd "siteSetLimit", [size_limit], (res) => + if res != "ok" + return false @loading.printLine res @inner_loaded = false # Inner frame not loaded, just a 404 page displayed if reload diff --git a/src/Ui/media/all.js b/src/Ui/media/all.js index 9841177a..7d52fc8e 100644 --- a/src/Ui/media/all.js +++ b/src/Ui/media/all.js @@ -679,7 +679,6 @@ jQuery.extend( jQuery.easing, }).call(this); - /* ---- src/Ui/media/Notifications.coffee ---- */ @@ -810,19 +809,19 @@ jQuery.extend( jQuery.easing, (function() { var Wrapper, origin, proto, ws_url, - __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; }, - __indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; }, - __slice = [].slice; + bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; }, + indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; }, + slice = [].slice; Wrapper = (function() { function Wrapper(ws_url) { - this.gotoSite = __bind(this.gotoSite, this); - this.setSizeLimit = __bind(this.setSizeLimit, this); - this.onLoad = __bind(this.onLoad, this); - this.onCloseWebsocket = __bind(this.onCloseWebsocket, this); - this.onOpenWebsocket = __bind(this.onOpenWebsocket, this); - this.onMessageInner = __bind(this.onMessageInner, this); - this.onMessageWebsocket = __bind(this.onMessageWebsocket, this); + this.gotoSite = bind(this.gotoSite, this); + this.setSizeLimit = bind(this.setSizeLimit, this); + this.onLoad = bind(this.onLoad, this); + this.onCloseWebsocket = bind(this.onCloseWebsocket, this); + this.onOpenWebsocket = bind(this.onOpenWebsocket, this); + this.onMessageInner = bind(this.onMessageInner, this); + this.onMessageWebsocket = bind(this.onMessageWebsocket, this); this.log("Created!"); this.loading = new Loading(); this.notifications = new Notifications($(".notifications")); @@ -870,7 +869,7 @@ jQuery.extend( jQuery.easing, } Wrapper.prototype.onMessageWebsocket = function(e) { - var cmd, id, message, type, _ref; + var cmd, id, message, ref, type; message = JSON.parse(e.data); cmd = message.cmd; if (cmd === "response") { @@ -882,8 +881,8 @@ jQuery.extend( jQuery.easing, } else if (cmd === "notification") { type = message.params[0]; id = "notification-" + message.id; - if (__indexOf.call(message.params[0], "-") >= 0) { - _ref = message.params[0].split("-"), id = _ref[0], type = _ref[1]; + if (indexOf.call(message.params[0], "-") >= 0) { + ref = message.params[0].split("-"), id = ref[0], type = ref[1]; } return this.notifications.add(id, type, message.params[1], message.params[2]); } else if (cmd === "progress") { @@ -1038,7 +1037,7 @@ jQuery.extend( jQuery.easing, Wrapper.prototype.actionRequestFullscreen = function() { var elem, request_fullscreen; - if (__indexOf.call(this.site_info.settings.permissions, "Fullscreen") >= 0) { + if (indexOf.call(this.site_info.settings.permissions, "Fullscreen") >= 0) { elem = document.getElementById("inner-iframe"); request_fullscreen = elem.requestFullScreen || elem.webkitRequestFullscreen || elem.mozRequestFullScreen || elem.msRequestFullScreen; request_fullscreen.call(elem); @@ -1336,7 +1335,7 @@ jQuery.extend( jQuery.easing, }; Wrapper.prototype.onLoad = function(e) { - var _ref; + var ref; this.inner_loaded = true; if (!this.inner_ready) { this.sendInner({ @@ -1345,7 +1344,7 @@ jQuery.extend( jQuery.easing, } if (this.ws.ws.readyState === 1 && !this.site_info) { return this.reloadSiteInfo(); - } else if (this.site_info && (((_ref = this.site_info.content) != null ? _ref.title : void 0) != null)) { + } else if (this.site_info && (((ref = this.site_info.content) != null ? ref.title : void 0) != null)) { window.document.title = this.site_info.content.title + " - ZeroNet"; return this.log("Setting title to", window.document.title); } @@ -1374,7 +1373,9 @@ jQuery.extend( jQuery.easing, } else { _this.displayConfirm("Site is larger than allowed: " + ((site_info.settings.size / 1024 / 1024).toFixed(1)) + "MB/" + site_info.size_limit + "MB", "Set limit to " + site_info.next_size_limit + "MB", function() { return _this.ws.cmd("siteSetLimit", [site_info.next_size_limit], function(res) { - return _this.notifications.add("size_limit", "done", res, 5000); + if (res === "ok") { + return _this.notifications.add("size_limit", "done", "Site storage limit modified!", 5000); + } }); }); } @@ -1430,7 +1431,9 @@ jQuery.extend( jQuery.easing, this.displayConfirm("Running out of size limit (" + ((site_info.settings.size / 1024 / 1024).toFixed(1)) + "MB/" + site_info.size_limit + "MB)", "Set limit to " + site_info.next_size_limit + "MB", (function(_this) { return function() { _this.ws.cmd("siteSetLimit", [site_info.next_size_limit], function(res) { - return _this.notifications.add("size_limit", "done", res, 5000); + if (res === "ok") { + return _this.notifications.add("size_limit", "done", "Site storage limit modified!", 5000); + } }); return false; }; @@ -1453,11 +1456,11 @@ jQuery.extend( jQuery.easing, }; Wrapper.prototype.toHtmlSafe = function(values) { - var i, value, _i, _len; + var i, j, len, value; if (!(values instanceof Array)) { values = [values]; } - for (i = _i = 0, _len = values.length; _i < _len; i = ++_i) { + for (i = j = 0, len = values.length; j < len; i = ++j) { value = values[i]; value = String(value).replace(/&/g, '&').replace(//g, '>').replace(/"/g, '"'); value = value.replace(/<([\/]{0,1}(br|b|u|i))>/g, "<$1>"); @@ -1473,6 +1476,9 @@ jQuery.extend( jQuery.easing, this.ws.cmd("siteSetLimit", [size_limit], (function(_this) { return function(res) { var src; + if (res !== "ok") { + return false; + } _this.loading.printLine(res); _this.inner_loaded = false; if (reload) { @@ -1499,8 +1505,8 @@ jQuery.extend( jQuery.easing, Wrapper.prototype.log = function() { var args; - args = 1 <= arguments.length ? __slice.call(arguments, 0) : []; - return console.log.apply(console, ["[Wrapper]"].concat(__slice.call(args))); + args = 1 <= arguments.length ? slice.call(arguments, 0) : []; + return console.log.apply(console, ["[Wrapper]"].concat(slice.call(args))); }; return Wrapper; @@ -1525,4 +1531,4 @@ jQuery.extend( jQuery.easing, window.wrapper = new Wrapper(ws_url); -}).call(this); \ No newline at end of file +}).call(this);