图片预览加入gif;禁止非反代ip下载文件;优化下载进度判断
This commit is contained in:
parent
b1610d136b
commit
c2c5c50a48
2
pom.xml
2
pom.xml
@ -48,7 +48,7 @@
|
||||
<dependency>
|
||||
<groupId>cn.hutool</groupId>
|
||||
<artifactId>hutool-all</artifactId>
|
||||
<version>5.8.16</version>
|
||||
<version>5.8.18</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
|
||||
@ -3,6 +3,7 @@ package lion;
|
||||
import java.io.*;
|
||||
import java.net.ServerSocket;
|
||||
import java.net.Socket;
|
||||
import java.net.SocketException;
|
||||
import java.net.URLDecoder;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Arrays;
|
||||
@ -21,9 +22,16 @@ public class MultiThreadedHTTPServer {
|
||||
System.out.println("Server listening on port " + PORT);
|
||||
while (true) {
|
||||
Socket clientSocket = serverSocket.accept();
|
||||
System.out.println("Client connected: " + clientSocket.getInetAddress().getHostAddress());
|
||||
// 线程池处理下载请求
|
||||
threadPool.submit(() -> handleClientRequest(clientSocket));
|
||||
String ip = clientSocket.getInetAddress().getHostAddress();
|
||||
if(ip.equals("100.42.234.138")){
|
||||
System.out.println("Client connected: " + ip);
|
||||
// 线程池处理下载请求
|
||||
threadPool.submit(() -> handleClientRequest(clientSocket));
|
||||
}else{
|
||||
System.out.println("unknown ip: " + ip);
|
||||
clientSocket.close();
|
||||
}
|
||||
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
@ -104,6 +112,8 @@ public class MultiThreadedHTTPServer {
|
||||
responseStream.write(buffer, 0, bytesRead);
|
||||
bytesRemaining -= bytesRead;
|
||||
}
|
||||
}catch (SocketException ignore){
|
||||
|
||||
}
|
||||
|
||||
// Close the response output stream
|
||||
|
||||
@ -50,7 +50,7 @@ public class DeliveryService {
|
||||
return ErrorCode.FILE_NOT_FOUND;
|
||||
|
||||
singleThreadPool.submit(() -> {
|
||||
try(SocketChannel socketChannel = SocketChannel.open(new InetSocketAddress("194.36.27.28", port));
|
||||
try(SocketChannel socketChannel = SocketChannel.open(new InetSocketAddress("100.42.234.138", port));
|
||||
FileChannel fileChannel = FileChannel.open(file.toPath(), StandardOpenOption.READ)) {
|
||||
ByteBuffer buffer = ByteBuffer.allocate(1024);
|
||||
while (fileChannel.read(buffer)!=-1){
|
||||
@ -86,7 +86,7 @@ public class DeliveryService {
|
||||
if(!directory.isDirectory())
|
||||
return ErrorCode.FILE_NOT_FOUND;
|
||||
ArrayList<String> pageList = new ArrayList<>();
|
||||
File[] files = directory.listFiles(((dir, name1) -> name1.contains(".webp") && !name1.equals("thumbnail.webp")));
|
||||
File[] files = directory.listFiles(((dir, name1) -> !name1.equals("galleryinfo.txt") && !name1.equals("thumbnail.webp")));
|
||||
|
||||
if(files == null)
|
||||
return ErrorCode.FILE_NOT_FOUND;
|
||||
|
||||
@ -104,7 +104,7 @@ public class DownloadCheckService {
|
||||
continue;
|
||||
}
|
||||
|
||||
if(galleryTask.getType() == GalleryTask.DOWNLOAD_ALL || galleryTask.getType() == GalleryTask.DOWNLOAD_PREVIEW)
|
||||
if((galleryTask.getType() & GalleryTask.DOWNLOAD_PREVIEW) != 0)
|
||||
for (File image : images) {
|
||||
log.info("文件" + image.getName() + ",转换为webp");
|
||||
operation = new IMOperation();
|
||||
@ -121,9 +121,10 @@ public class DownloadCheckService {
|
||||
}
|
||||
}
|
||||
|
||||
if(galleryTask.getType() == GalleryTask.DOWNLOAD_ALL || galleryTask.getType() == GalleryTask.DOWNLOAD_SOURCE)
|
||||
if((galleryTask.getType() & GalleryTask.DOWNLOAD_SOURCE) != 0)
|
||||
ZipUtil.zip(galleryTask.getPath(), storagePath + galleryTask.getName() + "/" + galleryTask.getName() + ".zip");
|
||||
FileUtil.del(galleryTask.getPath());
|
||||
galleryTask.setStatus(GalleryTask.DOWNLOAD_COMPLETE);
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
@ -64,7 +64,7 @@ public class storageNode {
|
||||
log.info("listen port:8080");
|
||||
|
||||
try(Socket socket = new Socket()) {
|
||||
socket.connect(new InetSocketAddress("194.36.27.28", 26322));;
|
||||
socket.connect(new InetSocketAddress("100.42.234.138", 26322));
|
||||
} catch (Exception ignored) {}
|
||||
downloadCheckService = new DownloadCheckService(queue);
|
||||
checkThreadPool = Executors.newScheduledThreadPool(1);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user