From 13abc35d465ded3266b704642d5b4f4b321c1bb6 Mon Sep 17 00:00:00 2001 From: fvanroie <15969459+fvanroie@users.noreply.github.com> Date: Sat, 13 Nov 2021 08:10:40 +0100 Subject: [PATCH] Add script.js.gz --- .gitignore | 2 + data/script.js | 1 + data/script.js.gz | Bin 0 -> 1225 bytes src/sys/svc/hasp_http.cpp | 132 +++++++++++++++++++++++------------ user_setups/esp32/_esp32.ini | 1 + 5 files changed, 92 insertions(+), 44 deletions(-) create mode 100644 data/script.js create mode 100644 data/script.js.gz diff --git a/.gitignore b/.gitignore index e65d6fd8..4b197432 100644 --- a/.gitignore +++ b/.gitignore @@ -10,6 +10,8 @@ data/* !data/vars.css !data/style.css !data/style.css.gz +!data/script.js +!data/script.js.gz src/user_setups/active/* include/user_config_override.h src/user_config_override.h diff --git a/data/script.js b/data/script.js new file mode 100644 index 00000000..9a8e4bea --- /dev/null +++ b/data/script.js @@ -0,0 +1 @@ +function aref(e){setTimeout(function(){ref("")},1e3*e)}function ref(e){var o=(new Date).getTime();return document.getElementById("bmp").src="?a="+e+"&q="+o,!1}function about(){document.getElementById("doc").innerHTML='

openHASP

Copyright© 2019-2021 Francis Van Roie
MIT License

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files(the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and / or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.


Based on the previous work of the following open source developers:

HASwitchPlate

Copyright© 2019 Allen Derusha allen @derusha.org
MIT License

LVGL

Copyright© 2021 LVGL Kft
MIT License

zi Font Engine

Copyright© 2020-2021 Francis Van Roie
MIT License

TFT_eSPI Library

Copyright© 2020 Bodmer (https://github.com/Bodmer) All rights reserved.
FreeBSD License

includes parts from the Adafruit_GFX library
Copyright© 2012 Adafruit Industries. All rights reserved
BSD License

ArduinoJson

Copyright© 2014-2021 Benoit BLANCHON
MIT License

PubSubClient

Copyright© 2008-2015 Nicholas O'Leary
MIT License

ArduinoLog

Copyright© 2017,2018 Thijs Elenbaas, MrRobot62, rahuldeo2047, NOX73, dhylands, Josha blemasle, mfalkvidd
MIT License

QR Code generator

Copyright© Project Nayuki
MIT License

AceButton

Copyright© 2018 Brian T. Park
MIT License

'} \ No newline at end of file diff --git a/data/script.js.gz b/data/script.js.gz new file mode 100644 index 0000000000000000000000000000000000000000..35c934fdf305fa7cab702dbc9f93fbd7159ebafa GIT binary patch literal 1225 zcmV;)1UCC0iwFo2UXNh{0CQtfEdYI6X6Rc&+9KoI^bD<2dz(pulOq5(pQh9oAb z+E30US;*Ot!@Em6==k5=JD^%Eonat%yZh|3FL{`^O`*AHfJvNpvG-G<&iE2VtGhc} zxA)T+JDuJy=Mg@>kG)@4VcVz+CPBREHh2kRrm@#wY+$;**AjIr8z@E5F0s+Z;?-y# zhikv=cJk$_)9Wi)yy?7UZ#oa~LFevw`W4QdM}P9LoEQ<2y)a}T7~V7}r`arcbMLr% zJP<2vrfwP^AJAbWR%^)@mA+fh(`z_7eDw0+(c#e}m`K(XT)`*SKq5FEALMc{^D_u| zfsLZ`YH++7#3+|sDMN>xE0mb8VL`DPO9$o>5yTvdipd2!parmI4J(w20z|GEZ+No+ z1}44n)D^)fG1r$&A~~19loADJgm=|1X3L-R8dXx3LQ(+fu$(<-29@gYSrd7SCs=LH_&;j z=~9_X+bPGEaR5Ss!n!sX92FINjo-#g3)388upmBCEiO%Qg=k7{YErMZbIU3;`*VR%>{b98p^35OVaKq#n(fY{DnxCr2v$Oxr2p00-;tPlkVcd2vzvI}rw}L6Cx7gXq2s1>?l|z-&!*97 z2IP^rVRi=51l;fpKKS9-0q;wkcxehz0{$!xe2?z@a1@-5{qO{a6cQVYJ!G?Y~Nhpgq z^TMp}hjazrCwhi->IQ+$T7!lN2?VTO~Tq2X4vcvgP{g$>a;v8-lwo-!!8m*hPTfl&w)pRQ;PcS%hnJ_+Zx( zSC%br#Cy`lTlV3}rq4rc1f?4WZaA7o;l4JmM^YqFA}p{$$+VFB*u_%Vf0U4| n+jG9R$^wV2*0+x21q>x;4PfW#4OrT$CdI"; const char HTTP_META_GO_BACK[] PROGMEM = ""; const char HTTP_HEADER[] PROGMEM = "%s"; -const char HTTP_HEADER_END[] PROGMEM = "
"; +const char HTTP_HEADER_END[] PROGMEM = + "" + "
"; const char HTTP_FOOTER[] PROGMEM = ""; @@ -462,40 +465,40 @@ static void webHandleAbout() String httpMessage((char*)0); httpMessage.reserve(HTTP_PAGE_SIZE); - httpMessage += F("

openHASP

Copyright© 2019-2021 Francis Van Roie "); - httpMessage += mitLicense; - httpMessage += F("

Based on the previous work of the following open source developers.


"); - httpMessage += F("

HASwitchPlate

Copyright© 2019 Allen Derusha allen@derusha.org"); - httpMessage += mitLicense; - httpMessage += F("

LVGL

Copyright© 2021 LVGL Kft"); - httpMessage += mitLicense; - httpMessage += F("

zi Font Engine

Copyright© 2020-2021 Francis Van Roie"); - httpMessage += mitLicense; - httpMessage += F("

TFT_eSPI Library

Copyright© 2020 Bodmer (https://github.com/Bodmer) All " - "rights reserved.
FreeBSD License

"); - httpMessage += - F("

includes parts from the Adafruit_GFX library
Copyright© 2012 Adafruit Industries. " - "All rights reserved
BSD License

"); - httpMessage += F("

ArduinoJson

Copyright© 2014-2021 Benoit BLANCHON"); - httpMessage += mitLicense; - httpMessage += F("

PubSubClient

Copyright© 2008-2015 Nicholas O'Leary"); - httpMessage += mitLicense; - httpMessage += - F("

ArduinoLog

Copyright© 2017,2018 Thijs Elenbaas, MrRobot62, rahuldeo2047, NOX73, " - "dhylands, Josha blemasle, mfalkvidd"); - httpMessage += mitLicense; -#if HASP_USE_SYSLOG > 0 - // Replaced with WiFiUDP client - // httpMessage += F("

Syslog

Copyright© 2016 Martin Sloup"); - // httpMessage += mitLicense; -#endif -#if HASP_USE_QRCODE > 0 - httpMessage += F("

QR Code generator

Copyright© Project Nayuki"); - httpMessage += mitLicense; -#endif - httpMessage += F("

AceButton

Copyright© 2018 Brian T. Park"); - httpMessage += mitLicense; - + /* + httpMessage += F("

openHASP

Copyright© 2019-2021 Francis Van Roie "); + httpMessage += mitLicense; + httpMessage += F("

Based on the previous work of the following open source developers.


"); + httpMessage += F("

HASwitchPlate

Copyright© 2019 Allen Derusha allen@derusha.org"); + httpMessage += mitLicense; + httpMessage += F("

LVGL

Copyright© 2021 LVGL Kft"); + httpMessage += mitLicense; + httpMessage += F("

TFT_eSPI Library

Copyright© 2020 Bodmer (https://github.com/Bodmer) + All " "rights reserved.
FreeBSD License

"); httpMessage += F("

includes parts from the + Adafruit_GFX library
Copyright© 2012 Adafruit Industries. " "All rights reserved
BSD + License

"); httpMessage += F("

ArduinoJson

Copyright© 2014-2021 Benoit BLANCHON"); + httpMessage += mitLicense; + httpMessage += F("

PubSubClient

Copyright© 2008-2015 Nicholas O'Leary"); + httpMessage += mitLicense; + httpMessage += F("

FreeType

Copyright© 1996-2002, 2006 David Turner, Robert Wilhelm, " + "and Werner Lemberg.
FreeType License

"); + httpMessage += + F("

ArduinoLog

Copyright© 2017,2018 Thijs Elenbaas, MrRobot62, rahuldeo2047, NOX73, " + "dhylands, Josha blemasle, mfalkvidd"); + httpMessage += mitLicense; + #if HASP_USE_SYSLOG > 0 + // Replaced with WiFiUDP client + // httpMessage += F("

Syslog

Copyright© 2016 Martin Sloup"); + // httpMessage += mitLicense; + #endif + #if HASP_USE_QRCODE > 0 + httpMessage += F("

QR Code generator

Copyright© Project Nayuki"); + httpMessage += mitLicense; + #endif + httpMessage += F("

AceButton

Copyright© 2018 Brian T. Park"); + httpMessage += mitLicense; + */ + httpMessage += "
"; httpMessage += FPSTR(MAIN_MENU_BUTTON); webSendHeader(haspDevice.get_hostname(), httpMessage.length(), false); @@ -913,9 +916,10 @@ static int handleFileRead(String path) if(path.endsWith("/")) { path += F("index.htm"); } - + String style_css = F("/style.css"); - bool is_style_css = (path == style_css); + String script_js = F("/script.js"); + bool is_cached = (path == style_css) || (path == script_js); String pathWithGz = path + F(".gz"); if(HASP_FS.exists(pathWithGz) || HASP_FS.exists(path)) { @@ -948,8 +952,8 @@ static int handleFileRead(String path) } else { - // Only styles.css can be cached - if(is_style_css) webSendCacheHeader(file.size(), 3600); + // script.js and styles.css can be cached + if(is_cached) webSendCacheHeader(file.size(), 3600); // Stream other files directly from filesystem webServer.streamFile(file, contentType); @@ -963,7 +967,7 @@ static int handleFileRead(String path) if(path == F("/edit.htm")) { size_t size = EDIT_HTM_GZ_END - EDIT_HTM_GZ_START; webServer.sendHeader(F("Content-Encoding"), F("gzip")); - return webSendCached(200, PSTR("text/html"), (const char*)EDIT_HTM_GZ_START, size); // OK + return webSendCached(200, PSTR("text/html"), (const char*)EDIT_HTM_GZ_START, size); } #endif @@ -971,7 +975,15 @@ static int handleFileRead(String path) if(path == style_css) { size_t size = STYLE_CSS_GZ_END - STYLE_CSS_GZ_START; webServer.sendHeader(F("Content-Encoding"), F("gzip")); - return webSendCached(200, PSTR("text/css"), (const char*)STYLE_CSS_GZ_START, size); // OK + return webSendCached(200, PSTR("text/css"), (const char*)STYLE_CSS_GZ_START, size); + } +#endif + +#if defined(ARDUINO_ARCH_ESP32) && defined(CONFIG_IDF_TARGET_ESP32) + if(path == script_js) { + size_t size = SCRIPT_JS_GZ_END - SCRIPT_JS_GZ_START; + webServer.sendHeader(F("Content-Encoding"), F("gzip")); + return webSendCached(200, PSTR("text/javascript"), (const char*)SCRIPT_JS_GZ_START, size); } #endif @@ -2350,14 +2362,46 @@ static void webSendCssVars() webSendCached(200, PSTR("text/css"), HTTP_CSS.c_str(), HTTP_CSS.length()); } +/* // Do not keep JS in memory because it is cached in the browser static void webSendJavascript() { + // Refresh screenshot String javascript = F("function aref(t){setTimeout(function() {ref('');}, t*1000)}" "function ref(a){ var t=new " - "Date().getTime();document.getElementById('bmp').src='?a='+a+'&q='+t;return false;}"); + "Date().getTime();document.getElementById('bmp').src='?a='+a+'&q='+t;return false;};"); + // This string can be gzipped: + javascript += + "function about(){document.getElementById('doc').innerHTML='

" D_MANUFACTURER + "

Copyright© 2019-2021 Francis Van Roie
MIT License

" + "

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and " + "associated documentation files(the \"Software\"), to deal in the Software without restriction, including " + "without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and / or sell " + "copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the " + "following conditions:

" + "

The above copyright notice and this permission notice shall be included in all copies or substantial " + "portions of the Software.

THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, " + "EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR " + "PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, " + "DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN " + "CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.


" + "

Based on the previous work of the following open source developers:

" + "

HASwitchPlate

Copyright© 2019 Allen Derusha allen@derusha.org
MIT License

" + "

LVGL

Copyright© 2021 LVGL Kft
MIT License

" + "

zi Font Engine

Copyright© 2020-2021 Francis Van Roie
MIT License

" + "

TFT_eSPI Library

Copyright© 2020 Bodmer (https://github.com/Bodmer) All rights " + "reserved.
FreeBSD License

" + "

includes parts from the Adafruit_GFX library
Copyright© 2012 Adafruit Industries. All " + "rights reserved
BSD License

" + "

ArduinoJson

Copyright© 2014-2021 Benoit BLANCHON
MIT License

" + "

PubSubClient

Copyright© 2008-2015 Nicholas O'Leary
MIT License

" + "

ArduinoLog

Copyright© 2017,2018 Thijs Elenbaas, MrRobot62, rahuldeo2047, NOX73, dhylands, " + "Josha blemasle, mfalkvidd
MIT License

" + "

QR Code generator

Copyright© Project Nayuki
MIT License

" + "

AceButton

Copyright© 2018 Brian T. Park
MIT License

';}"; webSendCached(200, PSTR("text/javascript"), javascript.c_str(), javascript.length()); } +*/ //////////////////////////////////////////////////////////////////////////////////////////////////// static inline void webStartConfigPortal() @@ -2390,7 +2434,7 @@ void httpSetup() // Shared pages between STA and AP webServer.on(F("/about"), webHandleAbout); webServer.on(F("/vars.css"), webSendCssVars); - webServer.on(F("/js"), webSendJavascript); + // webServer.on(F("/js"), webSendJavascript); webServer.onNotFound(httpHandleNotFound); #if HASP_USE_WIFI > 0 diff --git a/user_setups/esp32/_esp32.ini b/user_setups/esp32/_esp32.ini index 8fa46ad8..7c764df6 100644 --- a/user_setups/esp32/_esp32.ini +++ b/user_setups/esp32/_esp32.ini @@ -92,6 +92,7 @@ platform = espressif32@^3.3.2 board_build.embed_files = data/edit.htm.gz data/style.css.gz + data/script.js.gz board_build.filesystem = littlefs ; ----- crash reporter monitor_filters = esp32_exception_decoder