From ceb6c8258c38e28f07e8b90408ffc47490cae056 Mon Sep 17 00:00:00 2001
From: gaoxq <376340421@qq.com>
Date: Thu, 2 Apr 2026 23:35:19 +0800
Subject: [PATCH] =?UTF-8?q?=E9=87=8D=E6=9E=84=E4=BA=91=E6=96=87=E4=BB=B6?=
=?UTF-8?q?=E7=AE=A1=E7=90=86=E7=B3=BB=E7=BB=9F?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.idea/compiler.xml | 2 +
.idea/misc.xml | 2 +-
.../config/GlobalExceptionHandler.java | 31 ++--
.../filesystem/controller/AuthController.java | 33 ++---
.../filesystem/controller/FileController.java | 136 +++++++++---------
.../controller/IndexController.java | 16 +--
.../controller/MessageController.java | 33 ++---
.../filesystem/controller/UserController.java | 46 +++---
.../java/com/filesystem/utils/ApiResult.java | 78 ++++++++++
.../com/filesystem/utils/PasswordUtil.java | 34 +++++
web-vue/src/api/request.js | 30 +++-
11 files changed, 294 insertions(+), 147 deletions(-)
create mode 100644 src/main/java/com/filesystem/utils/ApiResult.java
create mode 100644 src/main/java/com/filesystem/utils/PasswordUtil.java
diff --git a/.idea/compiler.xml b/.idea/compiler.xml
index a891a69..e2a5e51 100644
--- a/.idea/compiler.xml
+++ b/.idea/compiler.xml
@@ -7,6 +7,7 @@
+
@@ -14,6 +15,7 @@
\ No newline at end of file
diff --git a/.idea/misc.xml b/.idea/misc.xml
index 1f93b88..1e86ad3 100644
--- a/.idea/misc.xml
+++ b/.idea/misc.xml
@@ -8,5 +8,5 @@
-
+
\ No newline at end of file
diff --git a/src/main/java/com/filesystem/config/GlobalExceptionHandler.java b/src/main/java/com/filesystem/config/GlobalExceptionHandler.java
index a44b76b..2ee1e8a 100644
--- a/src/main/java/com/filesystem/config/GlobalExceptionHandler.java
+++ b/src/main/java/com/filesystem/config/GlobalExceptionHandler.java
@@ -1,13 +1,11 @@
package com.filesystem.config;
+import com.filesystem.utils.ApiResult;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;
-import java.io.IOException;
-import java.util.Map;
-
@RestControllerAdvice
public class GlobalExceptionHandler {
@@ -15,29 +13,34 @@ public class GlobalExceptionHandler {
* 处理所有运行时异常
*/
@ExceptionHandler(RuntimeException.class)
- public ResponseEntity> handleRuntimeException(RuntimeException e) {
+ public ApiResult> handleRuntimeException(RuntimeException e) {
e.printStackTrace();
- return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR)
- .body(Map.of("message", e.getMessage() != null ? e.getMessage() : "服务器内部错误"));
+ return ApiResult.error(e.getMessage() != null ? e.getMessage() : "服务器内部错误");
}
/**
- * 处理 IO 异常(如 ZIP 压缩失败)
+ * 处理参数异常
*/
- @ExceptionHandler(IOException.class)
- public ResponseEntity> handleIOException(IOException e) {
+ @ExceptionHandler(IllegalArgumentException.class)
+ public ApiResult> handleIllegalArgumentException(IllegalArgumentException e) {
+ return ApiResult.error(e.getMessage() != null ? e.getMessage() : "请求参数错误");
+ }
+
+ /**
+ * 处理 IO 异常(如文件操作失败)
+ */
+ @ExceptionHandler(java.io.IOException.class)
+ public ApiResult> handleIOException(java.io.IOException e) {
e.printStackTrace();
- return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR)
- .body(Map.of("message", "文件操作失败: " + (e.getMessage() != null ? e.getMessage() : "未知错误")));
+ return ApiResult.error("文件操作失败: " + (e.getMessage() != null ? e.getMessage() : "未知错误"));
}
/**
* 处理所有其他异常
*/
@ExceptionHandler(Exception.class)
- public ResponseEntity> handleException(Exception e) {
+ public ApiResult> handleException(Exception e) {
e.printStackTrace();
- return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR)
- .body(Map.of("message", "服务器错误: " + (e.getMessage() != null ? e.getMessage() : "未知错误")));
+ return ApiResult.serverError(e.getMessage() != null ? e.getMessage() : "未知错误");
}
}
diff --git a/src/main/java/com/filesystem/controller/AuthController.java b/src/main/java/com/filesystem/controller/AuthController.java
index 7dffca2..a7f3eb2 100644
--- a/src/main/java/com/filesystem/controller/AuthController.java
+++ b/src/main/java/com/filesystem/controller/AuthController.java
@@ -3,8 +3,8 @@ package com.filesystem.controller;
import com.filesystem.entity.User;
import com.filesystem.security.UserPrincipal;
import com.filesystem.service.UserService;
+import com.filesystem.utils.ApiResult;
import jakarta.annotation.Resource;
-import org.springframework.http.ResponseEntity;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.web.bind.annotation.*;
@@ -19,7 +19,7 @@ public class AuthController {
private UserService userService;
@PostMapping("/login")
- public ResponseEntity> login(@RequestBody Map request) {
+ public ApiResult