Merge pull request #1535 from korhojoa/zopfli

Repackage OTA html file with zopfli
This commit is contained in:
Daniel Öster 2025-09-22 15:16:21 +03:00 committed by GitHub
commit a8d74f5885
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 25 additions and 2 deletions

File diff suppressed because one or more lines are too long

View file

@ -3,6 +3,6 @@
#include <Arduino.h>
extern const uint8_t ELEGANT_HTML[11640];
extern const uint8_t ELEGANT_HTML[10615];
#endif

View file

@ -0,0 +1,23 @@
import json
from pathlib import Path
libpath = Path("ayushsharma82-ElegantOTA")
gzipped=libpath/"CurrentPlainHTML.txt.gz"
header=libpath/"src/elop.h"
cpp=libpath/"src/elop.cpp"
if not gzipped.exists():
print(f"Please create {gzipped.resolve()} to replace OTA file.")
print(f"Example: zopfli -v --i10000 {libpath.resolve()}/CurrentPlainHTML.txt")
raise SystemExit(1)
gzipbytes=gzipped.read_bytes()
intlist = [int(one) for one in gzipbytes]
content = json.dumps(intlist).replace("[","{").replace("]","}").replace(" ", "")
headertext = header.read_text()
header.write_text(headertext[:1+headertext.find("[")]+str(len(gzipbytes))+headertext[headertext.find("]"):])
cpptext = cpp.read_text()
first_bracket = cpptext.find("[")
second_bracket = cpptext.find("]")
corrected_bytes = cpptext[:1+first_bracket]+str(len(gzipbytes))+cpptext[second_bracket:]
cppout = corrected_bytes[:corrected_bytes.find("{")]+content+corrected_bytes[corrected_bytes.find(";"):]+"\n"
cpp.write_text(cppout)
print("File content updated from", gzipped.resolve())
print("Bytes fixed:", cpptext[1+first_bracket:second_bracket], "to", len(gzipbytes))