mirror of
https://github.com/GravitLauncher/Launcher
synced 2024-11-15 03:31:15 +03:00
[FEATURE] Настройка включения/выключения отображения скрытых файлов при скачке
This commit is contained in:
parent
856fe8797d
commit
a09a7c8cf6
3 changed files with 9 additions and 6 deletions
|
@ -254,6 +254,7 @@ public static class NettyConfig {
|
|||
public boolean fileServerEnabled;
|
||||
public boolean sendExceptionEnabled;
|
||||
public boolean ipForwarding;
|
||||
public boolean showHiddenFiles;
|
||||
public String launcherURL;
|
||||
public String downloadURL;
|
||||
public String launcherEXEURL;
|
||||
|
|
|
@ -63,7 +63,7 @@ public void initChannel(SocketChannel ch) {
|
|||
pipeline.addLast(new WebSocketServerCompressionHandler());
|
||||
pipeline.addLast(new WebSocketServerProtocolHandler(WEBSOCKET_PATH, null, true));
|
||||
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));
|
||||
pipelineHook.hook(context, ch);
|
||||
}
|
||||
|
|
|
@ -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 final Path base;
|
||||
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.fullOut = fullOut;
|
||||
this.showHiddenFiles = showHiddenFiles;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -92,7 +94,7 @@ public void channelRead0(ChannelHandlerContext ctx, FullHttpRequest request) thr
|
|||
}
|
||||
|
||||
File file = base.resolve(path).toFile();
|
||||
if (file.isHidden() || !file.exists()) {
|
||||
if ((file.isHidden() && !showHiddenFiles) || !file.exists()) {
|
||||
sendError(ctx, NOT_FOUND);
|
||||
return;
|
||||
}
|
||||
|
@ -100,7 +102,7 @@ public void channelRead0(ChannelHandlerContext ctx, FullHttpRequest request) thr
|
|||
if (file.isDirectory()) {
|
||||
if (fullOut) {
|
||||
if (uri.endsWith("/")) {
|
||||
sendListing(ctx, file, uri);
|
||||
sendListing(ctx, file, uri, showHiddenFiles);
|
||||
} else {
|
||||
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 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);
|
||||
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");
|
||||
|
||||
for (File f : dir.listFiles()) {
|
||||
if (f.isHidden() || !f.canRead()) {
|
||||
if (( f.isHidden() && !showHidden) || !f.canRead()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue