From a03e649da6b243986d7ca4ae467be6f17558d97a Mon Sep 17 00:00:00 2001 From: Calum Lind Date: Tue, 14 Dec 2021 22:28:43 +0000 Subject: [PATCH] [Build] Fix WebUI js minifying error Some users encoutered a bug where WebUI in browser show a white screen, which indicates a problem with loading javascript files. The problem was due to closure minifying failure leaving a zero-length deluge-all.js file which broke the usual fallback mechanism to debug files. * Fixed usage of ES6 const declaration breaking closure minifying. * Cleanup minified files upon errors so no zero length files left * Replaced broken and unmaintained slimit with rjsmin. * Fixed unable to set dev or debug query args due to request args requiring bytes. --- DEPENDS.md | 4 ++-- deluge/ui/web/js/deluge-all/CopyMagnetWindow.js | 2 +- deluge/ui/web/server.py | 4 ++-- minify_web_js.py | 8 +++++--- requirements-dev.txt | 1 + 5 files changed, 11 insertions(+), 8 deletions(-) diff --git a/DEPENDS.md b/DEPENDS.md index d15824446..0844718c4 100644 --- a/DEPENDS.md +++ b/DEPENDS.md @@ -13,7 +13,7 @@ All modules will require the [common](#common) section dependencies. - [setuptools] - [intltool] - Optional: Desktop file translation for \*nix. -- [closure-compiler] - Minify javascript (alternative is [slimit]) +- [closure-compiler] - Minify javascript (alternative is [rjsmin]) ## Common @@ -71,7 +71,7 @@ All modules will require the [common](#common) section dependencies. [setuptools]: https://setuptools.readthedocs.io/en/latest/ [intltool]: https://freedesktop.org/wiki/Software/intltool/ [closure-compiler]: https://developers.google.com/closure/compiler/ -[slimit]: https://slimit.readthedocs.io/en/latest/ +[rjsmin]: https://pypi.org/project/rjsmin/ [openssl]: https://www.openssl.org/ [pyopenssl]: https://pyopenssl.org [twisted]: https://twistedmatrix.com diff --git a/deluge/ui/web/js/deluge-all/CopyMagnetWindow.js b/deluge/ui/web/js/deluge-all/CopyMagnetWindow.js index 3e0cc9464..ddcd4abf9 100644 --- a/deluge/ui/web/js/deluge-all/CopyMagnetWindow.js +++ b/deluge/ui/web/js/deluge-all/CopyMagnetWindow.js @@ -51,7 +51,7 @@ Deluge.CopyMagnet = Ext.extend(Ext.Window, { }, show: function (a) { Deluge.CopyMagnet.superclass.show.call(this); - const torrent = deluge.torrents.getSelected(); + var torrent = deluge.torrents.getSelected(); deluge.client.core.get_magnet_uri(torrent.id, { success: this.onRequestComplete, scope: this, diff --git a/deluge/ui/web/server.py b/deluge/ui/web/server.py index f3866729e..ea2658071 100644 --- a/deluge/ui/web/server.py +++ b/deluge/ui/web/server.py @@ -592,13 +592,13 @@ class TopLevel(resource.Resource): uri_false = ('false', 'no', 'off', '0') debug_arg = None - req_dbg_arg = request.args.get('debug', [b''])[-1].decode().lower() + req_dbg_arg = request.args.get(b'debug', [b''])[-1].decode().lower() if req_dbg_arg in uri_true: debug_arg = True elif req_dbg_arg in uri_false: debug_arg = False - dev_arg = request.args.get('dev', [b''])[-1].decode().lower() in uri_true + dev_arg = request.args.get(b'dev', [b''])[-1].decode().lower() in uri_true dev_ver = 'dev' in common.get_version() script_type = 'normal' diff --git a/minify_web_js.py b/minify_web_js.py index 18f2d2343..a5cd97c59 100755 --- a/minify_web_js.py +++ b/minify_web_js.py @@ -55,14 +55,14 @@ def minify_closure(file_in, file_out): return False -# Closure outputs smallest files but it is a java-based command, so have slimit +# Closure outputs smallest files but java-based command, can use rJSmin # as a python-only fallback. # -# deluge-all.js: Closure 127K, Slimit: 143K, JSMin: 162K +# deluge-all.js: Closure 131K, rJSmin: 148K # if not closure_cmd: try: - from slimit import minify as minify + from rjsmin import jsmin as minify except ImportError: print('Warning: No minifying command found.') minify = None @@ -124,6 +124,8 @@ def minify_js_dir(source_dir): print('Minifying %s' % source_dir) if not minify_file(file_debug_js, file_minified_js): print('Warning: Failed minifying files %s, debug only' % source_dir) + if os.path.isfile(file_minified_js): + os.remove(file_minified_js) if __name__ == '__main__': diff --git a/requirements-dev.txt b/requirements-dev.txt index c66dd799f..7e1194457 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -11,3 +11,4 @@ flake8-comprehensions flake8-debugger flake8-mock flake8-mutable +rjsmin