Compare commits
2 Commits
54b1dd47a6
...
6f0049442f
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6f0049442f | ||
|
|
1516226192 |
5
pom.xml
5
pom.xml
@ -110,6 +110,11 @@
|
||||
<version>6.9.1</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-websocket</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.lionsoul</groupId>
|
||||
<artifactId>ip2region</artifactId>
|
||||
|
||||
@ -0,0 +1,22 @@
|
||||
package com.lion.lionwebsite.Configuration;
|
||||
|
||||
import com.lion.lionwebsite.Service.WebSocketService;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.web.socket.config.annotation.EnableWebSocket;
|
||||
import org.springframework.web.socket.config.annotation.WebSocketConfigurer;
|
||||
import org.springframework.web.socket.config.annotation.WebSocketHandlerRegistry;
|
||||
|
||||
@Configuration
|
||||
@EnableWebSocket
|
||||
public class WebsocketConfiguration implements WebSocketConfigurer {
|
||||
|
||||
WebSocketService webSocketService;
|
||||
public WebsocketConfiguration(WebSocketService webSocketService) {
|
||||
this.webSocketService = webSocketService;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) {
|
||||
registry.addHandler(webSocketService, "/ws/").setAllowedOriginPatterns("*");
|
||||
}
|
||||
}
|
||||
@ -43,7 +43,6 @@ public class GalleryManageController {
|
||||
case "gid" -> galleryManageService.selectTaskByGid(Integer.parseInt(param));
|
||||
case "all" -> galleryManageService.selectAllGallery(userId);
|
||||
case "name" -> galleryManageService.selectGalleryByName(param);
|
||||
case "undone" -> galleryManageService.selectUnDoneGallery();
|
||||
case "downloader" -> galleryManageService.selectGalleryByDownloader(AuthCode);
|
||||
default -> Response._failure("参数错误");
|
||||
};
|
||||
|
||||
@ -2,10 +2,8 @@ package com.lion.lionwebsite.Controller;
|
||||
|
||||
import com.lion.lionwebsite.Service.LocalServiceImpl;
|
||||
import com.lion.lionwebsite.Service.PersonalServiceImpl;
|
||||
import com.lion.lionwebsite.Util.FileDownload;
|
||||
import com.lion.lionwebsite.Util.Response;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import jakarta.annotation.Resource;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
@ -32,11 +30,6 @@ public class PersonalController {
|
||||
this.localService = localService;
|
||||
}
|
||||
|
||||
@GetMapping("/sub/self")
|
||||
public void sub(HttpServletResponse response, HttpServletRequest request){
|
||||
FileDownload.export(request, response, "sub/sub.txt");
|
||||
}
|
||||
|
||||
@GetMapping("/files")
|
||||
public String file(String path) throws IOException {
|
||||
return personalService.getFiles(path);
|
||||
|
||||
@ -6,17 +6,11 @@ import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class GalleryTask {
|
||||
|
||||
public static byte DOWNLOADING = 1;
|
||||
|
||||
public static byte DOWNLOAD_COMPLETE = 2;
|
||||
|
||||
public static byte DOWNLOAD_QUEUED = 3;
|
||||
|
||||
public static byte COMPRESSING = 3;
|
||||
public static byte COMPRESS_COMPLETE = 4;
|
||||
|
||||
public static byte COMPRESSING = 5;
|
||||
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
private String name;
|
||||
|
||||
|
||||
@ -123,6 +123,7 @@ public class GalleryManageService {
|
||||
if (gallery.getStatus().equals("已提交")) {
|
||||
response.success(gallery.toString());
|
||||
gallery.setDownloader(user.getId());
|
||||
gallery.set_download(true);
|
||||
galleryMapper.insertGallery(gallery);
|
||||
|
||||
long usedAmount = Long.parseLong(configurationMapper.selectConfiguration(CustomConfiguration.WEEK_USED_AMOUNT).getValue());
|
||||
@ -230,23 +231,6 @@ public class GalleryManageService {
|
||||
return response.toJSONString();
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询未完成的本子
|
||||
*
|
||||
* @return 查询结果
|
||||
*/
|
||||
public String selectUnDoneGallery() {
|
||||
Response response = Response.generateResponse();
|
||||
Gallery[] galleries = galleryMapper.selectUnDoneGalleries();
|
||||
|
||||
if (galleries.length > 0)
|
||||
response.success(new ObjectMapper().valueToTree(galleries).toString());
|
||||
else
|
||||
response.failure();
|
||||
|
||||
return response.toJSONString();
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过本子名查询本子
|
||||
*
|
||||
|
||||
@ -52,13 +52,16 @@ public class RemoteService {
|
||||
|
||||
AtomicInteger atomicInteger;
|
||||
|
||||
public RemoteService(GalleryMapper galleryMapper, PushService pushService){
|
||||
WebSocketService webSocketService;
|
||||
|
||||
public RemoteService(GalleryMapper galleryMapper, PushService pushService, WebSocketService webSocketService){
|
||||
this.galleryMapper = galleryMapper;
|
||||
this.pushService = pushService;
|
||||
atomicInteger = new AtomicInteger(0);
|
||||
eventLoopGroup = new DefaultEventLoop();
|
||||
downloadThread = Executors.newCachedThreadPool();
|
||||
promiseHashMap = new HashMap<>();
|
||||
this.webSocketService = webSocketService;
|
||||
|
||||
if(!initChannel()){ //如果远程服务器连接失败,则开启本地监听
|
||||
monitor = new Thread(this::monitorFunc);
|
||||
@ -190,6 +193,7 @@ public class RemoteService {
|
||||
log.info(gallery.getName() + "下载进度:" + gallery.getProceeding() + "/" + gallery.getPages());
|
||||
galleryMapper.updateGallery(gallery);
|
||||
}
|
||||
webSocketService.updateTaskProcessing(galleryTasks);
|
||||
}
|
||||
else if(msg instanceof ResponseMessage rsm)
|
||||
promiseHashMap.get(rsm.messageId).setSuccess(rsm);
|
||||
|
||||
@ -0,0 +1,73 @@
|
||||
package com.lion.lionwebsite.Service;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import com.lion.lionwebsite.Domain.GalleryTask;
|
||||
import com.lion.lionwebsite.Util.CustomUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.web.socket.*;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
@Service
|
||||
public class WebSocketService implements WebSocketHandler {
|
||||
|
||||
ArrayList<WebSocketSession> sessions;
|
||||
|
||||
ObjectMapper objectMapper;
|
||||
|
||||
public WebSocketService() {
|
||||
sessions = new ArrayList<>();
|
||||
objectMapper = CustomUtil.objectMapper;
|
||||
}
|
||||
|
||||
public void updateTaskProcessing(GalleryTask[] galleryTasks){
|
||||
if(sessions.isEmpty())
|
||||
return;
|
||||
for (GalleryTask galleryTask : galleryTasks)
|
||||
if(galleryTask.getStatus() == GalleryTask.COMPRESS_COMPLETE) {
|
||||
sessions.forEach(s -> {
|
||||
try {
|
||||
s.sendMessage(new TextMessage("{\"type\": \"fullUpdate\"}"));
|
||||
} catch (Exception ignore) {
|
||||
}
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
ObjectNode objectNode = objectMapper.createObjectNode();
|
||||
objectNode.put("type", "updateTasks");
|
||||
objectNode.set("data", objectMapper.valueToTree(galleryTasks));
|
||||
System.out.println(objectNode);
|
||||
sessions.forEach(s -> {
|
||||
try {
|
||||
s.sendMessage(new TextMessage(objectNode.toString()));
|
||||
}catch (Exception ignore){}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterConnectionEstablished(@NotNull WebSocketSession session) {}
|
||||
|
||||
@Override
|
||||
public void handleMessage(@NotNull WebSocketSession session, @NotNull WebSocketMessage<?> message) throws Exception {
|
||||
if(message.getPayload().toString().equals("DownloaderWebsocket"))
|
||||
sessions.add(session);
|
||||
else
|
||||
session.close();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleTransportError(@NotNull WebSocketSession session, @NotNull Throwable exception) {}
|
||||
|
||||
@Override
|
||||
public void afterConnectionClosed(@NotNull WebSocketSession session, @NotNull CloseStatus closeStatus) {
|
||||
sessions.remove(session);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean supportsPartialMessages() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
Binary file not shown.
Loading…
Reference in New Issue
Block a user