소스 검색

ObjectType 中添加一个 Any 枚举, 表示任意文件

reghao 1 년 전
부모
커밋
380872806c

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

@@ -13,9 +13,11 @@ public enum ObjectType {
     Video(1002, "Video"),
     Audio(1003, "Audio"),
     Text(1004, "Text"),
-    Other(1005, "Application");
+    Other(1005, "Application"),
+    Any(1006, "*/*");
 
     private final int code;
+    // contentType 的值不能改变, 代码中会使用它作为前缀和上传文件的 content-type 进行比较
     private final String contentType;
     ObjectType(int code, String contentType) {
         this.code = code;

+ 1 - 0
oss-api/src/main/java/cn/reghao/oss/api/iface/ConsoleService.java

@@ -17,4 +17,5 @@ public interface ConsoleService {
     ObjectChannel getChannelByCode(int owner, int channelCode);
     Integer getChannelCodeByUrl(int owner, String url);
     ServerInfo getUploadStore(int channelCode);
+    ServerInfo getUploadStore(int channelCode, int owner);
 }

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

@@ -32,9 +32,13 @@ public class ChannelValidateService {
             return Result.fail(errMsg);
         }
 
+        if (fileType == ObjectType.Any.getCode()) {
+            return Result.success();
+        }
+
         String contentType = ObjectType.getDescByCode(fileType).toLowerCase(Locale.ROOT);
         String mediaType = FileType.getMediaType(file.getAbsolutePath());
-        if (!contentType.equals(ObjectType.Other.getDesc()) && !mediaType.startsWith(contentType)) {
+        if (!mediaType.startsWith(contentType)) {
             String errMsg = String.format("channel validate failed, the format of file is not %s", contentType);
             return Result.fail(errMsg);
         }