From da9b7a52dbc6fcd2173efef90528d8fccc322554 Mon Sep 17 00:00:00 2001
From: longz <longzhaoz@qq.com>
Date: 星期五, 17 七月 2026 16:22:40 +0800
Subject: [PATCH] P1问题fix
---
ruoyi-service/ruoyi-account/src/main/java/com/ruoyi/account/controller/FileController.java | 35 ++++++++++++++++++++++++++++++++---
1 files changed, 32 insertions(+), 3 deletions(-)
diff --git a/ruoyi-service/ruoyi-account/src/main/java/com/ruoyi/account/controller/FileController.java b/ruoyi-service/ruoyi-account/src/main/java/com/ruoyi/account/controller/FileController.java
index 373f4d4..82ca91a 100644
--- a/ruoyi-service/ruoyi-account/src/main/java/com/ruoyi/account/controller/FileController.java
+++ b/ruoyi-service/ruoyi-account/src/main/java/com/ruoyi/account/controller/FileController.java
@@ -16,6 +16,8 @@
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;
+import java.util.LinkedHashSet;
+import java.util.Set;
import java.util.UUID;
import java.util.concurrent.TimeUnit;
@@ -29,6 +31,8 @@
@RestController
@RequestMapping("/file/")
public class FileController {
+
+ private static final String MANAGE_MEDIA_EXTENSIONS = "mp4,avi,rmvb,mov,wmv,flv,mkv,mpeg,mpg";
@Autowired
private FileUploadConfig fileUploadConfig;
@@ -105,7 +109,7 @@
// 获取文件后缀
String ext = filename.substring(filename.lastIndexOf(".") + 1);
// 检查文件类型
- String allowedExt = getAllowedExt(fileUploadConfig.getDocExt());
+ String allowedExt = getManageAllowedExt();
if (!isAllowedExt(ext, allowedExt)) {
return invalidExtResult(allowedExt);
}
@@ -205,7 +209,32 @@
return fileUploadConfig.getAllowExt();
}
- private boolean isAllowedExt(String ext, String allowedExt) {
+ String getManageAllowedExt() {
+ return mergeAllowedExt(getAllowedExt(fileUploadConfig.getDocExt()), MANAGE_MEDIA_EXTENSIONS);
+ }
+
+ static String mergeAllowedExt(String... extensionGroups) {
+ Set<String> extensions = new LinkedHashSet<>();
+ if (extensionGroups != null) {
+ for (String group : extensionGroups) {
+ if (group == null) {
+ continue;
+ }
+ for (String item : group.split(",")) {
+ String normalizedItem = item.trim();
+ if (normalizedItem.startsWith(".")) {
+ normalizedItem = normalizedItem.substring(1);
+ }
+ if (!normalizedItem.isEmpty()) {
+ extensions.add(normalizedItem.toLowerCase());
+ }
+ }
+ }
+ }
+ return String.join(",", extensions);
+ }
+
+ static boolean isAllowedExt(String ext, String allowedExt) {
if (ext == null || allowedExt == null || allowedExt.trim().length() == 0) {
return false;
}
@@ -225,4 +254,4 @@
private AjaxResult invalidExtResult(String allowedExt) {
return AjaxResult.error("上传文件格式不正确,仅支持" + (allowedExt == null ? "" : allowedExt));
}
-}
\ No newline at end of file
+}
--
Gitblit v1.7.1