Browse Source

对不同 channel 上传的文件进行验证

reghao 2 năm trước cách đây
mục cha
commit
7d585d0c05

+ 8 - 0
dfs-store/src/main/java/cn/reghao/dfs/store/service/ChannelValidateService.java

@@ -29,6 +29,8 @@ public class ChannelValidateService {
                 return validatePhoto(file);
             case audio:
                 return validateAudio(file);
+            case image:
+                return validateImage(file);
             default:
                 log.info("{} 的文件暂时无法处理", channel.getPrefix());
                 return false;
@@ -64,4 +66,10 @@ public class ChannelValidateService {
         String mediaType = FileType.getMediaType(file.getAbsolutePath());
         return mediaType.startsWith("audio");
     }
+
+    private boolean validateImage(File file) {
+        String mediaType = FileType.getMediaType(file.getAbsolutePath());
+        long len = file.length();
+        return len < 1024*1024*10 && mediaType.startsWith("image");
+    }
 }

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

@@ -19,7 +19,9 @@ public enum UploadChannel {
     // 用户状态照片上传
     photo(5, "image/photo/"),
     // 音频上传
-    audio(6, "audio/playback/");
+    audio(6, "audio/playback/"),
+    // 图片上传
+    image(7, "i/");
 
     private final int code;
     private final String prefix;