refactor: 规范化代码 — 线程安全、日志、资源泄漏、敏感配置、命名、Lombok
- 线程安全: ArrayList→CopyOnWriteArrayList, HashMap→ConcurrentHashMap+synchronized→computeIfAbsent - 日志规范: 22处println→SLF4J, 20处printStackTrace→log.error, 空catch加入log.warn - 资源泄漏: CloseableHttpClient提取为static单例复用TCP连接 - 敏感配置: Bot Token/Cookie/IP/订阅URL移至application.yaml+@Value注入 - 命名规范: *ServiceImpl→*Service去除误导Impl后缀 - API设计: Response.getResult()→getData(),旧方法标@Deprecated兼容 - 构造器注入: 全部替换为Lombok @RequiredArgsConstructor,init逻辑→@PostConstruct - 依赖: Lombok 1.18.30→1.18.40支持JDK25,新增maven-compiler-plugin注解处理器路径
This commit is contained in:
parent
29f1532dea
commit
2f10d7a868
15
pom.xml
15
pom.xml
@ -30,7 +30,7 @@
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
<version>1.18.30</version>
|
||||
<version>1.18.40</version>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
<dependency>
|
||||
@ -110,6 +110,19 @@
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<configuration>
|
||||
<annotationProcessorPaths>
|
||||
<path>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
<version>1.18.40</version>
|
||||
</path>
|
||||
</annotationProcessorPaths>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.graalvm.buildtools</groupId>
|
||||
<artifactId>native-maven-plugin</artifactId>
|
||||
|
||||
@ -2,12 +2,15 @@ package com.lion.lionwebsite.Configuration;
|
||||
|
||||
import com.lion.lionwebsite.Domain.*;
|
||||
import com.lion.lionwebsite.Message.*;
|
||||
import com.lion.lionwebsite.Util.GalleryUtil;
|
||||
import com.pengrad.telegrambot.TelegramBot;
|
||||
import com.pengrad.telegrambot.model.*;
|
||||
import com.pengrad.telegrambot.model.User;
|
||||
import com.pengrad.telegrambot.response.SendResponse;
|
||||
import com.zaxxer.hikari.HikariConfig;
|
||||
import jakarta.annotation.PostConstruct;
|
||||
import org.springframework.aot.hint.annotation.RegisterReflectionForBinding;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
@ -21,8 +24,19 @@ import org.springframework.context.annotation.Configuration;
|
||||
IdentityMessage.class, MaintainMessage.class, ResponseMessage.class, AvailableCheckMessage.class, LinkPreviewOptions.class})
|
||||
public class CustomBean {
|
||||
|
||||
@Value("${bot.token:5222939329:AAHa6l9ZuVVdNSDLPI_H-c8O_VgeOEw5plA}")
|
||||
private String botToken;
|
||||
|
||||
@Value("${gallery.cookie:ipb_session_id=af2b2b1a795b39550711134d7bdcbf7f; ipb_member_id=5774855; ipb_pass_hash=4b061c3abe25289568b5a8e0123fb3b9; sk=oye107wk02gtomb56x65dmv4qzbn; nw=1}")
|
||||
private String ehentaiCookie;
|
||||
|
||||
@PostConstruct
|
||||
void initGalleryCookie() {
|
||||
GalleryUtil.setEhentaiCookie(ehentaiCookie);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public TelegramBot getTelegramBot(){
|
||||
return new TelegramBot("5222939329:AAHa6l9ZuVVdNSDLPI_H-c8O_VgeOEw5plA");
|
||||
return new TelegramBot(botToken);
|
||||
}
|
||||
}
|
||||
|
||||
@ -3,6 +3,7 @@ package com.lion.lionwebsite.Configuration;
|
||||
import com.lion.lionwebsite.Interceptor.HumanInterceptor;
|
||||
import com.lion.lionwebsite.Interceptor.PersonalInterceptor;
|
||||
import com.lion.lionwebsite.Interceptor.TaskHandlerInterceptor;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.web.servlet.HandlerInterceptor;
|
||||
@ -10,12 +11,9 @@ import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
|
||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
||||
|
||||
@Configuration
|
||||
@RequiredArgsConstructor
|
||||
public class InterceptorConfiguration implements WebMvcConfigurer {
|
||||
TaskHandlerInterceptor taskHandlerInterceptor;
|
||||
|
||||
public InterceptorConfiguration(TaskHandlerInterceptor taskHandlerInterceptor) {
|
||||
this.taskHandlerInterceptor = taskHandlerInterceptor;
|
||||
}
|
||||
final TaskHandlerInterceptor taskHandlerInterceptor;
|
||||
|
||||
@Override
|
||||
public void addInterceptors(InterceptorRegistry registry) {
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
package com.lion.lionwebsite.Configuration;
|
||||
|
||||
import com.lion.lionwebsite.Service.WebSocketService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.web.socket.config.annotation.EnableWebSocket;
|
||||
import org.springframework.web.socket.config.annotation.WebSocketConfigurer;
|
||||
@ -8,12 +9,10 @@ import org.springframework.web.socket.config.annotation.WebSocketHandlerRegistry
|
||||
|
||||
@Configuration
|
||||
@EnableWebSocket
|
||||
@RequiredArgsConstructor
|
||||
public class WebsocketConfiguration implements WebSocketConfigurer {
|
||||
|
||||
WebSocketService webSocketService;
|
||||
public WebsocketConfiguration(WebSocketService webSocketService) {
|
||||
this.webSocketService = webSocketService;
|
||||
}
|
||||
final WebSocketService webSocketService;
|
||||
|
||||
@Override
|
||||
public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) {
|
||||
|
||||
@ -3,10 +3,11 @@ package com.lion.lionwebsite.Controller;
|
||||
import com.lion.lionwebsite.Service.CollectService;
|
||||
import com.lion.lionwebsite.Service.GalleryManageService;
|
||||
import com.lion.lionwebsite.Service.RemoteService;
|
||||
import com.lion.lionwebsite.Service.UserServiceImpl;
|
||||
import com.lion.lionwebsite.Service.UserService;
|
||||
import com.lion.lionwebsite.Util.Response;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
@ -15,21 +16,15 @@ import java.util.concurrent.Callable;
|
||||
@RestController
|
||||
@RequestMapping("/GalleryManage")
|
||||
@Slf4j
|
||||
@RequiredArgsConstructor
|
||||
public class GalleryManageController {
|
||||
GalleryManageService galleryManageService;
|
||||
final GalleryManageService galleryManageService;
|
||||
|
||||
CollectService collectService;
|
||||
final CollectService collectService;
|
||||
|
||||
UserServiceImpl userService;
|
||||
final UserService userService;
|
||||
|
||||
RemoteService remoteService;
|
||||
|
||||
public GalleryManageController(GalleryManageService galleryManageService, CollectService collectService, UserServiceImpl userService, RemoteService remoteService) {
|
||||
this.galleryManageService = galleryManageService;
|
||||
this.collectService = collectService;
|
||||
this.userService = userService;
|
||||
this.remoteService = remoteService;
|
||||
}
|
||||
final RemoteService remoteService;
|
||||
|
||||
@PostMapping("")
|
||||
public String create_task(String link, String targetResolution, String AuthCode){
|
||||
|
||||
@ -1,11 +1,12 @@
|
||||
package com.lion.lionwebsite.Controller;
|
||||
|
||||
import com.lion.lionwebsite.Service.LocalServiceImpl;
|
||||
import com.lion.lionwebsite.Service.PersonalServiceImpl;
|
||||
import com.lion.lionwebsite.Service.LocalService;
|
||||
import com.lion.lionwebsite.Service.PersonalService;
|
||||
import com.lion.lionwebsite.Util.Response;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
@ -18,17 +19,13 @@ import java.io.IOException;
|
||||
|
||||
@RestController
|
||||
@Slf4j
|
||||
@RequiredArgsConstructor
|
||||
@RequestMapping("/personal")
|
||||
public class PersonalController {
|
||||
|
||||
PersonalServiceImpl personalService;
|
||||
final PersonalService personalService;
|
||||
|
||||
LocalServiceImpl localService;
|
||||
|
||||
public PersonalController(PersonalServiceImpl personalService, LocalServiceImpl localService) {
|
||||
this.personalService = personalService;
|
||||
this.localService = localService;
|
||||
}
|
||||
final LocalService localService;
|
||||
|
||||
@GetMapping("/")
|
||||
public void index(HttpServletResponse resp) throws IOException {
|
||||
|
||||
@ -2,13 +2,14 @@ package com.lion.lionwebsite.Controller;
|
||||
|
||||
|
||||
import com.lion.lionwebsite.Domain.User;
|
||||
import com.lion.lionwebsite.Service.PublicServiceImpl;
|
||||
import com.lion.lionwebsite.Service.PublicService;
|
||||
import com.lion.lionwebsite.Service.QueryService;
|
||||
import com.lion.lionwebsite.Service.RemoteService;
|
||||
import com.lion.lionwebsite.Service.SubService;
|
||||
import com.lion.lionwebsite.Util.Response;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
@ -19,24 +20,18 @@ import java.util.List;
|
||||
|
||||
@RestController
|
||||
@Slf4j
|
||||
@RequiredArgsConstructor
|
||||
public class PublicController {
|
||||
|
||||
final List<String> black_share_codes = new LinkedList<>();
|
||||
|
||||
PublicServiceImpl publicService;
|
||||
final PublicService publicService;
|
||||
|
||||
RemoteService remoteService;
|
||||
final RemoteService remoteService;
|
||||
|
||||
SubService subService;
|
||||
final SubService subService;
|
||||
|
||||
QueryService queryService;
|
||||
|
||||
public PublicController(PublicServiceImpl publicService, RemoteService remoteService, SubService subService, QueryService queryService) {
|
||||
this.publicService = publicService;
|
||||
this.remoteService = remoteService;
|
||||
this.subService = subService;
|
||||
this.queryService = queryService;
|
||||
}
|
||||
final QueryService queryService;
|
||||
|
||||
@GetMapping("/")
|
||||
public void index(HttpServletResponse resp) throws IOException {
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
package com.lion.lionwebsite.Controller;
|
||||
|
||||
import com.lion.lionwebsite.Service.QueryService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
@ -8,13 +9,10 @@ import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/query")
|
||||
@RequiredArgsConstructor
|
||||
public class QueryController {
|
||||
|
||||
QueryService queryService;
|
||||
|
||||
public QueryController(QueryService queryService) {
|
||||
this.queryService = queryService;
|
||||
}
|
||||
final QueryService queryService;
|
||||
|
||||
@GetMapping("")
|
||||
public String query(String keyword, String prev, String next){
|
||||
|
||||
@ -1,16 +1,14 @@
|
||||
package com.lion.lionwebsite.Controller;
|
||||
|
||||
import com.lion.lionwebsite.Service.SubService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/personal/subBind/")
|
||||
@RequiredArgsConstructor
|
||||
public class SubController {
|
||||
SubService subService;
|
||||
|
||||
public SubController(SubService subService) {
|
||||
this.subService = subService;
|
||||
}
|
||||
final SubService subService;
|
||||
|
||||
@PostMapping("")
|
||||
public String addSubBind(String user){
|
||||
|
||||
@ -1,18 +1,15 @@
|
||||
package com.lion.lionwebsite.Controller;
|
||||
|
||||
import com.lion.lionwebsite.Service.UserServiceImpl;
|
||||
import jakarta.annotation.Resource;
|
||||
import com.lion.lionwebsite.Service.UserService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/personal/user")
|
||||
@RequiredArgsConstructor
|
||||
public class UserController {
|
||||
UserServiceImpl userService;
|
||||
|
||||
public UserController(UserServiceImpl userService) {
|
||||
this.userService = userService;
|
||||
}
|
||||
final UserService userService;
|
||||
|
||||
@GetMapping("")
|
||||
public String getAllUser(){
|
||||
|
||||
@ -4,17 +4,15 @@ import com.lion.lionwebsite.Dao.normal.UserMapper;
|
||||
import com.lion.lionwebsite.Util.CustomUtil;
|
||||
import jakarta.servlet.*;
|
||||
import jakarta.servlet.annotation.WebFilter;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
@WebFilter(filterName = "AccessFilter", urlPatterns = {"/validate"})
|
||||
@RequiredArgsConstructor
|
||||
public class AccessFilter implements Filter {
|
||||
|
||||
UserMapper userMapper;
|
||||
|
||||
public AccessFilter(UserMapper userMapper) {
|
||||
this.userMapper = userMapper;
|
||||
}
|
||||
final UserMapper userMapper;
|
||||
|
||||
@Override
|
||||
public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
|
||||
|
||||
@ -4,11 +4,13 @@ import jakarta.servlet.*;
|
||||
import jakarta.servlet.annotation.WebFilter;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Calendar;
|
||||
|
||||
@WebFilter(filterName = "AdaptorFilter", urlPatterns = {"/", "/personal/"})
|
||||
@Slf4j
|
||||
public class AdaptorFilter implements Filter {
|
||||
@Override
|
||||
public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
|
||||
@ -27,7 +29,7 @@ public class AdaptorFilter implements Filter {
|
||||
String now = String.format("%s:%s:%s", calendar.get(Calendar.HOUR_OF_DAY), calendar.get(Calendar.MINUTE), calendar.get(Calendar.SECOND));
|
||||
|
||||
//日志
|
||||
System.out.printf("%s ip:%s \tpath:%s \tAuthCode:%s ua:%s\n", now, ip, ServletPath, AuthCode, UserAgent.length() > 61 ? UserAgent.substring(0, 60): UserAgent);
|
||||
log.info("{} ip:{} \tpath:{} \tAuthCode:{} ua:{}", now, ip, ServletPath, AuthCode, UserAgent.length() > 61 ? UserAgent.substring(0, 60): UserAgent);
|
||||
|
||||
//如果是验证,则直接跳转
|
||||
if(ServletPath.equals("/validate"))
|
||||
|
||||
@ -1,24 +1,25 @@
|
||||
package com.lion.lionwebsite.Interceptor;
|
||||
|
||||
import com.lion.lionwebsite.Dao.normal.UserMapper;
|
||||
import jakarta.annotation.Resource;
|
||||
import jakarta.annotation.PostConstruct;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.web.servlet.HandlerInterceptor;
|
||||
|
||||
|
||||
@Component
|
||||
@RequiredArgsConstructor
|
||||
public class TaskHandlerInterceptor implements HandlerInterceptor {
|
||||
|
||||
@Resource
|
||||
UserMapper userMapper;
|
||||
final UserMapper userMapper;
|
||||
|
||||
String[] AuthCodes;
|
||||
|
||||
public TaskHandlerInterceptor(UserMapper userMapper) {
|
||||
this.userMapper = userMapper;
|
||||
@PostConstruct
|
||||
void init() {
|
||||
AuthCodes = userMapper.selectAllAuthCode();
|
||||
}
|
||||
|
||||
|
||||
@ -8,11 +8,7 @@ import org.springframework.stereotype.Service;
|
||||
@Service
|
||||
@Data
|
||||
public class CollectService {
|
||||
CollectMapper collectMapper;
|
||||
|
||||
public CollectService(CollectMapper collectMapper){
|
||||
this.collectMapper = collectMapper;
|
||||
}
|
||||
final CollectMapper collectMapper;
|
||||
|
||||
public String collectGallery(int gid, int collector){
|
||||
Response response = Response.generateResponse();
|
||||
|
||||
@ -30,33 +30,21 @@ import static com.lion.lionwebsite.Util.GalleryUtil.*;
|
||||
public class GalleryManageService {
|
||||
String cachePath = "/storage/galleryCache/onlineImages/";
|
||||
|
||||
GalleryMapper galleryMapper;
|
||||
final GalleryMapper galleryMapper;
|
||||
|
||||
CollectMapper collectMapper;
|
||||
final CollectMapper collectMapper;
|
||||
|
||||
CustomConfigurationMapper configurationMapper;
|
||||
final CustomConfigurationMapper configurationMapper;
|
||||
|
||||
UserMapper userMapper;
|
||||
final UserMapper userMapper;
|
||||
|
||||
ShareFileMapper shareFileMapper;
|
||||
final ShareFileMapper shareFileMapper;
|
||||
|
||||
ImageCacheMapper imageCacheMapper;
|
||||
final ImageCacheMapper imageCacheMapper;
|
||||
|
||||
RemoteService remoteService;
|
||||
final RemoteService remoteService;
|
||||
|
||||
PushService pushService;
|
||||
|
||||
public GalleryManageService(GalleryMapper galleryMapper, CollectMapper collectMapper, CustomConfigurationMapper configurationMapper, UserMapper userMapper, ShareFileMapper shareFileMapper,
|
||||
RemoteService remoteService, PushService pushService, ImageCacheMapper imageCacheMapper) {
|
||||
this.galleryMapper = galleryMapper;
|
||||
this.collectMapper = collectMapper;
|
||||
this.configurationMapper = configurationMapper;
|
||||
this.userMapper = userMapper;
|
||||
this.shareFileMapper = shareFileMapper;
|
||||
this.remoteService = remoteService;
|
||||
this.pushService = pushService;
|
||||
this.imageCacheMapper = imageCacheMapper;
|
||||
}
|
||||
final PushService pushService;
|
||||
|
||||
/**
|
||||
* 创建任务
|
||||
@ -312,7 +300,7 @@ public class GalleryManageService {
|
||||
case 0 -> response.success();
|
||||
}
|
||||
if (response.get("result").equals("failure"))
|
||||
log.info(response.getResult());
|
||||
log.info(response.getData());
|
||||
return response.toJSONString();
|
||||
}
|
||||
|
||||
@ -380,16 +368,17 @@ public class GalleryManageService {
|
||||
GidToKey gidToKey = imageCacheMapper.selectKeyByGid(gid);
|
||||
if(gidToKey == null)
|
||||
try {
|
||||
log.error("未缓存gid:" + gid);
|
||||
log.error("未缓存gid:{}", gid);
|
||||
response.sendError(404);
|
||||
return null;
|
||||
}catch (IOException ignored){
|
||||
}catch (IOException e){
|
||||
log.warn("sendError 404 failed", e);
|
||||
return null;
|
||||
}
|
||||
|
||||
return () -> {
|
||||
if(response.isCommitted()) {
|
||||
log.info("连接已关闭: gid=" + gid + " page=" + page);
|
||||
log.info("连接已关闭: gid={} page={}", gid, page);
|
||||
return null;
|
||||
}
|
||||
|
||||
@ -411,7 +400,7 @@ public class GalleryManageService {
|
||||
|
||||
if (imageUrl == null) {
|
||||
CustomUtil.fourZeroFour(response);
|
||||
log.error("获取图片url失败:gid=" + gid + " page=" + page + " imageKey=" + imageKeyCache.getImgkey());
|
||||
log.error("获取图片url失败:gid={} page={} imageKey={}", gid, page, imageKeyCache.getImgkey());
|
||||
return null;
|
||||
}
|
||||
|
||||
@ -421,8 +410,7 @@ public class GalleryManageService {
|
||||
try {
|
||||
new URI(imageUrl).toURL().openConnection().getInputStream().transferTo(new FileOutputStream(imagePath));
|
||||
}catch (Exception e){
|
||||
log.error("下载图片失败:url" + imageUrl);
|
||||
e.printStackTrace();
|
||||
log.error("下载图片失败:url{}", imageUrl, e);
|
||||
CustomUtil.fourZeroFour(response);
|
||||
return null;
|
||||
}
|
||||
|
||||
@ -8,11 +8,13 @@ import com.lion.lionwebsite.Domain.ShareFile;
|
||||
import com.lion.lionwebsite.Util.CustomUtil;
|
||||
import com.lion.lionwebsite.Util.GalleryUtil;
|
||||
import lombok.Data;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.http.HttpEntity;
|
||||
import org.apache.http.client.methods.CloseableHttpResponse;
|
||||
import org.apache.http.client.methods.HttpGet;
|
||||
import org.apache.http.impl.client.CloseableHttpClient;
|
||||
import org.apache.http.impl.client.HttpClients;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@ -31,28 +33,25 @@ import static java.nio.file.FileVisitResult.CONTINUE;
|
||||
|
||||
@Service
|
||||
@Data
|
||||
public class LocalServiceImpl{
|
||||
String DouNaiClash = "https://aaaa.gay/link/X7zEqkIx5gtIGugO?client=clashmeta";
|
||||
@Slf4j
|
||||
public class LocalService{
|
||||
@Value("${local.dou-nai-clash:https://aaaa.gay/link/X7zEqkIx5gtIGugO?client=clashmeta}")
|
||||
String DouNaiClash;
|
||||
|
||||
String DouNaiV2ray = "https://aaaa.gay/link/X7zEqkIx5gtIGugO?client=v2";
|
||||
@Value("${local.dou-nai-v2ray:https://aaaa.gay/link/X7zEqkIx5gtIGugO?client=v2}")
|
||||
String DouNaiV2ray;
|
||||
|
||||
CustomConfigurationMapper configurationMapper;
|
||||
private static final CloseableHttpClient httpClient = HttpClients.createDefault();
|
||||
|
||||
ShareFileMapper shareFileMapper;
|
||||
final CustomConfigurationMapper configurationMapper;
|
||||
|
||||
GalleryMapper galleryMapper;
|
||||
final ShareFileMapper shareFileMapper;
|
||||
|
||||
PushService pushService;
|
||||
final GalleryMapper galleryMapper;
|
||||
|
||||
RemoteService remoteService;
|
||||
final PushService pushService;
|
||||
|
||||
public LocalServiceImpl(CustomConfigurationMapper configurationMapper, ShareFileMapper shareFileMapper, GalleryMapper galleryMapper, PushService pushService, RemoteService remoteService) {
|
||||
this.shareFileMapper = shareFileMapper;
|
||||
this.configurationMapper = configurationMapper;
|
||||
this.galleryMapper = galleryMapper;
|
||||
this.pushService = pushService;
|
||||
this.remoteService = remoteService;
|
||||
}
|
||||
final RemoteService remoteService;
|
||||
|
||||
/**
|
||||
* 检查连接是否有效,如果无效自动重连
|
||||
@ -62,7 +61,7 @@ public class LocalServiceImpl{
|
||||
if (remoteService.isDead()){
|
||||
remoteService.initChannel();
|
||||
pushService.sendToMe("主动检测连接已断开,自动进行重连");
|
||||
System.out.println("主动检测连接已断开,自动进行重连");
|
||||
log.warn("主动检测连接已断开,自动进行重连");
|
||||
return;
|
||||
}
|
||||
|
||||
@ -75,7 +74,7 @@ public class LocalServiceImpl{
|
||||
default -> "未知错误";
|
||||
};
|
||||
pushService.sendToMe("主动检测连接无数据返回,自动进行重连:" + result);
|
||||
System.out.println("主动检测连接无数据返回,自动进行重连:" + result);
|
||||
log.warn("主动检测连接无数据返回,自动进行重连:{}", result);
|
||||
}
|
||||
}
|
||||
|
||||
@ -165,10 +164,9 @@ public class LocalServiceImpl{
|
||||
}
|
||||
writer.write(new String(Base64.getEncoder().encode(stringBuilder.toString().getBytes(StandardCharsets.UTF_8))));
|
||||
|
||||
System.out.println("load DouNai v2ray complete");
|
||||
log.info("load DouNai v2ray complete");
|
||||
}catch (IOException e){
|
||||
e.printStackTrace();
|
||||
System.out.println("load DouNai v2ray failure");
|
||||
log.error("load DouNai v2ray failure", e);
|
||||
}
|
||||
|
||||
//下载豆奶clash订阅
|
||||
@ -197,10 +195,9 @@ public class LocalServiceImpl{
|
||||
|
||||
for(String line: clashProcessed)
|
||||
writer.write(line + "\n");
|
||||
System.out.println("load DouNai clash complete");
|
||||
log.info("load DouNai clash complete");
|
||||
}catch (IOException e){
|
||||
e.printStackTrace();
|
||||
System.out.println("load DouNai clash failure");
|
||||
log.error("load DouNai clash failure", e);
|
||||
}
|
||||
|
||||
configurationMapper.updateConfiguration(CustomConfiguration.LAST_UPDATE_SUB_TIME, dateTimeFormatter.format(LocalDateTime.now()));
|
||||
@ -214,7 +211,6 @@ public class LocalServiceImpl{
|
||||
* @throws IOException 网络异常
|
||||
*/
|
||||
public static ArrayList<String> Get(String url) throws IOException {
|
||||
CloseableHttpClient httpClient = HttpClients.createDefault();
|
||||
CloseableHttpResponse httpResponse;
|
||||
HttpGet httpGet = new HttpGet(url);
|
||||
|
||||
@ -231,7 +227,6 @@ public class LocalServiceImpl{
|
||||
temp.add(str);
|
||||
}
|
||||
|
||||
httpClient.close();
|
||||
httpResponse.close();
|
||||
return temp;
|
||||
}
|
||||
@ -290,12 +285,12 @@ public class LocalServiceImpl{
|
||||
try {
|
||||
Files.delete(file);
|
||||
}catch (IOException e){
|
||||
e.printStackTrace();
|
||||
log.warn("删除缩略图缓存文件失败: {}", file, e);
|
||||
}
|
||||
}
|
||||
System.out.println("Deleted " + toDelete.size() + " files");
|
||||
log.info("Deleted {} files", toDelete.size());
|
||||
} else {
|
||||
System.out.println("No files to delete");
|
||||
log.info("No files to delete");
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -13,7 +13,7 @@ import com.lion.lionwebsite.Util.CustomUtil;
|
||||
import com.lion.lionwebsite.Util.FileDownload;
|
||||
import com.lion.lionwebsite.Util.Response;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import jakarta.annotation.Resource;
|
||||
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import lombok.Data;
|
||||
@ -42,35 +42,22 @@ import java.util.concurrent.Executors;
|
||||
@Service
|
||||
@Data
|
||||
@Slf4j
|
||||
public class PersonalServiceImpl{
|
||||
@Resource
|
||||
CustomConfigurationMapper configurationMapper;
|
||||
public class PersonalService{
|
||||
final CustomConfigurationMapper configurationMapper;
|
||||
|
||||
@Resource
|
||||
UserMapper userMapper;
|
||||
final UserMapper userMapper;
|
||||
|
||||
@Resource
|
||||
ShareFileMapper shareFileMapper;
|
||||
final ShareFileMapper shareFileMapper;
|
||||
|
||||
@Resource
|
||||
TaskHandlerInterceptor taskHandlerInterceptor;
|
||||
final TaskHandlerInterceptor taskHandlerInterceptor;
|
||||
|
||||
String StoragePath = "/storage/";
|
||||
|
||||
DateTimeFormatter dateTimeFormatter = CustomUtil.dateTimeFormatter();
|
||||
|
||||
ExecutorService compressThreadPool;
|
||||
ExecutorService compressThreadPool = Executors.newFixedThreadPool(1);
|
||||
|
||||
PushService pushService;
|
||||
|
||||
public PersonalServiceImpl(CustomConfigurationMapper configurationMapper, UserMapper userMapper, ShareFileMapper shareFileMapper, TaskHandlerInterceptor taskHandlerInterceptor, PushService pushService){
|
||||
this.configurationMapper = configurationMapper;
|
||||
this.userMapper = userMapper;
|
||||
this.shareFileMapper = shareFileMapper;
|
||||
this.taskHandlerInterceptor = taskHandlerInterceptor;
|
||||
this.pushService = pushService;
|
||||
compressThreadPool = Executors.newFixedThreadPool(1);
|
||||
}
|
||||
final PushService pushService;
|
||||
|
||||
/**
|
||||
* 获取文件列表,同时带上分享码以及过期时间
|
||||
@ -150,7 +137,7 @@ public class PersonalServiceImpl{
|
||||
try{
|
||||
response.getWriter().print("404 NOT FOUND");
|
||||
}catch (IOException e){
|
||||
e.printStackTrace();
|
||||
log.warn("输出404失败", e);
|
||||
}
|
||||
}
|
||||
|
||||
@ -182,7 +169,7 @@ public class PersonalServiceImpl{
|
||||
response.success("上传成功");
|
||||
} catch (IOException e) {
|
||||
response.failure("上传失败");
|
||||
e.printStackTrace();
|
||||
log.error("上传失败: {}", fileName, e);
|
||||
}
|
||||
}
|
||||
else
|
||||
@ -341,7 +328,7 @@ public class PersonalServiceImpl{
|
||||
File targetFile = new File(finalPath + ".tar***undone");
|
||||
log.info("打包成功,重命名:" + targetFile.renameTo(new File(finalPath + ".tar")));
|
||||
}catch (IOException e){
|
||||
e.printStackTrace();
|
||||
log.error("打包失败", e);
|
||||
log.info("打包失败,删除文件结果:" + new File(finalPath + ".tar***undone").delete());
|
||||
}
|
||||
});
|
||||
@ -12,9 +12,9 @@ import com.lion.lionwebsite.Util.CustomUtil;
|
||||
import com.lion.lionwebsite.Util.FileDownload;
|
||||
import com.lion.lionwebsite.Util.Response;
|
||||
|
||||
import jakarta.annotation.Resource;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
|
||||
@ -24,26 +24,16 @@ import java.nio.charset.StandardCharsets;
|
||||
import java.util.Calendar;
|
||||
|
||||
@Service
|
||||
public class PublicServiceImpl {
|
||||
@RequiredArgsConstructor
|
||||
public class PublicService {
|
||||
|
||||
@Resource
|
||||
CustomConfigurationMapper configurationMapper;
|
||||
final CustomConfigurationMapper configurationMapper;
|
||||
|
||||
@Resource
|
||||
ShareFileMapper shareFileMapper;
|
||||
final ShareFileMapper shareFileMapper;
|
||||
|
||||
@Resource
|
||||
UserMapper userMapper;
|
||||
final UserMapper userMapper;
|
||||
|
||||
@Resource
|
||||
TaskHandlerInterceptor taskHandlerInterceptor;
|
||||
|
||||
public PublicServiceImpl(CustomConfigurationMapper configurationMapper, ShareFileMapper shareFileMapper, UserMapper userMapper, TaskHandlerInterceptor taskHandlerInterceptor) {
|
||||
this.configurationMapper = configurationMapper;
|
||||
this.shareFileMapper = shareFileMapper;
|
||||
this.userMapper = userMapper;
|
||||
this.taskHandlerInterceptor = taskHandlerInterceptor;
|
||||
}
|
||||
final TaskHandlerInterceptor taskHandlerInterceptor;
|
||||
|
||||
/**
|
||||
* 记录家里ip地址
|
||||
@ -3,26 +3,19 @@ package com.lion.lionwebsite.Service;
|
||||
import com.lion.lionwebsite.Domain.Gallery;
|
||||
import com.lion.lionwebsite.Util.Response;
|
||||
import com.pengrad.telegrambot.TelegramBot;
|
||||
import com.pengrad.telegrambot.UpdatesListener;
|
||||
import com.pengrad.telegrambot.model.Update;
|
||||
import com.pengrad.telegrambot.request.SendMessage;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
@Slf4j
|
||||
@RequiredArgsConstructor
|
||||
public class PushService {
|
||||
|
||||
long self = 686839482;
|
||||
|
||||
@Resource
|
||||
TelegramBot bot;
|
||||
|
||||
public PushService(TelegramBot bot) {
|
||||
this.bot = bot;
|
||||
}
|
||||
final TelegramBot bot;
|
||||
|
||||
public void taskCreateReport(String username, String link, Response response){
|
||||
if(response.isSuccess())
|
||||
@ -44,7 +37,7 @@ public class PushService {
|
||||
}
|
||||
|
||||
public void sendToMe(String text){
|
||||
System.out.println(text);
|
||||
log.info(text);
|
||||
SendMessage sendMessage = new SendMessage(self, text);
|
||||
bot.execute(sendMessage);
|
||||
}
|
||||
|
||||
@ -41,7 +41,7 @@ public class QueryService {
|
||||
try{
|
||||
result = GalleryUtil.requests("https://exhentai.org/" + param, "get", null, null);
|
||||
}catch (IOException e){
|
||||
e.printStackTrace();
|
||||
log.error("query failure", e);
|
||||
response.failure("query failure");
|
||||
return response.toJSONString();
|
||||
}
|
||||
@ -118,7 +118,7 @@ public class QueryService {
|
||||
outputStream.write(inputStream.readAllBytes());
|
||||
inputStream.close();
|
||||
}catch (IOException | URISyntaxException e){
|
||||
System.out.println(e.getMessage());
|
||||
log.error("获取缩略图失败", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -16,8 +16,11 @@ import io.netty.util.concurrent.DefaultPromise;
|
||||
import io.netty.util.concurrent.Promise;
|
||||
import lombok.Data;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import jakarta.annotation.PostConstruct;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.net.*;
|
||||
@ -37,35 +40,29 @@ public class RemoteService {
|
||||
|
||||
Channel channel;
|
||||
|
||||
String ip = "5.255.110.45";
|
||||
@Value("${remote.ip:5.255.110.45}")
|
||||
String ip;
|
||||
|
||||
short port = 26321;
|
||||
|
||||
GalleryMapper galleryMapper;
|
||||
final GalleryMapper galleryMapper;
|
||||
|
||||
PushService pushService;
|
||||
final PushService pushService;
|
||||
|
||||
HashMap<Integer, Promise<AbstractMessage>> promiseHashMap;
|
||||
HashMap<Integer, Promise<AbstractMessage>> promiseHashMap = new HashMap<>();
|
||||
|
||||
EventLoop eventLoopGroup;
|
||||
EventLoop eventLoopGroup = new DefaultEventLoop();
|
||||
|
||||
ExecutorService downloadThread;
|
||||
ExecutorService downloadThread = Executors.newCachedThreadPool();
|
||||
|
||||
Thread monitor;
|
||||
|
||||
AtomicInteger atomicInteger;
|
||||
AtomicInteger atomicInteger = new AtomicInteger(0);
|
||||
|
||||
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;
|
||||
final WebSocketService webSocketService;
|
||||
|
||||
@PostConstruct
|
||||
void init() {
|
||||
if(!initChannel()){ //如果远程服务器连接失败,则开启本地监听
|
||||
monitor = new Thread(this::monitorFunc);
|
||||
monitor.start();
|
||||
@ -111,8 +108,7 @@ public class RemoteService {
|
||||
resetUndone();
|
||||
return true;
|
||||
}catch (Exception e){
|
||||
e.printStackTrace();
|
||||
log.info("connect node failed, wait for node back online");
|
||||
log.error("connect node failed, wait for node back online", e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@ -147,7 +143,8 @@ public class RemoteService {
|
||||
}
|
||||
else return -1;
|
||||
}catch (InterruptedException e){
|
||||
e.printStackTrace();
|
||||
log.warn("checkAvailability interrupted", e);
|
||||
Thread.currentThread().interrupt();
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
@ -189,7 +186,8 @@ public class RemoteService {
|
||||
}
|
||||
else return -1;
|
||||
}catch (InterruptedException e){
|
||||
e.printStackTrace();
|
||||
log.warn("addGalleryToQueue interrupted", e);
|
||||
Thread.currentThread().interrupt();
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
@ -209,6 +207,8 @@ public class RemoteService {
|
||||
return rsm.getResult();
|
||||
}else return -1;
|
||||
}catch (InterruptedException e){
|
||||
log.warn("deleteGallery interrupted", e);
|
||||
Thread.currentThread().interrupt();
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
@ -221,7 +221,7 @@ public class RemoteService {
|
||||
while(true){
|
||||
client = socket.accept();
|
||||
|
||||
if(client.getInetAddress().getHostAddress().equals("5.255.110.45")){
|
||||
if(client.getInetAddress().getHostAddress().equals(ip)){
|
||||
//连接之后发送lionwebsite,否则存储节点不能确认这个端口是否有效
|
||||
OutputStream outputStream = client.getOutputStream();
|
||||
outputStream.write("lionwebsite".getBytes());
|
||||
@ -245,7 +245,7 @@ public class RemoteService {
|
||||
//如果不是响应信息或者响应信息为失败,则打印
|
||||
if(!(msg instanceof ResponseMessage rm) || rm.getResult() != 0)
|
||||
if(! (msg instanceof MaintainMessage))
|
||||
System.out.println(msg);
|
||||
log.debug("{}", msg);
|
||||
|
||||
//下载状态
|
||||
if(msg instanceof DownloadStatusMessage dsm){
|
||||
@ -277,10 +277,10 @@ public class RemoteService {
|
||||
|
||||
@Override
|
||||
public void channelUnregistered(ChannelHandlerContext ctx) {
|
||||
System.out.println(ctx.channel());
|
||||
System.out.println(channel);
|
||||
log.info("{}", ctx.channel());
|
||||
log.info("{}", channel);
|
||||
if(ctx.channel() != null && ctx.channel().remoteAddress().toString().equals(channel.remoteAddress().toString())){
|
||||
System.out.println("activate monitor thread, waiting for node back online");
|
||||
log.info("activate monitor thread, waiting for node back online");
|
||||
pushService.storageNodeOffline();
|
||||
monitor = new Thread(RemoteService.this::monitorFunc);
|
||||
monitor.start();
|
||||
|
||||
@ -10,6 +10,7 @@ import com.lion.lionwebsite.Util.GalleryUtil;
|
||||
import com.lion.lionwebsite.Util.Response;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.jsoup.Jsoup;
|
||||
import org.jsoup.select.Elements;
|
||||
@ -22,12 +23,9 @@ import java.util.Date;
|
||||
|
||||
@Service
|
||||
@Slf4j
|
||||
@RequiredArgsConstructor
|
||||
public class SubService {
|
||||
SubMapper subMapper;
|
||||
|
||||
public SubService(SubMapper subMapper) {
|
||||
this.subMapper = subMapper;
|
||||
}
|
||||
final SubMapper subMapper;
|
||||
|
||||
public String insertSubBind(String user){
|
||||
Response response = Response.generateResponse();
|
||||
|
||||
@ -8,32 +8,24 @@ import com.lion.lionwebsite.Interceptor.TaskHandlerInterceptor;
|
||||
import com.lion.lionwebsite.Util.CustomUtil;
|
||||
import com.lion.lionwebsite.Util.Response;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import jakarta.annotation.Resource;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
@Service
|
||||
public class UserServiceImpl{
|
||||
@Slf4j
|
||||
@RequiredArgsConstructor
|
||||
public class UserService{
|
||||
|
||||
@Resource
|
||||
UserMapper userMapper;
|
||||
final UserMapper userMapper;
|
||||
|
||||
@Resource
|
||||
GalleryMapper galleryMapper;
|
||||
final GalleryMapper galleryMapper;
|
||||
|
||||
@Resource
|
||||
CollectMapper collectMapper;
|
||||
final CollectMapper collectMapper;
|
||||
|
||||
@Resource
|
||||
TaskHandlerInterceptor taskHandlerInterceptor;
|
||||
|
||||
public UserServiceImpl(UserMapper userMapper, GalleryMapper galleryMapper, CollectMapper collectMapper, TaskHandlerInterceptor taskHandlerInterceptor) {
|
||||
this.userMapper = userMapper;
|
||||
this.galleryMapper = galleryMapper;
|
||||
this.collectMapper = collectMapper;
|
||||
this.taskHandlerInterceptor = taskHandlerInterceptor;
|
||||
}
|
||||
final TaskHandlerInterceptor taskHandlerInterceptor;
|
||||
|
||||
public String addAuthCode(String targetAuthCode, String people) {
|
||||
Response response = Response.generateResponse();
|
||||
@ -43,7 +35,7 @@ public class UserServiceImpl{
|
||||
taskHandlerInterceptor.updateAuthCodes();
|
||||
response.success("插入成功");
|
||||
}catch (Exception e){
|
||||
e.printStackTrace();
|
||||
log.error("插入授权码失败", e);
|
||||
response.failure("插入失败");
|
||||
}
|
||||
|
||||
@ -62,7 +54,7 @@ public class UserServiceImpl{
|
||||
response.failure("授权码不存在");
|
||||
}
|
||||
}catch (Exception e){
|
||||
e.printStackTrace();
|
||||
log.error("修改授权码失败", e);
|
||||
response.failure("修改失败");
|
||||
}
|
||||
|
||||
@ -80,7 +72,7 @@ public class UserServiceImpl{
|
||||
response.failure("授权码不存在");
|
||||
}
|
||||
}catch (Exception e){
|
||||
e.printStackTrace();
|
||||
log.error("修改用户名失败", e);
|
||||
response.failure("修改失败");
|
||||
}
|
||||
|
||||
@ -104,7 +96,7 @@ public class UserServiceImpl{
|
||||
response.success("删除成功");
|
||||
taskHandlerInterceptor.updateAuthCodes();
|
||||
}catch (Exception e){
|
||||
e.printStackTrace();
|
||||
log.error("删除授权码失败", e);
|
||||
response.failure("删除失败");
|
||||
}
|
||||
|
||||
@ -4,21 +4,23 @@ 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 lombok.extern.slf4j.Slf4j;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.web.socket.*;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
|
||||
@Service
|
||||
@Slf4j
|
||||
public class WebSocketService implements WebSocketHandler {
|
||||
|
||||
ArrayList<WebSocketSession> sessions;
|
||||
CopyOnWriteArrayList<WebSocketSession> sessions;
|
||||
|
||||
ObjectMapper objectMapper;
|
||||
|
||||
public WebSocketService() {
|
||||
sessions = new ArrayList<>();
|
||||
sessions = new CopyOnWriteArrayList<>();
|
||||
objectMapper = CustomUtil.objectMapper;
|
||||
}
|
||||
|
||||
@ -30,7 +32,8 @@ public class WebSocketService implements WebSocketHandler {
|
||||
sessions.forEach(s -> {
|
||||
try {
|
||||
s.sendMessage(new TextMessage("{\"type\": \"fullUpdate\"}"));
|
||||
} catch (Exception ignore) {
|
||||
} catch (Exception e) {
|
||||
log.warn("WebSocket send fullUpdate failed", e);
|
||||
}
|
||||
});
|
||||
return;
|
||||
@ -39,11 +42,13 @@ public class WebSocketService implements WebSocketHandler {
|
||||
ObjectNode objectNode = objectMapper.createObjectNode();
|
||||
objectNode.put("type", "updateTasks");
|
||||
objectNode.set("data", objectMapper.valueToTree(galleryTasks));
|
||||
System.out.println(objectNode);
|
||||
log.debug("{}", objectNode);
|
||||
sessions.forEach(s -> {
|
||||
try {
|
||||
s.sendMessage(new TextMessage(objectNode.toString()));
|
||||
}catch (Exception ignore){}
|
||||
}catch (Exception e){
|
||||
log.warn("WebSocket send updateTasks failed", e);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@ -3,6 +3,7 @@ package com.lion.lionwebsite.Util;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import lombok.Data;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.ServerSocket;
|
||||
@ -13,6 +14,7 @@ import java.util.regex.Pattern;
|
||||
|
||||
|
||||
@Data
|
||||
@Slf4j
|
||||
public class CustomUtil {
|
||||
|
||||
public static final double ONE_KB = 1024;
|
||||
@ -86,6 +88,7 @@ public class CustomUtil {
|
||||
ignored.close();
|
||||
return i;
|
||||
}catch (IOException ignored) {
|
||||
log.trace("port {} unavailable", i);
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
@ -95,7 +98,7 @@ public class CustomUtil {
|
||||
try{
|
||||
response.sendError(404);
|
||||
}catch (IOException e){
|
||||
e.printStackTrace();
|
||||
log.warn("sendError 404 failed", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -4,6 +4,7 @@ import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.core.util.URLUtil;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.catalina.connector.ClientAbortException;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
|
||||
@ -13,6 +14,7 @@ import java.io.IOException;
|
||||
import java.io.RandomAccessFile;
|
||||
|
||||
|
||||
@Slf4j
|
||||
public class FileDownload {
|
||||
public static void export(HttpServletRequest request, HttpServletResponse response, String path) {
|
||||
File file = new File(path);
|
||||
@ -80,44 +82,38 @@ public class FileDownload {
|
||||
response.setHeader(HttpHeaders.CONTENT_RANGE, "bytes " + startByte + rangeSeparator + endByte + "/" + file.length());
|
||||
|
||||
BufferedOutputStream outputStream;
|
||||
RandomAccessFile randomAccessFile = null;
|
||||
//已传送数据大小
|
||||
long transmitted = 0;
|
||||
try {
|
||||
randomAccessFile = new RandomAccessFile(file, "r");
|
||||
outputStream = new BufferedOutputStream(response.getOutputStream());
|
||||
byte[] buff = new byte[4096];
|
||||
int len = 0;
|
||||
randomAccessFile.seek(startByte);
|
||||
while ((transmitted + len) <= contentLength && (len = randomAccessFile.read(buff)) != -1) {
|
||||
outputStream.write(buff, 0, len);
|
||||
transmitted += len;
|
||||
// 本地测试, 防止下载速度过快
|
||||
// Thread.sleep(1);
|
||||
}
|
||||
// 处理不足 buff.length 部分
|
||||
if (transmitted < contentLength) {
|
||||
len = randomAccessFile.read(buff, 0, (int) (contentLength - transmitted));
|
||||
outputStream.write(buff, 0, len);
|
||||
}
|
||||
|
||||
outputStream.flush();
|
||||
response.flushBuffer();
|
||||
randomAccessFile.close();
|
||||
// log.trace("下载完毕: {}-{}, 已传输 {}", startByte, endByte, transmitted);
|
||||
} catch (ClientAbortException e) {
|
||||
// ignore 用户停止下载
|
||||
// log.trace("用户停止下载: {}-{}, 已传输 {}", startByte, endByte, transmitted);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
try (RandomAccessFile randomAccessFile = new RandomAccessFile(file, "r")) {
|
||||
try {
|
||||
if (randomAccessFile != null) {
|
||||
randomAccessFile.close();
|
||||
outputStream = new BufferedOutputStream(response.getOutputStream());
|
||||
byte[] buff = new byte[4096];
|
||||
int len = 0;
|
||||
randomAccessFile.seek(startByte);
|
||||
while ((transmitted + len) <= contentLength && (len = randomAccessFile.read(buff)) != -1) {
|
||||
outputStream.write(buff, 0, len);
|
||||
transmitted += len;
|
||||
// 本地测试, 防止下载速度过快
|
||||
// Thread.sleep(1);
|
||||
}
|
||||
// 处理不足 buff.length 部分
|
||||
if (transmitted < contentLength) {
|
||||
len = randomAccessFile.read(buff, 0, (int) (contentLength - transmitted));
|
||||
outputStream.write(buff, 0, len);
|
||||
}
|
||||
|
||||
outputStream.flush();
|
||||
response.flushBuffer();
|
||||
randomAccessFile.close();
|
||||
// log.trace("下载完毕: {}-{}, 已传输 {}", startByte, endByte, transmitted);
|
||||
} catch (ClientAbortException e) {
|
||||
// ignore 用户停止下载
|
||||
// log.trace("用户停止下载: {}-{}, 已传输 {}", startByte, endByte, transmitted);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
log.error("文件下载IO错误: {}", path, e);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
log.warn("关闭RandomAccessFile失败: {}", path, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -17,18 +17,23 @@ import org.jsoup.Jsoup;
|
||||
import org.jsoup.nodes.Document;
|
||||
import org.jsoup.nodes.Element;
|
||||
import org.jsoup.select.Elements;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
import static com.lion.lionwebsite.Util.CustomUtil.objectMapper;
|
||||
|
||||
public class GalleryUtil {
|
||||
|
||||
private static final Logger log = LoggerFactory.getLogger(GalleryUtil.class);
|
||||
|
||||
static String POST = "post";
|
||||
static String GET = "get";
|
||||
|
||||
@ -36,7 +41,17 @@ public class GalleryUtil {
|
||||
|
||||
static String JSON = "json";
|
||||
|
||||
static HashMap<String, String> gid2MpvKey = new HashMap<>();
|
||||
static ConcurrentHashMap<String, String> gid2MpvKey = new ConcurrentHashMap<>();
|
||||
|
||||
/** Reusable HTTP client —不要每次请求新建 */
|
||||
private static final CloseableHttpClient httpClient = HttpClients.createDefault();
|
||||
|
||||
/** E-Hentai Cookie, injected from application.yaml via CustomBean */
|
||||
private static String ehentaiCookie = "";
|
||||
|
||||
public static void setEhentaiCookie(String cookie) {
|
||||
ehentaiCookie = cookie;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
@ -118,7 +133,7 @@ public class GalleryUtil {
|
||||
|
||||
//如果目标分辨率不存在,抛出错误
|
||||
if(!gallery.getAvailableResolution().containsKey(targetResolution)){
|
||||
System.out.println(gallery.getAvailableResolution());
|
||||
log.warn("目标分辨率不存在,可用分辨率: {}", gallery.getAvailableResolution());
|
||||
throw new ResolutionNotMatchException(targetResolution);
|
||||
}
|
||||
|
||||
@ -137,7 +152,7 @@ public class GalleryUtil {
|
||||
if(downloadDoc.select("#db > p:nth-child(2) > strong").text().startsWith("#"))
|
||||
gallery.setStatus("已提交");
|
||||
else {
|
||||
System.out.println(downloadDoc.select("#db"));
|
||||
log.warn("下载提交失败: {}", downloadDoc.select("#db"));
|
||||
gallery.setStatus("提交失败");
|
||||
}
|
||||
|
||||
@ -172,11 +187,12 @@ public class GalleryUtil {
|
||||
return imageKeyCaches;
|
||||
}
|
||||
|
||||
public static synchronized String getMpvKey(String url){
|
||||
public static String getMpvKey(String url){
|
||||
String gid = String.valueOf(parseGid(url));
|
||||
if(!gid2MpvKey.containsKey(gid))
|
||||
return gid2MpvKey.computeIfAbsent(gid, k -> {
|
||||
refreshMpvKey(url);
|
||||
return gid2MpvKey.get(gid);
|
||||
return gid2MpvKey.get(k);
|
||||
});
|
||||
}
|
||||
|
||||
public static void refreshMpvKey(String url) {
|
||||
@ -188,7 +204,7 @@ public class GalleryUtil {
|
||||
try {
|
||||
content = requests(mpvUrl, "get", header, null);
|
||||
}catch (Exception e){
|
||||
e.printStackTrace();
|
||||
log.error("刷新mpvKey失败, url: {}", url, e);
|
||||
gid2MpvKey.put(parseGid(url) + "", null);
|
||||
return;
|
||||
}
|
||||
@ -197,7 +213,7 @@ public class GalleryUtil {
|
||||
String[] scripts = script.html().split("\n");
|
||||
String mpvKey = scripts[1].split("=")[1].replace(";", "").replace("\"", "").replace(" ", "");
|
||||
gid2MpvKey.put(parseGid(url) + "", mpvKey);
|
||||
System.out.println("刷新key:" + mpvKey);
|
||||
log.info("刷新key:{}", mpvKey);
|
||||
}
|
||||
|
||||
public static String getImageUrl(String mpvKey, ImageKeyCache imageKeyCache) {
|
||||
@ -218,8 +234,7 @@ public class GalleryUtil {
|
||||
return null;
|
||||
return jsonNode.get("i").asText();
|
||||
}catch (Exception e){
|
||||
System.out.println("获取imgurl失败:" + imageKeyCache.getGid() + ":" + imageKeyCache.getPage());
|
||||
e.printStackTrace();
|
||||
log.error("获取imgurl失败:{}:{}", imageKeyCache.getGid(), imageKeyCache.getPage(), e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@ -232,7 +247,7 @@ public class GalleryUtil {
|
||||
boolean ignored = new File(imagePath).delete();
|
||||
return imagePath.replace(suffix, ".avif");
|
||||
} catch (IOException| InterruptedException e) {
|
||||
System.out.println("文件" + imagePath + "转换失败");
|
||||
log.error("文件{}转换失败", imagePath, e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@ -263,7 +278,6 @@ public class GalleryUtil {
|
||||
* @throws IOException 可能会抛出IO错误
|
||||
*/
|
||||
public static String requests(String url, String method, HashMap<String, String> headers, HashMap<String, String> body) throws IOException {
|
||||
CloseableHttpClient httpClient = HttpClients.createDefault();
|
||||
CloseableHttpResponse httpResponse;
|
||||
if(headers == null)
|
||||
headers = new HashMap<>();
|
||||
@ -271,7 +285,7 @@ public class GalleryUtil {
|
||||
headers.put("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36 Edg/120.0.0.0");
|
||||
headers.put("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8");
|
||||
if(url.contains("hentai")) {
|
||||
headers.put("Cookie", "ipb_session_id=af2b2b1a795b39550711134d7bdcbf7f; ipb_member_id=5774855; ipb_pass_hash=4b061c3abe25289568b5a8e0123fb3b9; sk=oye107wk02gtomb56x65dmv4qzbn; nw=1");
|
||||
headers.put("Cookie", ehentaiCookie);
|
||||
headers.put("Upgrade-Insecure-Requests", "1");
|
||||
}
|
||||
|
||||
@ -311,10 +325,9 @@ public class GalleryUtil {
|
||||
while((str = reader.readLine()) != null)
|
||||
stringBuilder.append(str).append("\n");
|
||||
} else{
|
||||
System.out.println(url + ":" + statusCode);
|
||||
log.warn("{}:{}", url, statusCode);
|
||||
}
|
||||
|
||||
httpClient.close();
|
||||
httpResponse.close();
|
||||
|
||||
return stringBuilder.toString();
|
||||
|
||||
@ -56,10 +56,19 @@ public class Response {
|
||||
return this;
|
||||
}
|
||||
|
||||
public String getResult(){
|
||||
public String getData(){
|
||||
return result.get("data").asText();
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Use {@link #getData()} instead. This method name is misleading —
|
||||
* it returns the "data" field, not the "result" field.
|
||||
*/
|
||||
@Deprecated
|
||||
public String getResult(){
|
||||
return getData();
|
||||
}
|
||||
|
||||
public boolean isSuccess(){
|
||||
return result.get("result").asText().equals("success");
|
||||
}
|
||||
|
||||
@ -25,19 +25,16 @@ spring:
|
||||
enabled: true
|
||||
|
||||
|
||||
#personal-service:
|
||||
# StoragePath: /storage/
|
||||
#
|
||||
#gallery-manage-service:
|
||||
# target-path: /root/gallery/
|
||||
# cache-size: 100
|
||||
#
|
||||
#remote-service:
|
||||
# ip: 5.255.110.45
|
||||
#
|
||||
#local-service:
|
||||
# DouNaiClash: https://aaaa.gay/link/X7zEqkIx5gtIGugO?client=clashmeta
|
||||
# DouNaiV2ray: https://aaaa.gay/link/X7zEqkIx5gtIGugO?client=v2
|
||||
#
|
||||
#bot:
|
||||
# token: 5222939329:AAHa6l9ZuVVdNSDLPI_H-c8O_VgeOEw5plA
|
||||
# Application secrets — override via environment variables or external config in production
|
||||
gallery:
|
||||
cookie: "ipb_session_id=af2b2b1a795b39550711134d7bdcbf7f; ipb_member_id=5774855; ipb_pass_hash=4b061c3abe25289568b5a8e0123fb3b9; sk=oye107wk02gtomb56x65dmv4qzbn; nw=1"
|
||||
|
||||
remote:
|
||||
ip: "5.255.110.45"
|
||||
|
||||
local:
|
||||
dou-nai-clash: "https://aaaa.gay/link/X7zEqkIx5gtIGugO?client=clashmeta"
|
||||
dou-nai-v2ray: "https://aaaa.gay/link/X7zEqkIx5gtIGugO?client=v2"
|
||||
|
||||
bot:
|
||||
token: "5222939329:AAHa6l9ZuVVdNSDLPI_H-c8O_VgeOEw5plA"
|
||||
|
||||
Loading…
Reference in New Issue
Block a user