Kaynağa Gözat

oss-store 中使用 ObjectChannel 来代替 UploadChannel

reghao 2 yıl önce
ebeveyn
işleme
e113fbe1b3

+ 14 - 6
oss-store/src/main/java/cn/reghao/oss/store/controller/ObjectGetController.java

@@ -1,12 +1,13 @@
 package cn.reghao.oss.store.controller;
 
 import cn.reghao.oss.api.constant.ChannelAction;
+import cn.reghao.oss.api.dto.ObjectChannel;
 import cn.reghao.oss.store.config.OssProperties;
 import cn.reghao.oss.store.service.GetObjectService;
+import cn.reghao.oss.store.service.ObjectChannelService;
 import cn.reghao.oss.store.util.JwtUtil;
 import cn.reghao.oss.store.util.ObjectUtil;
 import cn.reghao.oss.store.util.SignatureUtil;
-import cn.reghao.oss.api.constant.UploadChannel;
 import cn.reghao.oss.api.dto.OssPayload;
 import com.github.benmanes.caffeine.cache.Cache;
 import com.github.benmanes.caffeine.cache.Caffeine;
@@ -25,11 +26,14 @@ public class ObjectGetController {
     private final GetObjectService getObjectService;
     private final Cache<String, String> cache;
     private final OssProperties ossProperties;
+    private final ObjectChannelService objectChannelService;
 
-    public ObjectGetController(GetObjectService getObjectService, OssProperties ossProperties) {
+    public ObjectGetController(GetObjectService getObjectService, OssProperties ossProperties,
+                               ObjectChannelService objectChannelService) {
         this.getObjectService = getObjectService;
         this.cache = Caffeine.newBuilder().maximumSize(10_000).expireAfterAccess(1, TimeUnit.HOURS).build();
         this.ossProperties = ossProperties;
+        this.objectChannelService = objectChannelService;
     }
 
     @RequestMapping(value = "/**", method = RequestMethod.HEAD)
@@ -54,9 +58,7 @@ public class ObjectGetController {
             return;
         }
 
-        if (objectName.startsWith(UploadChannel.avatar.getPrefix())
-                || objectName.startsWith(UploadChannel.image.getPrefix())
-                || objectName.startsWith(UploadChannel.img.getPrefix())) {
+        if (objectName.startsWith("/image/a/") || objectName.startsWith("/image/i/") || objectName.startsWith("/img/")) {
             getObjectService.getObject(objectName);
             return;
         }
@@ -87,8 +89,14 @@ public class ObjectGetController {
 
         OssPayload ossPayload = JwtUtil.getOssPayload(token, ossProperties.getSecretKey());
         int channelId = ossPayload.getChannelId();
+        ObjectChannel objectChannel = objectChannelService.getObjectChannel(channelId);
+        if (objectChannel == null) {
+            getObjectService.writeResponse(HttpServletResponse.SC_FORBIDDEN);
+            return;
+        }
+
         long userId = ossPayload.getUserId();
-        String prefix = UploadChannel.getUploadChannel(channelId).getPrefix();
+        String prefix = objectChannel.getPrefix();
         if (!objectName.startsWith(prefix)) {
             getObjectService.writeResponse(HttpServletResponse.SC_FORBIDDEN);
             return;

+ 20 - 24
oss-store/src/main/java/cn/reghao/oss/store/controller/ObjectUploadController.java

@@ -56,35 +56,31 @@ public class ObjectUploadController {
     }
 
     @PostMapping(value = "/", produces = MediaType.APPLICATION_JSON_VALUE)
-    public ResponseEntity<String> postObject(MultipartFile file, Integer channelId,
-                                             String client, String sha256sum, Long userId) throws Exception {
+    public ResponseEntity<String> postObject(MultipartFile file, Integer channelId, String objectName,
+                                             String client, String sha256sum) throws Exception {
         /* permission check */
-        if (client == null) {
-            String token = ServletUtil.getBearerToken();
-            if (token == null) {
-                return ResponseEntity.status(HttpStatus.UNAUTHORIZED)
-                        .body(WebResult.failWithMsg("no token in request"));
-            }
-
-            OssPayload ossPayload = JwtUtil.getOssPayload(token, ossProperties.getSecretKey());
-            String action = ossPayload.getAction();
-            if (!"upload".equals(action)) {
-                return ResponseEntity.status(HttpStatus.FORBIDDEN)
-                        .body(WebResult.failWithMsg("it's not upload token"));
-            }
+        String token = ServletUtil.getBearerToken();
+        if (token == null) {
+            return ResponseEntity.status(HttpStatus.UNAUTHORIZED)
+                    .body(WebResult.failWithMsg("no token in request"));
+        }
 
-            int channelId1 = ossPayload.getChannelId();
-            if (channelId != channelId1) {
-                return ResponseEntity.status(HttpStatus.FORBIDDEN)
-                        .body(WebResult.failWithMsg("channel not match in token"));
-            }
+        OssPayload ossPayload = JwtUtil.getOssPayload(token, ossProperties.getSecretKey());
+        String action = ossPayload.getAction();
+        if (!"upload".equals(action)) {
+            return ResponseEntity.status(HttpStatus.FORBIDDEN)
+                    .body(WebResult.failWithMsg("it's not upload token"));
+        }
 
-            long userId1 = ossPayload.getUserId();
-            UserContext context = new UserContext(userId1);
-        } else {
-            UserContext context = new UserContext(userId);
+        int channelId1 = ossPayload.getChannelId();
+        if (channelId != channelId1) {
+            return ResponseEntity.status(HttpStatus.FORBIDDEN)
+                    .body(WebResult.failWithMsg("channel not match in token"));
         }
 
+        long userId1 = ossPayload.getUserId();
+        UserContext context = new UserContext(userId1);
+
         /* channel validate */
         String contentId = UUID.randomUUID().toString().replace("-", "");
         long size = file.getSize();

+ 1 - 4
oss-store/src/main/java/cn/reghao/oss/store/inerceptor/AccessLogInterceptor.java

@@ -1,9 +1,7 @@
 package cn.reghao.oss.store.inerceptor;
 
 import cn.reghao.jutil.web.ServletUtil;
-import cn.reghao.oss.api.constant.UploadChannel;
 import cn.reghao.oss.store.config.OssProperties;
-import cn.reghao.oss.store.util.ObjectUtil;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.lang.Nullable;
 import org.springframework.stereotype.Component;
@@ -12,7 +10,6 @@ import org.springframework.web.servlet.ModelAndView;
 
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
-import java.util.List;
 
 /**
  * 访问日志拦截器
@@ -46,7 +43,7 @@ public class AccessLogInterceptor implements HandlerInterceptor {
         }
 
         String objectName = uri.replaceFirst("/", "");
-        if (objectName.startsWith(UploadChannel.img.getPrefix())) {
+        if (objectName.startsWith("img/")) {
             return true;
         } else if (referer == null || !referer.contains(referFrom)) {
             log.error("request object {} from {} has been blocked", uri, referer);

+ 2 - 4
oss-store/src/main/java/cn/reghao/oss/store/model/po/FileMeta.java

@@ -46,7 +46,7 @@ public class FileMeta extends BaseObject<Integer> {
     }
 
     public FileMeta(String objectName, String objectId, String contentId, String filename, long size,
-                    int fileType, String contentType, String sha256sum, String pid, boolean diskFile, int scope) {
+                    int fileType, String contentType, String sha256sum, String pid, int scope) {
         this.objectName = objectName;
         this.objectId = objectId;
         this.contentId = contentId;
@@ -57,11 +57,10 @@ public class FileMeta extends BaseObject<Integer> {
         this.sha256sum = sha256sum;
         this.pid = pid;
         this.uploadBy = UserContext.getUser();
-        this.diskFile = diskFile;
         this.scope = scope;
     }
 
-    public FileMeta(String objectName, String objectId, String filename, FileMeta fileMeta, boolean diskFile, int scope) {
+    public FileMeta(String objectName, String objectId, String filename, FileMeta fileMeta, int scope) {
         this.objectName = objectName;
         this.objectId = objectId;
         this.contentId = fileMeta.getContentId();
@@ -72,7 +71,6 @@ public class FileMeta extends BaseObject<Integer> {
         this.sha256sum = fileMeta.getSha256sum();
         this.pid = fileMeta.getPid();
         this.uploadBy = UserContext.getUser();
-        this.diskFile = diskFile;
         this.scope = scope;
     }
 }

+ 0 - 1
oss-store/src/main/java/cn/reghao/oss/store/model/vo/ObjectProp.java

@@ -11,7 +11,6 @@ import lombok.Getter;
 @Getter
 public class ObjectProp {
     private String objectName;
-    private boolean diskFile;
     private int scope;
     private String pid;
 }

+ 0 - 31
oss-store/src/main/java/cn/reghao/oss/store/rpc/ChannelServiceImpl.java

@@ -1,31 +0,0 @@
-package cn.reghao.oss.store.rpc;
-
-import cn.reghao.oss.api.constant.UploadChannel;
-import cn.reghao.oss.api.dto.ChannelDto;
-import cn.reghao.oss.api.iface.ChannelService;
-import org.apache.dubbo.config.annotation.DubboService;
-import org.springframework.stereotype.Service;
-
-import java.util.ArrayList;
-import java.util.List;
-
-/**
- * @author reghao
- * @date 2023-06-02 10:28:28
- */
-@DubboService
-@Service
-public class ChannelServiceImpl implements ChannelService {
-    @Override
-    public List<ChannelDto> getChannels() {
-        List<ChannelDto> list = new ArrayList<>();
-        for (UploadChannel channel : UploadChannel.values()) {
-            int channelId = channel.getCode();
-            String channelPrefix = channel.getPrefix();
-            String channelName = channel.name();
-            list.add(new ChannelDto(channelPrefix, channelId, channelName));
-        }
-
-        return list;
-    }
-}

+ 1 - 2
oss-store/src/main/java/cn/reghao/oss/store/rpc/ObjectServiceImpl.java

@@ -9,7 +9,6 @@ import cn.reghao.oss.store.service.ObjectNameService;
 import cn.reghao.oss.store.util.JwtUtil;
 import cn.reghao.oss.store.util.SignatureUtil;
 import cn.reghao.oss.api.constant.ChannelAction;
-import cn.reghao.oss.api.constant.UploadChannel;
 import cn.reghao.oss.api.iface.ObjectService;
 import cn.reghao.oss.store.db.mapper.FileMetaMapper;
 import org.apache.dubbo.config.annotation.DubboService;
@@ -75,7 +74,7 @@ public class ObjectServiceImpl implements ObjectService {
         long timestamp = System.currentTimeMillis() + 3600*1000;
 
         String action = ChannelAction.download.getName();
-        OssPayload ossPayload = new OssPayload(action, UploadChannel.video.getCode(), loginUser);
+        OssPayload ossPayload = new OssPayload(action, 102, loginUser);
         String token = JwtUtil.createToken(ossPayload, timestamp, secretKey);
         String nonce = UUID.randomUUID().toString();
         String queryString = String.format("token=%s&t=%s&nonce=%s", token, timestamp, nonce);

+ 24 - 47
oss-store/src/main/java/cn/reghao/oss/store/service/ChannelValidateService.java

@@ -1,9 +1,9 @@
 package cn.reghao.oss.store.service;
 
+import cn.reghao.oss.api.constant.ObjectType;
+import cn.reghao.oss.api.dto.ObjectChannel;
 import cn.reghao.oss.store.util.FileType;
 import cn.reghao.jutil.jdk.result.Result;
-import cn.reghao.oss.api.constant.SupportedMedia;
-import cn.reghao.oss.api.constant.UploadChannel;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.stereotype.Service;
 
@@ -16,64 +16,41 @@ import java.io.File;
 @Slf4j
 @Service
 public class ChannelValidateService {
-    public Result validate(File file, int channelId) {
-        UploadChannel channel = UploadChannel.getUploadChannel(channelId);
-        switch (channel) {
-            case disk:
-                return Result.success();
-            case video:
-                return validateVideo(file);
-            case audio:
-                return validateAudio(file);
-            case avatar:
-                return validateImage(file, UploadChannel.avatar.getMaxSize());
-            case image:
-            case img:
-                return validateImage(file, UploadChannel.image.getMaxSize());
-            case photo:
-                return validateImage(file, UploadChannel.photo.getMaxSize());
-            default:
-                String errMsg = String.format("%s 的文件暂时无法处理", channel.getPrefix());
-                return Result.fail(errMsg);
-        }
+    private final ObjectChannelService objectChannelService;
+
+    public ChannelValidateService(ObjectChannelService objectChannelService) {
+        this.objectChannelService = objectChannelService;
     }
 
-    private Result validateVideo(File file) {
-        String mediaType = FileType.getMediaType(file.getAbsolutePath());
-        long maxSize = UploadChannel.video.getMaxSize();
-        long len = file.length();
-        if (len > maxSize) {
-            String errMsg = String.format("视频文件大小不能超过 %s bytes", maxSize);
+    public Result validate(File file, int channelId) {
+        ObjectChannel objectChannel = objectChannelService.getObjectChannel(channelId);
+        if (objectChannel == null) {
+            String errMsg = String.format("channel validate failed, channel %s not exist", channelId);
             return Result.fail(errMsg);
-        } else if (!mediaType.startsWith("video")) {
-            return Result.fail("非视频文件格式");
         }
 
-        return Result.success();
+        return validateFile(file, objectChannel);
     }
 
-    private Result validateAudio(File file) {
-        String mediaType = FileType.getMediaType(file.getAbsolutePath());
-        long maxSize = UploadChannel.audio.getMaxSize();
-        long len = file.length();
-        if (len > maxSize) {
-            String errMsg = String.format("音频文件大小不能超过 %s bytes", maxSize);
+    private Result validateFile(File file, ObjectChannel objectChannel) {
+        int fileType = objectChannel.getFileType();
+        ObjectType objectType = ObjectType.getByCode(fileType);
+        if (objectType == null) {
+            String errMsg = String.format("channel validate failed, file_type %s not exist", fileType);
             return Result.fail(errMsg);
-        } else if (!mediaType.startsWith("audio")) {
-            return Result.fail("非音频文件格式");
         }
 
-        return Result.success();
-    }
-
-    private Result validateImage(File file, long maxSize) {
-        String mediaType = FileType.getMediaType(file.getAbsolutePath());
+        long maxSize = objectChannel.getMaxSize();
         long len = file.length();
         if (len > maxSize) {
-            String errMsg = String.format("图片文件大小不能超过 %s bytes", maxSize);
+            String errMsg = String.format("channel validate failed, the size of %s file bigger than %s bytes", objectType.name(), maxSize);
             return Result.fail(errMsg);
-        } else if (!SupportedMedia.imageFormats.contains(mediaType.replace("image/", ""))) {
-            String errMsg = String.format("系统仅支持 %s 等图片格式", SupportedMedia.imageFormats);
+        }
+
+        String contentType = ObjectType.getDescByCode(fileType);
+        String mediaType = FileType.getMediaType(file.getAbsolutePath());
+        if (!mediaType.startsWith(contentType)) {
+            String errMsg = String.format("channel validate failed, the format of file is not %s", contentType);
             return Result.fail(errMsg);
         }
 

+ 32 - 0
oss-store/src/main/java/cn/reghao/oss/store/service/ObjectChannelService.java

@@ -0,0 +1,32 @@
+package cn.reghao.oss.store.service;
+
+import cn.reghao.jutil.jdk.machine.id.MachineId;
+import cn.reghao.oss.api.dto.ObjectChannel;
+import cn.reghao.oss.sdk.OssConsoleClient;
+import org.springframework.stereotype.Service;
+
+/**
+ * @author reghao
+ * @date 2024-02-28 11:05:34
+ */
+@Service
+public class ObjectChannelService {
+    private final MachineId machineId;
+    private final OssConsoleClient ossConsoleClient;
+
+    public ObjectChannelService(MachineId machineId, OssConsoleClient ossConsoleClient) {
+        this.machineId = machineId;
+        this.ossConsoleClient = ossConsoleClient;
+    }
+
+    public ObjectChannel getObjectChannel(int channelId) {
+        String nodeAddr = machineId.ipv4();
+        try {
+            return ossConsoleClient.getObjectChannel(nodeAddr, channelId);
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+
+        return null;
+    }
+}

+ 13 - 22
oss-store/src/main/java/cn/reghao/oss/store/service/ObjectNameService.java

@@ -1,12 +1,11 @@
 package cn.reghao.oss.store.service;
 
+import cn.reghao.oss.api.dto.ObjectChannel;
 import cn.reghao.oss.store.config.OssProperties;
 import cn.reghao.oss.store.db.repository.ObjectRepository;
 import cn.reghao.oss.store.model.po.FileMeta;
 import cn.reghao.oss.store.model.vo.ObjectProp;
 import cn.reghao.oss.store.util.StringUtil;
-import cn.reghao.oss.api.constant.ObjectScope;
-import cn.reghao.oss.api.constant.UploadChannel;
 import org.springframework.stereotype.Service;
 
 import java.util.ArrayList;
@@ -21,35 +20,30 @@ import java.util.UUID;
 public class ObjectNameService {
     private final ObjectRepository objectRepository;
     private final String domain;
+    private final ObjectChannelService objectChannelService;
 
-    public ObjectNameService(ObjectRepository objectRepository, OssProperties ossProperties) {
+    public ObjectNameService(ObjectRepository objectRepository, OssProperties ossProperties,
+                             ObjectChannelService objectChannelService) {
         this.objectRepository = objectRepository;
         this.domain = ossProperties.getDomain();
+        this.objectChannelService = objectChannelService;
     }
 
     public String getObjectUrl(String objectName) {
         return String.format("//%s/%s", domain, objectName);
     }
 
-    public String getObjectNameFromUrl(String url) {
-        return url.replace(String.format("//%s/", domain), "");
-    }
-
     public ObjectProp getObjectProp(int channelId, String filename) throws Exception {
-        String suffix = StringUtil.getSuffix(filename);
-        UploadChannel channel = UploadChannel.getUploadChannel(channelId);
+        ObjectChannel channel = objectChannelService.getObjectChannel(channelId);
         if (channel == null) {
-            throw new Exception("channelId 不合法");
+            String errMsg = String.format("channel_id %s illegal", channelId);
+            throw new Exception(errMsg);
         }
 
+        int scope = channel.getScope();
+        String suffix = StringUtil.getSuffix(filename);
         String objectPrefix = channel.getPrefix();
         String objectName = objectPrefix + UUID.randomUUID().toString().replace("-", "") + suffix;
-        boolean diskFile = channelId == UploadChannel.disk.getCode();
-        int scope = ObjectScope.PRIVATE.getCode();
-        if (channelId == UploadChannel.avatar.getCode() || channelId == UploadChannel.image.getCode()) {
-            scope = ObjectScope.PUBLIC.getCode();
-        }
-
         FileMeta fileMeta = objectRepository.getByObjectName(objectPrefix);
         if (fileMeta == null) {
             String errMsg = String.format("objectPrefix %s 不合法", objectPrefix);
@@ -57,21 +51,18 @@ public class ObjectNameService {
         }
 
         String pid = fileMeta.getObjectId();
-        return new ObjectProp(objectName, diskFile, scope, pid);
+        return new ObjectProp(objectName, scope, pid);
     }
 
     public ObjectProp getObjectProp(String originalObjectName, String suffix) {
         int idx = originalObjectName.lastIndexOf("/");
         String prefix = originalObjectName.substring(0, idx+1);
-        UploadChannel channel = UploadChannel.getUploadChannel(prefix);
         FileMeta fileMeta = objectRepository.getByObjectName(originalObjectName);
-        boolean diskFile = fileMeta.getDiskFile();
         int scope = fileMeta.getScope();
         String pid = fileMeta.getPid();
 
-        String objectPrefix = channel.getPrefix();
-        String objectName = objectPrefix + UUID.randomUUID().toString().replace("-", "") + suffix;
-        return new ObjectProp(objectName, diskFile, scope, pid);
+        String objectName = prefix + UUID.randomUUID().toString().replace("-", "") + suffix;
+        return new ObjectProp(objectName, scope, pid);
     }
 
     public String getObjectNameFromOriginal(String originalObjectName, String suffix) {

+ 4 - 8
oss-store/src/main/java/cn/reghao/oss/store/service/PutObjectService.java

@@ -44,11 +44,9 @@ public class PutObjectService {
             String objectId = UUID.randomUUID().toString().replace("-", "");
             String contentType = FileType.getMediaType(savedPath);
             int fileType = FileType.getFileType(contentType);
-
-            boolean diskFile = objectProp.isDiskFile();
             int scope = objectProp.getScope();
             fileMeta = new FileMeta(objectName, objectId, contentId, originalFilename, size,
-                    fileType, contentType, sha256sum, pid, diskFile, scope);
+                    fileType, contentType, sha256sum, pid, scope);
             String blockId = UUID.randomUUID().toString();
             List<DataBlock> list = List.of(new DataBlock(contentId, 0, blockId, savedPath, size));
             objectRepository.saveObject(fileMeta, list);
@@ -67,9 +65,8 @@ public class PutObjectService {
         String savedPath = objectMeta.getAbsolutePath();
         String objectName = objectProp.getObjectName();
         String objectId = UUID.randomUUID().toString().replace("-", "");
-        boolean diskFile = objectProp.isDiskFile();
         int scope = objectProp.getScope();
-        FileMeta fileMeta1 = new FileMeta(objectName, objectId, filename, fileMeta, diskFile, scope);
+        FileMeta fileMeta1 = new FileMeta(objectName, objectId, filename, fileMeta, scope);
         objectRepository.saveFileMeta(fileMeta1);
         return new ObjectResult(objectName, objectId, fileType, savedPath, dupObjectId);
     }
@@ -85,7 +82,7 @@ public class PutObjectService {
         int scope = fileMeta.getScope();
         String toObjectName = objectNameService.getObjectNameFromOriginal(fromObjectName, suffix);
         String toObjectId = UUID.randomUUID().toString().replace("-", "");
-        FileMeta fileMeta1 = new FileMeta(toObjectName, toObjectId, filename, fileMeta, diskFile, scope);
+        FileMeta fileMeta1 = new FileMeta(toObjectName, toObjectId, filename, fileMeta, scope);
         objectRepository.saveFileMeta(fileMeta1);
         return new ObjectResult(toObjectName, toObjectId, fileType, savedPath);
     }
@@ -98,11 +95,10 @@ public class PutObjectService {
         String suffix = StringUtil.getSuffix(fromObjectName);
         String filename = fileMeta.getFilename();
         String savedPath = "";
-        boolean diskFile = fileMeta.getDiskFile();
         int scope = fileMeta.getScope();
         String toObjectName = objectNameService.getObjectNameFromOriginal(fromObjectName, suffix);
         String toObjectId = UUID.randomUUID().toString().replace("-", "");
-        FileMeta fileMeta1 = new FileMeta(toObjectName, toObjectId, filename, fileMeta, diskFile, scope);
+        FileMeta fileMeta1 = new FileMeta(toObjectName, toObjectId, filename, fileMeta, scope);
         objectRepository.saveFileMeta(fileMeta1);
         return new ObjectResult(toObjectName, toObjectId, fileType, savedPath);
     }

+ 6 - 5
oss-store/src/main/java/cn/reghao/oss/store/task/FileProcessor.java

@@ -1,20 +1,19 @@
 package cn.reghao.oss.store.task;
 
+import cn.reghao.oss.api.dto.ObjectChannel;
 import cn.reghao.oss.store.db.repository.ImageRepository;
 import cn.reghao.oss.store.model.vo.ObjectResult;
+import cn.reghao.oss.store.service.ObjectChannelService;
 import cn.reghao.oss.store.task.processor.AudioFileProcessor;
 import cn.reghao.oss.store.task.processor.DiskFileProcessor;
 import cn.reghao.oss.store.task.processor.ImageFileProcessor;
 import cn.reghao.oss.store.task.processor.VideoFileProcessor;
-import cn.reghao.jutil.jdk.thread.ThreadPoolWrapper;
 import cn.reghao.oss.api.constant.ObjectType;
 import cn.reghao.oss.api.constant.UploadChannel;
 import cn.reghao.oss.api.rest.UploadFileRet;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.stereotype.Service;
 
-import java.util.concurrent.ExecutorService;
-
 /**
  * @author reghao
  * @date 2023-05-22 18:11:03
@@ -22,21 +21,22 @@ import java.util.concurrent.ExecutorService;
 @Slf4j
 @Service
 public class FileProcessor {
-    private final ExecutorService threadPool = ThreadPoolWrapper.threadPool("file-processor", 10);
     private final ImageFileProcessor imageFileProcessor;
     private final VideoFileProcessor videoFileProcessor;
     private final AudioFileProcessor audioFileProcessor;
     private final DiskFileProcessor diskFileProcessor;
     private final ImageRepository imageRepository;
+    private final ObjectChannelService objectChannelService;
 
     public FileProcessor(ImageFileProcessor imageFileProcessor, VideoFileProcessor videoFileProcessor,
                          AudioFileProcessor audioFileProcessor, DiskFileProcessor diskFileProcessor,
-                         ImageRepository imageRepository) {
+                         ImageRepository imageRepository, ObjectChannelService objectChannelService) {
         this.imageFileProcessor = imageFileProcessor;
         this.videoFileProcessor = videoFileProcessor;
         this.audioFileProcessor = audioFileProcessor;
         this.diskFileProcessor = diskFileProcessor;
         this.imageRepository = imageRepository;
+        this.objectChannelService = objectChannelService;
     }
 
     public UploadFileRet process(ObjectResult objectResult, int channelId) throws Exception {
@@ -45,6 +45,7 @@ public class FileProcessor {
         ObjectType objectType = ObjectType.getByCode(fileType);
         UploadFileRet uploadFileRet = null;
 
+        ObjectChannel channel1 = objectChannelService.getObjectChannel(channelId);
         UploadChannel channel = UploadChannel.getUploadChannel(channelId);
         switch (channel) {
             case disk:

+ 0 - 15
oss-store/src/test/java/FileMetaTest.java

@@ -4,13 +4,9 @@ import cn.reghao.oss.store.db.mapper.FileMetaMapper;
 import cn.reghao.oss.store.model.po.DataBlock;
 import cn.reghao.oss.store.model.po.FileMeta;
 import cn.reghao.jutil.jdk.store.SubDirCount;
-import cn.reghao.oss.store.service.ObjectNameService;
-import cn.reghao.oss.store.util.UserContext;
 import cn.reghao.jutil.jdk.db.Page;
 import cn.reghao.jutil.jdk.security.DigestUtil;
 import cn.reghao.jutil.jdk.thread.ThreadPoolWrapper;
-import cn.reghao.oss.api.constant.ObjectScope;
-import cn.reghao.oss.api.constant.UploadChannel;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.io.FileUtils;
 import org.junit.Test;
@@ -155,17 +151,6 @@ public class FileMetaTest {
         }
     }
 
-    @Autowired
-    ObjectNameService objectNameService;
-    @Test
-    public void initUploadChannel() {
-        UserContext userContext = new UserContext(10001L);
-        for (UploadChannel channel : UploadChannel.values()) {
-            String objectName = channel.getPrefix();
-            objectNameService.createParentDirs(objectName, ObjectScope.PUBLIC.getCode());
-        }
-    }
-
     @Autowired
     DataBlockMapper dataBlockMapper;
     @Test