按 GID 查找画廊下载文件
This commit is contained in:
parent
ce21d8724e
commit
ad1d96290c
@ -69,33 +69,18 @@ public class MultiThreadedHTTPServer {
|
||||
}
|
||||
else {
|
||||
String filePath = "/root/gallery/gallery";
|
||||
String gid = paramMap.get("gid");
|
||||
file = gid == null ? null : findGalleryZipByGid(new File(filePath), gid);
|
||||
|
||||
//兼容没有gid参数的旧下载链接,再尝试按链接中的文件名查找
|
||||
if(file == null){
|
||||
String path = URLDecoder.decode(requestParts[1].split("\\?")[0], StandardCharsets.UTF_8);
|
||||
if(!path.contains(".")){
|
||||
file = new File("/root/abc");
|
||||
}else {
|
||||
if(path.contains(".")){
|
||||
String name = path.substring(0, path.lastIndexOf('.'));
|
||||
name = filePath + name + "/" + name + ".zip";
|
||||
file = new File(name);
|
||||
|
||||
//该文件不存在
|
||||
if(!file.isFile()){
|
||||
String gid = paramMap.get("gid");
|
||||
|
||||
//文件不存在的情况下gid也不存在,直接404
|
||||
if(gid == null)
|
||||
}else{
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -140,6 +125,28 @@ public class MultiThreadedHTTPServer {
|
||||
}
|
||||
}
|
||||
|
||||
private static File findGalleryZipByGid(File galleryRoot, String gid){
|
||||
File[] galleryDirectories = galleryRoot.listFiles(File::isDirectory);
|
||||
if(galleryDirectories == null)
|
||||
return null;
|
||||
|
||||
String marker = "[" + gid;
|
||||
for(File galleryDirectory : galleryDirectories){
|
||||
String name = galleryDirectory.getName();
|
||||
int markerIndex = name.lastIndexOf(marker);
|
||||
if(markerIndex < 0)
|
||||
continue;
|
||||
int suffixIndex = markerIndex + marker.length();
|
||||
if(suffixIndex >= name.length() || (name.charAt(suffixIndex) != ']' && name.charAt(suffixIndex) != '-'))
|
||||
continue;
|
||||
|
||||
File zip = new File(galleryDirectory, name + ".zip");
|
||||
if(zip.isFile())
|
||||
return zip;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static Map<String, String> parseRequestLine(String requestLine) {
|
||||
Map<String, String> queryParams = new HashMap<>();
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user