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