Skip to content

Commit 02195a7

Browse files
committed
Enable support for compressed files
1 parent ce496a1 commit 02195a7

34 files changed

+8078
-657
lines changed

gui

platformio.ini

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,7 @@ board_build.partitions = ${common.build_partitions}
117117
# ; use a special branch
118118
# framework-arduinoespressif32 @ https://github.com/marcovannoord/arduino-esp32.git#idf-release/v4.0
119119
# platformio/framework-arduinoespressif32 @ ~3.10006.0
120-
monitor_flags =
121-
--filter=esp32_exception_decoder
120+
monitor_filters = esp32_exception_decoder
122121

123122
[env:openevse_nodemcu-32s]
124123
board = nodemcu-32s
@@ -265,6 +264,8 @@ build_flags =
265264
-D TX2=32
266265
board_build.extra_flags = "-DARDUINO_ESP32_GATEWAY=\'E\'"
267266
upload_speed = 921600
267+
monitor_flags =
268+
--filter=esp32_exception_decoder
268269

269270
[env:openevse_esp32-heltec-wifi-lora-v2]
270271
board = heltec_wifi_lora_32_V2

scripts/extra_script.py

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ def make_static(env, target, source):
7070

7171
out_files = []
7272
for file in listdir(dist_dir):
73-
if isfile(join(dist_dir, file)):
73+
if isfile(join(dist_dir, file)) and (file.endswith(".gz") or file.endswith(".png") or file.endswith(".jpg")):
7474
out_files.append(file)
7575

7676
# Sort files to make sure the order is constant
@@ -84,24 +84,27 @@ def make_static(env, target, source):
8484
output += "StaticFile staticFiles[] = {\n"
8585

8686
for out_file in out_files:
87-
filetype = "TEXT"
88-
if out_file.endswith(".css"):
87+
filetype = None
88+
compress = True
89+
if out_file.endswith(".css.gz"):
8990
filetype = "CSS"
90-
elif out_file.endswith(".js"):
91+
elif out_file.endswith(".js.gz"):
9192
filetype = "JS"
92-
elif out_file.endswith(".htm") or out_file.endswith(".html"):
93+
elif out_file.endswith(".htm.gz") or out_file.endswith(".html.gz"):
9394
filetype = "HTML"
9495
elif out_file.endswith(".jpg"):
9596
filetype = "JPEG"
97+
compress = False
9698
elif out_file.endswith(".png"):
9799
filetype = "PNG"
98-
elif out_file.endswith(".svg"):
100+
compress = False
101+
elif out_file.endswith(".svg.gz"):
99102
filetype = "SVG"
100-
elif out_file.endswith(".json"):
103+
elif out_file.endswith(".json.gz"):
101104
filetype = "JSON"
102105

103106
c_name = get_c_name(out_file)
104-
output += " { \"/"+out_file+"\", CONTENT_"+c_name+", sizeof(CONTENT_"+c_name+") - 1, _CONTENT_TYPE_"+filetype+", CONTENT_"+c_name+"_ETAG },\n"
107+
output += " { \"/"+out_file.replace(".gz","")+"\", CONTENT_"+c_name+", sizeof(CONTENT_"+c_name+") - 1, _CONTENT_TYPE_"+filetype+", CONTENT_"+c_name+"_ETAG, "+("true" if compress else "false")+" },\n"
105108

106109
output += "};\n"
107110

@@ -115,7 +118,7 @@ def process_html_app(source, dest, env):
115118
web_server_static = join("$BUILDSRC_DIR", "web_server_static.cpp.o")
116119

117120
for file in sorted(listdir(source)):
118-
if isfile(join(source, file)):
121+
if isfile(join(source, file)) and (file.endswith(".gz") or file.endswith(".png") or file.endswith(".jpg")):
119122
data_file = join(source, file)
120123
header_file = join(dest, "web_server."+file+".h")
121124
env.Command(header_file, data_file, data_to_header)

src/web_server_static.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ struct StaticFile
2020
size_t length;
2121
const char *type;
2222
const char *etag;
23+
bool compressed;
2324
};
2425

2526
#include "web_static/web_server_static_files.h"
@@ -100,6 +101,9 @@ bool web_static_handle(MongooseHttpServerRequest *request)
100101
if (enableCors) {
101102
response->addHeader(F("Access-Control-Allow-Origin"), F("*"));
102103
}
104+
if(file->compressed) {
105+
response->addHeader(F("Content-Encoding"), F("gzip"));
106+
}
103107

104108
response->addHeader("Etag", file->etag);
105109
response->setContent((const uint8_t *)file->data, file->length);

src/web_static/web_server.assets.js.h

Lines changed: 0 additions & 3 deletions
This file was deleted.

0 commit comments

Comments
 (0)