Просмотр исходного кода

ChannelValidateService 中会使用 ObjectType 的 contentType 字段

reghao 1 год назад
Родитель
Сommit
e8dc587f20

+ 11 - 11
oss-api/src/main/java/cn/reghao/oss/api/constant/ObjectType.java

@@ -8,18 +8,18 @@ import java.util.Map;
  * @date 2023-06-13 15:09:09
  * @date 2023-06-13 15:09:09
  */
  */
 public enum ObjectType {
 public enum ObjectType {
-    Dir(1000, "directory"),
-    Image(1001, "image"),
-    Video(1002, "video"),
-    Audio(1003, "audio"),
-    Text(1004, "text"),
-    Other(1005, "application");
+    Dir(1000, "Dir"),
+    Image(1001, "Image"),
+    Video(1002, "Video"),
+    Audio(1003, "Audio"),
+    Text(1004, "Text"),
+    Other(1005, "Application");
 
 
     private final int code;
     private final int code;
-    private final String desc;
-    ObjectType(int code, String desc) {
+    private final String contentType;
+    ObjectType(int code, String contentType) {
         this.code = code;
         this.code = code;
-        this.desc = desc;
+        this.contentType = contentType;
     }
     }
 
 
     private static Map<Integer, ObjectType> map = new HashMap<>();
     private static Map<Integer, ObjectType> map = new HashMap<>();
@@ -32,7 +32,7 @@ public enum ObjectType {
     private static Map<Integer, String> descMap = new HashMap<>();
     private static Map<Integer, String> descMap = new HashMap<>();
     static {
     static {
         for (ObjectType objectType : ObjectType.values()) {
         for (ObjectType objectType : ObjectType.values()) {
-            descMap.put(objectType.code, objectType.desc);
+            descMap.put(objectType.code, objectType.contentType);
         }
         }
     }
     }
 
 
@@ -56,7 +56,7 @@ public enum ObjectType {
     }
     }
 
 
     public String getDesc() {
     public String getDesc() {
-        return desc;
+        return contentType;
     }
     }
 
 
     public static String getDescByCode(int code) {
     public static String getDescByCode(int code) {

+ 2 - 1
oss-store/src/main/java/cn/reghao/oss/store/service/ChannelValidateService.java

@@ -8,6 +8,7 @@ import lombok.extern.slf4j.Slf4j;
 import org.springframework.stereotype.Service;
 import org.springframework.stereotype.Service;
 
 
 import java.io.File;
 import java.io.File;
+import java.util.Locale;
 
 
 /**
 /**
  * @author reghao
  * @author reghao
@@ -31,7 +32,7 @@ public class ChannelValidateService {
             return Result.fail(errMsg);
             return Result.fail(errMsg);
         }
         }
 
 
-        String contentType = ObjectType.getDescByCode(fileType);
+        String contentType = ObjectType.getDescByCode(fileType).toLowerCase(Locale.ROOT);
         String mediaType = FileType.getMediaType(file.getAbsolutePath());
         String mediaType = FileType.getMediaType(file.getAbsolutePath());
         if (!contentType.equals(ObjectType.Other.getDesc()) && !mediaType.startsWith(contentType)) {
         if (!contentType.equals(ObjectType.Other.getDesc()) && !mediaType.startsWith(contentType)) {
             String errMsg = String.format("channel validate failed, the format of file is not %s", contentType);
             String errMsg = String.format("channel validate failed, the format of file is not %s", contentType);