From 58f5c30897596a1139c579704ea9f92b62bc9bf9 Mon Sep 17 00:00:00 2001 From: ulrich Date: Sat, 26 Oct 2024 12:32:05 +0000 Subject: [PATCH] fixFileName hinzugefuegt --- src/de/uhilger/neon/image/ImageFilter.java | 39 +++++++++++++++++++++++++++------------ 1 files changed, 27 insertions(+), 12 deletions(-) diff --git a/src/de/uhilger/neon/image/ImageFilter.java b/src/de/uhilger/neon/image/ImageFilter.java index 1f02274..4ef14cd 100644 --- a/src/de/uhilger/neon/image/ImageFilter.java +++ b/src/de/uhilger/neon/image/ImageFilter.java @@ -20,6 +20,7 @@ import com.sun.net.httpserver.Filter; import com.sun.net.httpserver.HttpExchange; import de.uhilger.neon.FileServer; +import de.uhilger.neon.HttpHelper; import java.io.IOException; /** @@ -60,19 +61,33 @@ @Override public void doFilter(HttpExchange exchange, Chain chain) throws IOException { + /* + Regex fuer Bilder + .+\.jpg|.+\.jpeg|.+\.png + (Testen z.B. auf https://regexr.com/) + */ + String pattern = (String) exchange.getHttpContext().getAttributes() + .getOrDefault("imageFilterPattern", ".+\\.jpg|.+\\.jpeg|.+\\.png"); String uriStr = exchange.getRequestURI().toString(); - //String fName = new HttpHelper().getFileName(exchange); - String fName = exchange - .getRequestURI() - .getPath() - .substring(exchange - .getHttpContext() - .getPath() - .length()); - ImageWorker worker = new ImageWorker(); - worker.createImages(exchange.getHttpContext().getAttributes().get(FileServer.ATTR_FILE_BASE).toString(), - fName, uriStr); - chain.doFilter(exchange); + try { + String fName = new HttpHelper().getFileName(exchange); + if(uriStr.toLowerCase().matches(pattern)) { + String fileBase = (String) exchange.getHttpContext().getAttributes() + .get(FileServer.ATTR_FILE_BASE); + String fileName = exchange + .getRequestURI() + .getPath() + .substring(exchange + .getHttpContext() + .getPath() + .length()); + new ImageWorker().createImages(fileBase, fileName, uriStr); + } + } catch(IllegalArgumentException ex) { + // ungueltiger Dateiname, keine Transformation noetig, tue nichts + } finally { + chain.doFilter(exchange); + } } @Override -- Gitblit v1.9.3