From 036ead920a1eaae2b6788c81cc0b4dc8373d2872 Mon Sep 17 00:00:00 2001 From: drfho Date: Sat, 14 Dec 2024 18:45:20 +0800 Subject: [PATCH 1/4] Added hash to minified JS aggregate for cache refreshing --- .gitignore | 1 + Products/zms/__init__.py | 11 +++++++++++ Products/zms/_confmanager.py | 1 + Products/zms/zpt/common/zmi_html_head.zpt | 4 +++- 4 files changed, 16 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 410739dbd..f47b661d2 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,7 @@ *.egg-info/ *.pyc Products/zms/plugins/www/zms-all.min.js +Products/zms/plugins/www/zms-all.min.js.hash Products/zms/plugins/www/i18n/*.js Products/zms/overrides.zcml .vscode/ diff --git a/Products/zms/__init__.py b/Products/zms/__init__.py index 94533f75e..0be807823 100644 --- a/Products/zms/__init__.py +++ b/Products/zms/__init__.py @@ -252,6 +252,17 @@ def initialize(context): standard.writeStdout(context, "add %s (Packed: %i -> %i Bytes)"%(fn, l0, l1)) fileobj.write(fc) fileobj.close() + # Before closing minified file finally create hash + # of packed file content and write it into separate file + min_fileobj = open(fileobj.name, 'r') + min_hash = standard.encrypt_password(min_fileobj.read(),hex=True) + min_hash_fileobj = open(fileobj.name + '.hash', 'w') + min_hash_fileobj.write(min_hash) + OFS.misc_.misc_.zms['confdict']['js_min.hash'] = min_hash + standard.writeStdout(context, "New minify hash created: %s" % min_hash_fileobj.name) + min_hash_fileobj.close() + min_fileobj.close() + # automated generation of language JavaScript from xml.dom import minidom diff --git a/Products/zms/_confmanager.py b/Products/zms/_confmanager.py index 347c0662e..90d838bac 100644 --- a/Products/zms/_confmanager.py +++ b/Products/zms/_confmanager.py @@ -471,6 +471,7 @@ def getConfPropertiesDefaults(self): {'key':'jquery.ui','title':'JQuery UI version','desc':'JQuery UI version.','datatype':'string'}, {'key':'jquery.plugin.version','title':'JQuery plugin version','desc':'JQuery plugin version','datatype':'string'}, {'key':'jquery.plugin.extensions','title':'JQuery plugin extensions','desc':'JQuery plugin extensions','datatype':'string'}, + {'key':'js_min.hash','title':'Hash value of minified ZMI-Javascript aggregate','desc':'Use hash-value of the minified ZMI-Javascript aggregate file for cache bustering','datatype':'string'}, {'key':'ZMS.blobfields.grant_public_access','title':'Grant public access to blob-fields','desc':'Blob-fields in restricted nodes are not visible. You may grant public access to blob-fields by activating this option.','datatype':'boolean'}, {'key':'ZMS.blobfields.accept_ranges','title':'Http-Header Accept-Ranges for blob-fields','desc':'Http-Header Accept-Ranges for blob-fields.','datatype':'string','default':'bytes'}, {'key':'ZMS.locale.amount.unit','title':'Currency unit for amount-types','desc':'The currency unit used for amount-types.','datatype':'string','default':'EUR'}, diff --git a/Products/zms/zpt/common/zmi_html_head.zpt b/Products/zms/zpt/common/zmi_html_head.zpt index 96cf196f4..6e4c1d197 100644 --- a/Products/zms/zpt/common/zmi_html_head.zpt +++ b/Products/zms/zpt/common/zmi_html_head.zpt @@ -27,7 +27,9 @@ + > From 71e8cd681ef95e8d16f6836c0eb1d882c8ba2243 Mon Sep 17 00:00:00 2001 From: drfho Date: Sat, 14 Dec 2024 19:20:00 +0800 Subject: [PATCH 2/4] log text --- Products/zms/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Products/zms/__init__.py b/Products/zms/__init__.py index 0be807823..0ee670a0a 100644 --- a/Products/zms/__init__.py +++ b/Products/zms/__init__.py @@ -259,7 +259,7 @@ def initialize(context): min_hash_fileobj = open(fileobj.name + '.hash', 'w') min_hash_fileobj.write(min_hash) OFS.misc_.misc_.zms['confdict']['js_min.hash'] = min_hash - standard.writeStdout(context, "New minify hash created: %s" % min_hash_fileobj.name) + standard.writeStdout(context, "add %s" % min_hash_fileobj.name) min_hash_fileobj.close() min_fileobj.close() From 8c077821977c526c6d35feb17c2c5920c584fb70 Mon Sep 17 00:00:00 2001 From: drfho Date: Sat, 14 Dec 2024 19:22:49 +0800 Subject: [PATCH 3/4] doc text --- Products/zms/__init__.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Products/zms/__init__.py b/Products/zms/__init__.py index 0ee670a0a..783a79418 100644 --- a/Products/zms/__init__.py +++ b/Products/zms/__init__.py @@ -252,8 +252,9 @@ def initialize(context): standard.writeStdout(context, "add %s (Packed: %i -> %i Bytes)"%(fn, l0, l1)) fileobj.write(fc) fileobj.close() - # Before closing minified file finally create hash - # of packed file content and write it into separate file + # Finally create hash value of packed file content: + # a. write it into separate file and + # b. create a configuration parameter min_fileobj = open(fileobj.name, 'r') min_hash = standard.encrypt_password(min_fileobj.read(),hex=True) min_hash_fileobj = open(fileobj.name + '.hash', 'w') From 5ba307e8310864ee41f91b927abf85710a92c2ea Mon Sep 17 00:00:00 2001 From: drfho Date: Mon, 16 Dec 2024 18:24:10 +0800 Subject: [PATCH 4/4] use python builtin hash function --- Products/zms/__init__.py | 3 ++- Products/zms/zpt/common/zmi_html_head.zpt | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/Products/zms/__init__.py b/Products/zms/__init__.py index 783a79418..78c8e9deb 100644 --- a/Products/zms/__init__.py +++ b/Products/zms/__init__.py @@ -256,7 +256,8 @@ def initialize(context): # a. write it into separate file and # b. create a configuration parameter min_fileobj = open(fileobj.name, 'r') - min_hash = standard.encrypt_password(min_fileobj.read(),hex=True) + min_fileobj_content = min_fileobj.read() + min_hash = str(hash(min_fileobj_content)) min_hash_fileobj = open(fileobj.name + '.hash', 'w') min_hash_fileobj.write(min_hash) OFS.misc_.misc_.zms['confdict']['js_min.hash'] = min_hash diff --git a/Products/zms/zpt/common/zmi_html_head.zpt b/Products/zms/zpt/common/zmi_html_head.zpt index 6e4c1d197..c84bdf247 100644 --- a/Products/zms/zpt/common/zmi_html_head.zpt +++ b/Products/zms/zpt/common/zmi_html_head.zpt @@ -28,7 +28,7 @@