Обновить меню и OTA BreathMonitor

This commit is contained in:
AidarKC
2026-10-25 14:30:10 +03:00
parent d5a37d3009
commit 16015cc45f
5 changed files with 107 additions and 68 deletions
@@ -441,6 +441,8 @@ public final class BreathServer {
}
private static String quoted(String s){return "\""+s.replace("\\","\\\\").replace("\"","\\\"")+"\"";}
private static void serveWeb(HttpExchange x,String path,String method) throws Exception {
if(path.equals("/firmware/manifest.json")){byte[] bytes="{\"current\":\"1.1\",\"stable\":{\"version\":\"1.1\",\"file\":\"breathmonitor-v1.1.bin\"},\"test\":{\"version\":\"1.2\",\"file\":\"breathmonitor-v1.2.bin\"}}".getBytes(StandardCharsets.UTF_8);if(method.equals("HEAD")){x.getResponseHeaders().set("Content-Type","application/json; charset=utf-8");x.sendResponseHeaders(200,-1);}else send(x,200,"application/json; charset=utf-8",bytes);return;}
if(path.startsWith("/firmware/")){String resource=path.substring("/firmware/".length());if(!resource.matches("breathmonitor-v1\\.(1|2)\\.bin"))throw new HttpError(404,"Firmware not found");try(InputStream in=BreathServer.class.getResourceAsStream("/firmware/"+resource)){if(in==null)throw new HttpError(404,"Firmware not installed");byte[] bytes=in.readAllBytes();if(method.equals("HEAD")){x.getResponseHeaders().set("Content-Type","application/octet-stream");x.sendResponseHeaders(200,-1);}else send(x,200,"application/octet-stream",bytes);return;}}
String name = switch(path){case "/","/index.html" -> "index.html";
case "/app.js" -> "app.js";case "/style.css" -> "style.css";
default -> null;};