当对应文件找不到的时候,尝试通过gid查找文件

This commit is contained in:
chuzhongzai 2023-09-05 20:04:36 +08:00
parent 8c0ca78dc6
commit fb5ff43364

View File

@ -69,9 +69,29 @@ public class MultiThreadedHTTPServer {
file = new File("/root/abc"); file = new File("/root/abc");
}else { }else {
String name = path.substring(0, path.lastIndexOf('.')); String name = path.substring(0, path.lastIndexOf('.'));
System.out.println(name); name = filePath + name + "/" + name + ".zip";
filePath += (name + "/" + name + ".zip"); file = new File(name);
file = new File(filePath);
//该文件不存在
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{ else{