added icon
This commit is contained in:
parent
dd14b7ba96
commit
2f3eeebe72
@ -26,7 +26,8 @@ public class HttpServerApp {
|
||||
server.createContext("/transmissions", exchange -> {
|
||||
try {
|
||||
setCors(exchange);
|
||||
if (!checkApiKey(exchange)) return;
|
||||
if (!checkApiKey(exchange))
|
||||
return;
|
||||
|
||||
URI uri = exchange.getRequestURI();
|
||||
String query = uri.getQuery();
|
||||
@ -58,7 +59,8 @@ public class HttpServerApp {
|
||||
server.createContext("/search", exchange -> {
|
||||
try {
|
||||
setCors(exchange);
|
||||
if (!checkApiKey(exchange)) return;
|
||||
if (!checkApiKey(exchange))
|
||||
return;
|
||||
|
||||
URI uri = exchange.getRequestURI();
|
||||
String query = null;
|
||||
@ -82,7 +84,8 @@ public class HttpServerApp {
|
||||
server.createContext("/refresh", exchange -> {
|
||||
try {
|
||||
setCors(exchange);
|
||||
if (!checkApiKey(exchange)) return;
|
||||
if (!checkApiKey(exchange))
|
||||
return;
|
||||
|
||||
if ("GET".equalsIgnoreCase(exchange.getRequestMethod())) {
|
||||
// přečti volitelné datum z query stringu
|
||||
@ -98,15 +101,15 @@ public class HttpServerApp {
|
||||
}
|
||||
|
||||
// pokud není zadané, použij dnešní den
|
||||
String dateStr = (dateParam != null && !dateParam.isBlank())
|
||||
? dateParam
|
||||
String dateStr = (dateParam != null && !dateParam.isBlank()) ? dateParam
|
||||
: java.time.LocalDate.now().toString();
|
||||
|
||||
// načti data pro konkrétní den
|
||||
System.out.println("🔄 Obnovuji data pro den: " + dateStr);
|
||||
service.reloadDayAsync(dateStr);
|
||||
|
||||
respondJson(exchange, "{\"status\":\"ok\",\"message\":\"Data pro den " + dateStr + " se obnovují.\"}");
|
||||
respondJson(exchange,
|
||||
"{\"status\":\"ok\",\"message\":\"Data pro den " + dateStr + " se obnovují.\"}");
|
||||
} else {
|
||||
exchange.sendResponseHeaders(405, -1);
|
||||
}
|
||||
@ -119,8 +122,24 @@ public class HttpServerApp {
|
||||
server.createContext("/", exchange -> {
|
||||
try {
|
||||
setCors(exchange);
|
||||
if (!checkApiKey(exchange)) return;
|
||||
String path = exchange.getRequestURI().getPath();
|
||||
if (path.equals("/icon.png")) {
|
||||
byte[] data = readResourceAsBytes("/icon.png");
|
||||
if (data == null) {
|
||||
sendError(exchange, 404, "index.html not found in resources");
|
||||
return;
|
||||
}
|
||||
exchange.getResponseHeaders().set("Content-Type", "image/png");
|
||||
exchange.sendResponseHeaders(200, data.length);
|
||||
try (OutputStream os = exchange.getResponseBody()) {
|
||||
os.write(data);
|
||||
os.flush();
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (!checkApiKey(exchange))
|
||||
return;
|
||||
if ("/".equals(path) || path.isEmpty() || path.equals("/index.html")) {
|
||||
String html = readResource("/index.html");
|
||||
if (html == null) {
|
||||
@ -132,6 +151,7 @@ public class HttpServerApp {
|
||||
exchange.sendResponseHeaders(200, bytes.length);
|
||||
try (OutputStream os = exchange.getResponseBody()) {
|
||||
os.write(bytes);
|
||||
os.flush();
|
||||
}
|
||||
} else {
|
||||
sendError(exchange, 404, "Not found");
|
||||
@ -150,6 +170,23 @@ public class HttpServerApp {
|
||||
System.out.println(" ➜ / (web UI)");
|
||||
}
|
||||
|
||||
private static byte[] readResourceAsBytes(String string) {
|
||||
try (InputStream is = HttpServerApp.class.getResourceAsStream(string)) {
|
||||
if (is == null)
|
||||
return null;
|
||||
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
|
||||
byte[] data = new byte[16384];
|
||||
int nRead;
|
||||
while ((nRead = is.read(data, 0, data.length)) != -1) {
|
||||
buffer.write(data, 0, nRead);
|
||||
}
|
||||
return buffer.toByteArray();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
// ======= API Key ochrana =======
|
||||
private static boolean checkApiKey(HttpExchange exchange) throws IOException {
|
||||
String query = exchange.getRequestURI().getQuery(); // např. apiKey=xxxx
|
||||
@ -214,7 +251,8 @@ public class HttpServerApp {
|
||||
// ======= Načtení resource =======
|
||||
private static String readResource(String resourcePath) {
|
||||
try (InputStream is = HttpServerApp.class.getResourceAsStream(resourcePath)) {
|
||||
if (is == null) return null;
|
||||
if (is == null)
|
||||
return null;
|
||||
try (BufferedReader br = new BufferedReader(new InputStreamReader(is, StandardCharsets.UTF_8))) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
String line;
|
||||
|
||||
BIN
src/main/resources/icon.png
Normal file
BIN
src/main/resources/icon.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 17 KiB |
@ -2,6 +2,7 @@
|
||||
<html lang="cs">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<link rel="icon" href="icon.png">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<title>TVCOM Přenosy</title>
|
||||
<style>
|
||||
@ -74,7 +75,7 @@ input, select, button {
|
||||
margin-top: 30px;
|
||||
}
|
||||
|
||||
@media (max-width: 500px) {
|
||||
@media ( max-width : 500px) {
|
||||
.card img {
|
||||
height: 120px;
|
||||
}
|
||||
@ -82,21 +83,20 @@ input, select, button {
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<h1>📺 TVCOM Přenosy</h1>
|
||||
<h1>📺 TVCOM Přenosy</h1>
|
||||
|
||||
<div class="filters">
|
||||
<input id="search" type="text" placeholder="Hledat přenos..." />
|
||||
<input id="datePicker" type="date" />
|
||||
<select id="sportFilter">
|
||||
<div class="filters">
|
||||
<input id="search" type="text" placeholder="Hledat přenos..." /> <input
|
||||
id="datePicker" type="date" /> <select id="sportFilter">
|
||||
<option value="">Všechny sporty</option>
|
||||
</select>
|
||||
<button id="refreshBtn">♻️ Obnovit data</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="loading">Načítám data...</div>
|
||||
<div id="list" class="grid" style="display: none"></div>
|
||||
<div id="loading">Načítám data...</div>
|
||||
<div id="list" class="grid" style="display: none"></div>
|
||||
|
||||
<script>
|
||||
<script>
|
||||
const API_BASE = "";
|
||||
const urlParams = new URLSearchParams(window.location.search);
|
||||
const apiKey = urlParams.get('apiKey');
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user