From fb5ff433648260ee3bcb4898a0379666d4ed7d2a Mon Sep 17 00:00:00 2001 From: chuzhongzai Date: Tue, 5 Sep 2023 20:04:36 +0800 Subject: [PATCH] =?UTF-8?q?=E5=BD=93=E5=AF=B9=E5=BA=94=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E6=89=BE=E4=B8=8D=E5=88=B0=E7=9A=84=E6=97=B6=E5=80=99=EF=BC=8C?= =?UTF-8?q?=E5=B0=9D=E8=AF=95=E9=80=9A=E8=BF=87gid=E6=9F=A5=E6=89=BE?= =?UTF-8?q?=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/lion/MultiThreadedHTTPServer.java | 26 ++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/src/main/java/lion/MultiThreadedHTTPServer.java b/src/main/java/lion/MultiThreadedHTTPServer.java index fcb0b40..a53711e 100644 --- a/src/main/java/lion/MultiThreadedHTTPServer.java +++ b/src/main/java/lion/MultiThreadedHTTPServer.java @@ -69,9 +69,29 @@ public class MultiThreadedHTTPServer { file = new File("/root/abc"); }else { String name = path.substring(0, path.lastIndexOf('.')); - System.out.println(name); - filePath += (name + "/" + name + ".zip"); - file = new File(filePath); + name = filePath + name + "/" + name + ".zip"; + file = new File(name); + + //该文件不存在 + if(!file.isFile()){ + String gid = paramMap.get("gid"); + + //文件不存在的情况下gid也不存在,直接404 + if(gid == null) + file = new File("/root/abc"); + + //gid存在的情况下尝试查找对应的文件 + else { + File[] galleryDirectories = (new File(filePath)).listFiles(); + + assert galleryDirectories != null; + for (File galleryDirectory : galleryDirectories) + if (galleryDirectory.getName().contains(gid)) { + file = new File(galleryDirectory.getAbsolutePath(), galleryDirectory.getName() + ".zip"); + break; + } + } + } } } else{