Please provide the code changes or file diffs you would like me to summarize.

This commit is contained in:
liumangmang
2026-05-07 14:12:54 +08:00
parent 3f0ebe24e0
commit 2d9011b606
17 changed files with 375 additions and 379 deletions
@@ -17,8 +17,6 @@ import org.springframework.web.cors.CorsConfigurationSource;
import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;
@Configuration
@EnableWebSecurity
@@ -2,6 +2,7 @@ package com.sshmanager.config;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.io.Resource;
import org.springframework.lang.NonNull;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import org.springframework.web.servlet.resource.PathResourceResolver;
@@ -15,13 +16,13 @@ import java.io.IOException;
public class SpaForwardConfig implements WebMvcConfigurer {
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
public void addResourceHandlers(@NonNull ResourceHandlerRegistry registry) {
registry.addResourceHandler("/**")
.addResourceLocations("classpath:/static/")
.resourceChain(true)
.addResolver(new PathResourceResolver() {
@Override
protected Resource getResource(String path, Resource location) throws IOException {
protected Resource getResource(@NonNull String path, @NonNull Resource location) throws IOException {
Resource resource = location.createRelative(path);
if (resource.exists() && resource.isReadable()) {
return resource;
@@ -9,6 +9,8 @@ import org.springframework.web.socket.WebSocketHandler;
import org.springframework.web.socket.server.HandshakeInterceptor;
import javax.servlet.http.HttpServletRequest;
import org.springframework.lang.NonNull;
import org.springframework.lang.Nullable;
import java.util.Map;
@Component
@@ -21,8 +23,8 @@ public class TerminalHandshakeInterceptor implements HandshakeInterceptor {
}
@Override
public boolean beforeHandshake(ServerHttpRequest request, ServerHttpResponse response,
WebSocketHandler wsHandler, Map<String, Object> attributes) throws Exception {
public boolean beforeHandshake(@NonNull ServerHttpRequest request, @NonNull ServerHttpResponse response,
@NonNull WebSocketHandler wsHandler, @NonNull Map<String, Object> attributes) throws Exception {
if (!(request instanceof ServletServerHttpRequest)) {
return false;
}
@@ -50,7 +52,7 @@ public class TerminalHandshakeInterceptor implements HandshakeInterceptor {
}
@Override
public void afterHandshake(ServerHttpRequest request, ServerHttpResponse response,
WebSocketHandler wsHandler, Exception exception) {
public void afterHandshake(@NonNull ServerHttpRequest request, @NonNull ServerHttpResponse response,
@NonNull WebSocketHandler wsHandler, @Nullable Exception exception) {
}
}
@@ -5,6 +5,7 @@ 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;
import org.springframework.lang.NonNull;
@Configuration
@EnableWebSocket
@@ -20,7 +21,8 @@ public class WebSocketConfig implements WebSocketConfigurer {
}
@Override
public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) {
@SuppressWarnings("null")
public void registerWebSocketHandlers(@NonNull WebSocketHandlerRegistry registry) {
registry.addHandler(terminalWebSocketHandler, "/ws/terminal")
.addInterceptors(terminalHandshakeInterceptor)
// Docker/remote deployments often use non-localhost origins.
@@ -14,7 +14,6 @@ import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.security.core.Authentication;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.servlet.mvc.method.annotation.StreamingResponseBody;
@@ -33,7 +32,6 @@ import java.util.concurrent.Future;
import java.util.concurrent.atomic.AtomicLong;
import java.util.function.Supplier;
import java.util.stream.Collectors;
import java.util.stream.Stream;
@RestController
@RequestMapping("/api/sftp")
@@ -282,7 +280,7 @@ public class SftpController {
return ResponseEntity.ok()
.header(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=\"" + filename + "\"")
.contentType(MediaType.APPLICATION_OCTET_STREAM)
.header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_OCTET_STREAM_VALUE)
.body(stream);
} catch (Exception e) {
return ResponseEntity.status(500).build();
@@ -331,12 +329,11 @@ public class SftpController {
file.transferTo(tempFile);
final java.io.File savedFile = tempFile;
UploadTaskStatus status = new UploadTaskStatus(taskId, userId, connectionId,
path, filename, file.getSize());
UploadTaskStatus status = new UploadTaskStatus(taskId, userId, filename, file.getSize());
status.setController(this);
uploadTasks.put(taskKey, status);
Future<?> future = transferTaskExecutor.submit(() -> {
transferTaskExecutor.submit(() -> {
status.setStatus("running");
try {
withSessionLock(key, () -> {
@@ -387,8 +384,6 @@ public class SftpController {
}
}
});
status.setFuture(future);
Map<String, Object> result = new HashMap<>();
result.put("taskId", taskId);
result.put("message", "Upload started");
@@ -654,6 +649,7 @@ public class SftpController {
}
@GetMapping("/transfer-remote/tasks/{taskId}/progress")
@SuppressWarnings("null")
public SseEmitter streamTransferProgress(
@PathVariable String taskId,
Authentication authentication) {
@@ -692,6 +688,7 @@ public class SftpController {
}
@GetMapping("/upload/tasks/{taskId}/progress")
@SuppressWarnings("null")
public SseEmitter streamUploadProgress(
@PathVariable String taskId,
Authentication authentication) {
@@ -739,6 +736,7 @@ public class SftpController {
}
}
@SuppressWarnings("null")
private void broadcastProgress(String taskKey, Map<String, Object> data) {
CopyOnWriteArrayList<SseEmitter> emitters = taskEmitters.get(taskKey);
if (emitters == null || emitters.isEmpty()) {
@@ -976,10 +974,7 @@ public class SftpController {
public static class UploadTaskStatus {
private final String taskId;
private final Long userId;
private final Long connectionId;
private final String path;
private final String filename;
private final long fileSize;
private final long createdAt;
private volatile String status;
private volatile String error;
@@ -987,17 +982,12 @@ public class SftpController {
private volatile long finishedAt;
private final AtomicLong totalBytes;
private final AtomicLong transferredBytes;
private volatile Future<?> future;
private volatile SftpController controller;
public UploadTaskStatus(String taskId, Long userId, Long connectionId,
String path, String filename, long fileSize) {
public UploadTaskStatus(String taskId, Long userId, String filename, long fileSize) {
this.taskId = taskId;
this.userId = userId;
this.connectionId = connectionId;
this.path = path;
this.filename = filename;
this.fileSize = fileSize;
this.createdAt = System.currentTimeMillis();
this.status = "queued";
this.totalBytes = new AtomicLong(fileSize);
@@ -1012,9 +1002,7 @@ public class SftpController {
this.controller = controller;
}
public void setFuture(Future<?> future) {
this.future = future;
}
public void setStatus(String status) {
this.status = status;
@@ -12,6 +12,7 @@ import org.springframework.web.socket.CloseStatus;
import org.springframework.web.socket.TextMessage;
import org.springframework.web.socket.WebSocketSession;
import org.springframework.web.socket.handler.TextWebSocketHandler;
import org.springframework.lang.NonNull;
import java.io.IOException;
import java.io.InputStream;
@@ -46,7 +47,8 @@ public class TerminalWebSocketHandler extends TextWebSocketHandler {
}
@Override
public void afterConnectionEstablished(WebSocketSession webSocketSession) throws Exception {
@SuppressWarnings("null")
public void afterConnectionEstablished(@NonNull WebSocketSession webSocketSession) throws Exception {
Long connectionId = (Long) webSocketSession.getAttributes().get("connectionId");
String username = (String) webSocketSession.getAttributes().get("username");
@@ -101,7 +103,7 @@ public class TerminalWebSocketHandler extends TextWebSocketHandler {
}
@Override
protected void handleTextMessage(WebSocketSession webSocketSession, TextMessage message) throws Exception {
protected void handleTextMessage(@NonNull WebSocketSession webSocketSession, @NonNull TextMessage message) throws Exception {
SshService.SshSession sshSession = sessions.get(webSocketSession.getId());
if (sshSession != null && sshSession.isConnected()) {
lastActivity.put(webSocketSession.getId(), System.currentTimeMillis());
@@ -122,7 +124,7 @@ public class TerminalWebSocketHandler extends TextWebSocketHandler {
}
@Override
public void afterConnectionClosed(WebSocketSession webSocketSession, CloseStatus status) throws Exception {
public void afterConnectionClosed(@NonNull WebSocketSession webSocketSession, @NonNull CloseStatus status) throws Exception {
SshService.SshSession sshSession = sessions.remove(webSocketSession.getId());
lastActivity.remove(webSocketSession.getId());
if (sshSession != null) {
@@ -6,7 +6,6 @@ import lombok.AllArgsConstructor;
import javax.persistence.*;
import java.time.Instant;
import java.time.temporal.ChronoUnit;
@Data
@NoArgsConstructor
@@ -8,6 +8,7 @@ import org.springframework.security.web.authentication.WebAuthenticationDetailsS
import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;
import org.springframework.web.filter.OncePerRequestFilter;
import org.springframework.lang.NonNull;
import javax.servlet.FilterChain;
import javax.servlet.ServletException;
@@ -27,8 +28,8 @@ public class JwtAuthenticationFilter extends OncePerRequestFilter {
}
@Override
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response,
FilterChain filterChain) throws ServletException, IOException {
protected void doFilterInternal(@NonNull HttpServletRequest request, @NonNull HttpServletResponse response,
@NonNull FilterChain filterChain) throws ServletException, IOException {
try {
String jwt = getJwtFromRequest(request);
if (StringUtils.hasText(jwt) && tokenProvider.validateToken(jwt)) {
@@ -7,6 +7,7 @@ import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Component;
import org.springframework.web.filter.OncePerRequestFilter;
import org.springframework.lang.NonNull;
import javax.servlet.FilterChain;
import javax.servlet.ServletException;
@@ -29,7 +30,7 @@ public class PasswordExpirationFilter extends OncePerRequestFilter {
}
@Override
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain)
protected void doFilterInternal(@NonNull HttpServletRequest request, @NonNull HttpServletResponse response, @NonNull FilterChain filterChain)
throws ServletException, IOException {
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
if (authentication != null && authentication.isAuthenticated()) {
@@ -59,6 +59,7 @@ public class BackupService {
}
@Transactional
@SuppressWarnings("null")
public BackupImportResponseDto importBackup(Long userId, BackupPackageDto backupPackage) {
if (backupPackage == null) {
throw new IllegalArgumentException("Backup package is required");
@@ -15,6 +15,7 @@ import java.util.List;
import java.util.stream.Collectors;
@Service
@SuppressWarnings("null")
public class ConnectionService {
private final ConnectionRepository connectionRepository;
@@ -28,17 +28,13 @@ import java.util.Optional;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyLong;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.doThrow;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyNoInteractions;
import static org.mockito.Mockito.when;
@ExtendWith(MockitoExtension.class)
@SuppressWarnings("null")
class ConnectionControllerTest {
@Mock
@@ -45,6 +45,7 @@ import static org.mockito.Mockito.verifyNoInteractions;
import static org.mockito.Mockito.when;
@ExtendWith(MockitoExtension.class)
@SuppressWarnings("null")
class SftpControllerTest {
@Mock
@@ -26,6 +26,7 @@ import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
@ExtendWith(MockitoExtension.class)
@SuppressWarnings("null")
class BackupServiceTest {
@Mock
@@ -27,6 +27,7 @@ import static org.mockito.Mockito.when;
import static org.mockito.Mockito.lenient;
@ExtendWith(MockitoExtension.class)
@SuppressWarnings("null")
class ConnectionServiceTest {
@Mock
@@ -23,6 +23,7 @@ import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
@ExtendWith(MockitoExtension.class)
@SuppressWarnings("null")
class SessionTreeLayoutServiceTest {
@Mock
@@ -110,12 +110,12 @@ export default function TransferCenterModal({
const unsubscribe = subscribeUploadProgress(taskId, (task) => {
updateTaskGroup(groupId, (current) => {
const nextItems = current.items.map((item) =>
item.taskId === task.taskId
item.taskId === task.taskId
? {
...item,
progress: task.progress,
status: task.status,
message: task.error || (task.status === 'success' ? '上传完成' : task.status === 'error' ? '上传失败' : task.status === 'cancelled' ? '已取消' : '正在传输...'),
message: task.error || (task.status === 'success' ? '上传完成' : task.status === 'error' ? '上传失败' : '正在传输...'),
}
: item,
)
@@ -231,9 +231,9 @@ export default function TransferCenterModal({
<div className="rounded-xl border border-slate-700 bg-black px-4 py-3 text-sm text-slate-400"></div>
</div>
</div>
<div className="flex-1 space-y-2">
<span className="text-sm text-slate-300">3. </span>
<div className="rounded-2xl border border-slate-700 bg-black p-2">
<div className="flex min-h-0 flex-1 flex-col space-y-2">
<span className="shrink-0 text-sm text-slate-300">3. </span>
<div className="min-h-0 flex-1 overflow-y-auto rounded-2xl border border-slate-700 bg-black p-2">
{connections.map((server) => {
const st = connectionStatuses[server.id]
const isOnline = st === 'online'