[FEATURE] Настройка включения/выключения отображения скрытых файлов при скачке

This commit is contained in:
Gravit 2019-08-29 16:19:33 +07:00
parent 856fe8797d
commit a09a7c8cf6
No known key found for this signature in database
GPG key ID: 061981E1E85D3216
3 changed files with 9 additions and 6 deletions

View file

@ -254,6 +254,7 @@ public static class NettyConfig {
public boolean fileServerEnabled; public boolean fileServerEnabled;
public boolean sendExceptionEnabled; public boolean sendExceptionEnabled;
public boolean ipForwarding; public boolean ipForwarding;
public boolean showHiddenFiles;
public String launcherURL; public String launcherURL;
public String downloadURL; public String downloadURL;
public String launcherEXEURL; public String launcherEXEURL;

View file

@ -63,7 +63,7 @@ public void initChannel(SocketChannel ch) {
pipeline.addLast(new WebSocketServerCompressionHandler()); pipeline.addLast(new WebSocketServerCompressionHandler());
pipeline.addLast(new WebSocketServerProtocolHandler(WEBSOCKET_PATH, null, true)); pipeline.addLast(new WebSocketServerProtocolHandler(WEBSOCKET_PATH, null, true));
if (server.config.netty.fileServerEnabled) if (server.config.netty.fileServerEnabled)
pipeline.addLast(new FileServerHandler(server.updatesDir, true)); pipeline.addLast(new FileServerHandler(server.updatesDir, true, config.showHiddenFiles));
pipeline.addLast(new WebSocketFrameHandler(context, server, service)); pipeline.addLast(new WebSocketFrameHandler(context, server, service));
pipelineHook.hook(context, ch); pipelineHook.hook(context, ch);
} }

View file

@ -58,10 +58,12 @@ public class FileServerHandler extends SimpleChannelInboundHandler<FullHttpReque
private static final boolean OLD_ALGO = Boolean.parseBoolean(System.getProperty("launcher.fileserver.oldalgo", "true")); private static final boolean OLD_ALGO = Boolean.parseBoolean(System.getProperty("launcher.fileserver.oldalgo", "true"));
private final Path base; private final Path base;
private final boolean fullOut; private final boolean fullOut;
private final boolean showHiddenFiles;
public FileServerHandler(Path base, boolean fullOut) { public FileServerHandler(Path base, boolean fullOut, boolean showHiddenFiles) {
this.base = base; this.base = base;
this.fullOut = fullOut; this.fullOut = fullOut;
this.showHiddenFiles = showHiddenFiles;
} }
@Override @Override
@ -92,7 +94,7 @@ public void channelRead0(ChannelHandlerContext ctx, FullHttpRequest request) thr
} }
File file = base.resolve(path).toFile(); File file = base.resolve(path).toFile();
if (file.isHidden() || !file.exists()) { if ((file.isHidden() && !showHiddenFiles) || !file.exists()) {
sendError(ctx, NOT_FOUND); sendError(ctx, NOT_FOUND);
return; return;
} }
@ -100,7 +102,7 @@ public void channelRead0(ChannelHandlerContext ctx, FullHttpRequest request) thr
if (file.isDirectory()) { if (file.isDirectory()) {
if (fullOut) { if (fullOut) {
if (uri.endsWith("/")) { if (uri.endsWith("/")) {
sendListing(ctx, file, uri); sendListing(ctx, file, uri, showHiddenFiles);
} else { } else {
sendRedirect(ctx, uri + '/'); sendRedirect(ctx, uri + '/');
} }
@ -182,7 +184,7 @@ public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) {
private static final Pattern ALLOWED_FILE_NAME = Pattern.compile("[^-\\._]?[^<>&\\\"]*"); private static final Pattern ALLOWED_FILE_NAME = Pattern.compile("[^-\\._]?[^<>&\\\"]*");
private static void sendListing(ChannelHandlerContext ctx, File dir, String dirPath) { private static void sendListing(ChannelHandlerContext ctx, File dir, String dirPath, boolean showHidden) {
FullHttpResponse response = new DefaultFullHttpResponse(HTTP_1_1, OK); FullHttpResponse response = new DefaultFullHttpResponse(HTTP_1_1, OK);
response.headers().set(HttpHeaderNames.CONTENT_TYPE, "text/html; charset=UTF-8"); response.headers().set(HttpHeaderNames.CONTENT_TYPE, "text/html; charset=UTF-8");
@ -201,7 +203,7 @@ private static void sendListing(ChannelHandlerContext ctx, File dir, String dirP
.append("<li><a href=\"../\">..</a></li>\r\n"); .append("<li><a href=\"../\">..</a></li>\r\n");
for (File f : dir.listFiles()) { for (File f : dir.listFiles()) {
if (f.isHidden() || !f.canRead()) { if (( f.isHidden() && !showHidden) || !f.canRead()) {
continue; continue;
} }