[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.
This commit is contained in:
Calum Lind 2021-12-14 22:28:43 +00:00
parent 073bbbc09d
commit a03e649da6
No known key found for this signature in database
GPG Key ID: 90597A687B836BA3
5 changed files with 11 additions and 8 deletions

View File

@ -13,7 +13,7 @@ All modules will require the [common](#common) section dependencies.
- [setuptools] - [setuptools]
- [intltool] - Optional: Desktop file translation for \*nix. - [intltool] - Optional: Desktop file translation for \*nix.
- [closure-compiler] - Minify javascript (alternative is [slimit]) - [closure-compiler] - Minify javascript (alternative is [rjsmin])
## Common ## Common
@ -71,7 +71,7 @@ All modules will require the [common](#common) section dependencies.
[setuptools]: https://setuptools.readthedocs.io/en/latest/ [setuptools]: https://setuptools.readthedocs.io/en/latest/
[intltool]: https://freedesktop.org/wiki/Software/intltool/ [intltool]: https://freedesktop.org/wiki/Software/intltool/
[closure-compiler]: https://developers.google.com/closure/compiler/ [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/ [openssl]: https://www.openssl.org/
[pyopenssl]: https://pyopenssl.org [pyopenssl]: https://pyopenssl.org
[twisted]: https://twistedmatrix.com [twisted]: https://twistedmatrix.com

View File

@ -51,7 +51,7 @@ Deluge.CopyMagnet = Ext.extend(Ext.Window, {
}, },
show: function (a) { show: function (a) {
Deluge.CopyMagnet.superclass.show.call(this); Deluge.CopyMagnet.superclass.show.call(this);
const torrent = deluge.torrents.getSelected(); var torrent = deluge.torrents.getSelected();
deluge.client.core.get_magnet_uri(torrent.id, { deluge.client.core.get_magnet_uri(torrent.id, {
success: this.onRequestComplete, success: this.onRequestComplete,
scope: this, scope: this,

View File

@ -592,13 +592,13 @@ class TopLevel(resource.Resource):
uri_false = ('false', 'no', 'off', '0') uri_false = ('false', 'no', 'off', '0')
debug_arg = None 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: if req_dbg_arg in uri_true:
debug_arg = True debug_arg = True
elif req_dbg_arg in uri_false: elif req_dbg_arg in uri_false:
debug_arg = 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() dev_ver = 'dev' in common.get_version()
script_type = 'normal' script_type = 'normal'

View File

@ -55,14 +55,14 @@ def minify_closure(file_in, file_out):
return False 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. # 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: if not closure_cmd:
try: try:
from slimit import minify as minify from rjsmin import jsmin as minify
except ImportError: except ImportError:
print('Warning: No minifying command found.') print('Warning: No minifying command found.')
minify = None minify = None
@ -124,6 +124,8 @@ def minify_js_dir(source_dir):
print('Minifying %s' % source_dir) print('Minifying %s' % source_dir)
if not minify_file(file_debug_js, file_minified_js): if not minify_file(file_debug_js, file_minified_js):
print('Warning: Failed minifying files %s, debug only' % source_dir) 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__': if __name__ == '__main__':

View File

@ -11,3 +11,4 @@ flake8-comprehensions
flake8-debugger flake8-debugger
flake8-mock flake8-mock
flake8-mutable flake8-mutable
rjsmin