Добавить upload и стабильную прошивку 1.2

This commit is contained in:
AidarKC
2026-10-25 20:08:02 +03:00
parent 9fffe5fe36
commit e407ab79e3
4 changed files with 19 additions and 14 deletions
@@ -441,7 +441,7 @@ 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.equals("/firmware/manifest.json")){byte[] bytes="{\"current\":\"1.2\",\"stable\":{\"version\":\"1.2\",\"file\":\"breathmonitor-v1.2.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";