Prechádzať zdrojové kódy

一大波更新, 懒得详细写了, 最大的变化是 oss-console 和 oss-store 之间采用 rpc 通信

reghao 1 rok pred
rodič
commit
ec806b7ff5
58 zmenil súbory, kde vykonal 369 pridanie a 715 odobranie
  1. 3 2
      oss-console/src/main/java/cn/reghao/oss/console/app/controller/OssServerController.java
  2. 18 0
      oss-console/src/main/java/cn/reghao/oss/console/app/controller/page/StoreObjectPageController.java
  3. 4 4
      oss-console/src/main/java/cn/reghao/oss/console/app/db/repository/UploadChannelRepository.java
  4. 1 1
      oss-console/src/main/java/cn/reghao/oss/console/app/db/repository/UserKeyRepository.java
  5. 2 2
      oss-console/src/main/java/cn/reghao/oss/console/app/db/repository/UserNodeRepository.java
  6. 5 0
      oss-console/src/main/java/cn/reghao/oss/console/app/model/po/StoreNode.java
  7. 2 2
      oss-console/src/main/java/cn/reghao/oss/console/app/model/po/UploadChannel.java
  8. 1 1
      oss-console/src/main/java/cn/reghao/oss/console/app/model/po/UserKey.java
  9. 5 2
      oss-console/src/main/java/cn/reghao/oss/console/app/model/po/UserNode.java
  10. 5 4
      oss-console/src/main/java/cn/reghao/oss/console/app/model/vo/StoreNodeVO.java
  11. 3 2
      oss-console/src/main/java/cn/reghao/oss/console/app/rpc/MediaRpcService.java
  12. 4 3
      oss-console/src/main/java/cn/reghao/oss/console/app/rpc/OssObjectService.java
  13. 22 22
      oss-console/src/main/java/cn/reghao/oss/console/app/rpc/OssService.java
  14. 0 4
      oss-console/src/main/java/cn/reghao/oss/console/app/service/StoreNodeService.java
  15. 11 12
      oss-console/src/main/java/cn/reghao/oss/console/app/service/UploadChannelService.java
  16. 4 4
      oss-console/src/main/java/cn/reghao/oss/console/app/service/UserKeyService.java
  17. 4 0
      oss-console/src/main/java/cn/reghao/oss/console/app/service/UserNodeService.java
  18. 1 1
      oss-console/src/main/java/cn/reghao/oss/console/config/web/ConsoleAuthInterceptor.java
  19. 84 0
      oss-console/src/main/java/cn/reghao/oss/console/rpc/NodeServiceImpl.java
  20. 3 3
      oss-console/src/main/java/cn/reghao/oss/console/util/AuthKeyContext.java
  21. 7 0
      oss-console/src/main/resources/application.yml
  22. 1 1
      oss-console/src/main/resources/templates/node/index.html
  23. 2 0
      oss-console/src/main/resources/templates/usernode/index1.html
  24. 3 29
      oss-console/src/test/java/OssConsoleTest.java
  25. 0 67
      oss-console/src/test/java/UploadChannel.java
  26. 2 2
      oss-sdk/src/main/java/cn/reghao/oss/sdk/OssConsoleClient.java
  27. 1 1
      oss-sdk/src/main/java/cn/reghao/oss/sdk/model/OssConsoleConfig.java
  28. 2 2
      oss-sdk/src/test/java/OssConsoleClientTest.java
  29. 12 1
      oss-store/README.md
  30. 4 3
      oss-store/bin/oss.yml
  31. 0 5
      oss-store/pom.xml
  32. 7 3
      oss-store/src/main/java/cn/reghao/oss/store/config/BeansConfig.java
  33. 5 18
      oss-store/src/main/java/cn/reghao/oss/store/config/SpringLifecycle.java
  34. 2 1
      oss-store/src/main/java/cn/reghao/oss/store/config/props/OssProperties.java
  35. 3 3
      oss-store/src/main/java/cn/reghao/oss/store/controller/ObjectGetController.java
  36. 4 4
      oss-store/src/main/java/cn/reghao/oss/store/controller/ObjectUploadController.java
  37. 0 5
      oss-store/src/main/java/cn/reghao/oss/store/db/mapper/DataBlockMapper.java
  38. 2 27
      oss-store/src/main/java/cn/reghao/oss/store/db/mapper/FileMetaMapper.java
  39. 2 2
      oss-store/src/main/java/cn/reghao/oss/store/inerceptor/TokenFilter.java
  40. 2 2
      oss-store/src/main/java/cn/reghao/oss/store/model/po/FileMeta.java
  41. 3 3
      oss-store/src/main/java/cn/reghao/oss/store/rpc/MediaServiceImpl.java
  42. 3 7
      oss-store/src/main/java/cn/reghao/oss/store/rpc/ObjectServiceImpl.java
  43. 33 0
      oss-store/src/main/java/cn/reghao/oss/store/rpc/RemoteService.java
  44. 4 28
      oss-store/src/main/java/cn/reghao/oss/store/rpc/StoreServiceImpl.java
  45. 1 0
      oss-store/src/main/java/cn/reghao/oss/store/service/FileStoreService.java
  46. 1 1
      oss-store/src/main/java/cn/reghao/oss/store/service/SignService.java
  47. 25 62
      oss-store/src/main/java/cn/reghao/oss/store/service/StoreLocalService.java
  48. 4 4
      oss-store/src/main/java/cn/reghao/oss/store/util/UserContext.java
  49. 0 36
      oss-store/src/main/resources/mapper/FileMetaMapper.xml
  50. 1 147
      oss-store/src/test/java/FileMetaTest.java
  51. 0 123
      oss-store/src/test/java/LocalFileTest.java
  52. 0 28
      store-api/src/main/java/cn/reghao/oss/storeapi/dto/DeleteFile.java
  53. 0 23
      store-api/src/main/java/cn/reghao/oss/storeapi/dto/FileInfo.java
  54. 33 0
      store-api/src/main/java/cn/reghao/oss/storeapi/dto/NodeProperties.java
  55. 1 1
      store-api/src/main/java/cn/reghao/oss/storeapi/dto/OssPayload.java
  56. 0 3
      store-api/src/main/java/cn/reghao/oss/storeapi/dto/StoreInfo.java
  57. 16 0
      store-api/src/main/java/cn/reghao/oss/storeapi/iface/NodeService.java
  58. 1 4
      store-api/src/main/java/cn/reghao/oss/storeapi/iface/StoreService.java

+ 3 - 2
oss-console/src/main/java/cn/reghao/oss/console/app/controller/OssServerController.java

@@ -33,14 +33,15 @@ public class OssServerController {
     @ApiOperation(value = "获取 oss-store 节点")
     @GetMapping(value = "/info", produces = MediaType.APPLICATION_JSON_VALUE)
     public String getServerInfo(@RequestParam("channelId") int channelId) throws Exception {
-        ServerInfo serverInfo = ossService.getServerInfo(channelId);
+        int loginUser = AuthKeyContext.getUser();
+        ServerInfo serverInfo = ossService.getServerInfo(channelId, loginUser);
         return WebResult.success(serverInfo);
     }
 
     @ApiOperation(value = "根据 channel_id 获取 UploadChannel")
     @GetMapping(value = "/channel", produces = MediaType.APPLICATION_JSON_VALUE)
     public String getChannel(@RequestParam("channelId") int channelId) {
-        long loginUser = AuthKeyContext.getUser();
+        int loginUser = AuthKeyContext.getUser();
         ObjectChannel objectChannel = uploadChannelService.getObjectChannelByChannelId(channelId, loginUser);
         return WebResult.success(objectChannel);
     }

+ 18 - 0
oss-console/src/main/java/cn/reghao/oss/console/app/controller/page/StoreObjectPageController.java

@@ -2,8 +2,11 @@ package cn.reghao.oss.console.app.controller.page;
 
 import cn.reghao.jutil.jdk.result.WebResult;
 import cn.reghao.oss.console.account.model.po.DiskFile;
+import cn.reghao.oss.console.account.service.UserContext;
+import cn.reghao.oss.console.app.rpc.OssService;
 import cn.reghao.oss.console.util.DefaultSetting;
 import cn.reghao.oss.console.util.db.PageSort;
+import cn.reghao.oss.storeapi.dto.ServerInfo;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
 import org.springframework.data.domain.Page;
@@ -21,6 +24,12 @@ import org.springframework.web.multipart.MultipartFile;
 @Controller
 @RequestMapping("/store/object")
 public class StoreObjectPageController {
+    private final OssService ossService;
+
+    public StoreObjectPageController(OssService ossService) {
+        this.ossService = ossService;
+    }
+
     @ApiOperation(value = "文件列表页面")
     @GetMapping(value = "/list")
     public String index(@RequestParam(value = "env", required = false) String env,
@@ -47,6 +56,15 @@ public class StoreObjectPageController {
     @ApiOperation(value = "文件上传页面")
     @GetMapping(value = "/upload")
     public String uploadPage(Model model) {
+        int loginUser = UserContext.getUser().getId();
+        int channelId = 105;
+        try {
+            ServerInfo serverInfo = ossService.getServerInfo(loginUser, channelId);
+            model.addAttribute("serverInfo", serverInfo);
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+
         return "/object/upload";
     }
 

+ 4 - 4
oss-console/src/main/java/cn/reghao/oss/console/app/db/repository/UploadChannelRepository.java

@@ -12,10 +12,10 @@ import java.util.List;
  * @date 2024-02-23 15:05:30
  */
 public interface UploadChannelRepository extends JpaRepository<UploadChannel, Integer> {
-    int countByCreateBy(long createBy);
-    List<UploadChannel> findByNodeIdAndCreateBy(int nodeId, long createBy);
-    UploadChannel findByChannelIdAndCreateBy(int channelId, long createBy);
-    UploadChannel findByPrefixAndCreateByAndNodeId(String prefix, long createBy, int nodeId);
+    int countByCreateBy(int createBy);
+    List<UploadChannel> findByNodeIdAndCreateBy(int nodeId, int createBy);
+    UploadChannel findByChannelIdAndCreateBy(int channelId, int createBy);
+    UploadChannel findByPrefixAndCreateByAndNodeId(String prefix, int createBy, int nodeId);
     UploadChannel findByPrefixAndNodeId(String prefix, int nodeId);
     List<UploadChannel> findByNodeId(int nodeId);
     Page<UploadChannel> findByCreateBy(int createBy, Pageable pageable);

+ 1 - 1
oss-console/src/main/java/cn/reghao/oss/console/app/db/repository/UserKeyRepository.java

@@ -8,6 +8,6 @@ import org.springframework.data.jpa.repository.JpaRepository;
  * @date 2024-02-27 10:35:53
  */
 public interface UserKeyRepository extends JpaRepository<UserKey, Integer> {
-    UserKey findByCreateBy(long createBy);
+    UserKey findByCreateBy(int createBy);
     UserKey findByAccessKeyId(String accessKeyId);
 }

+ 2 - 2
oss-console/src/main/java/cn/reghao/oss/console/app/db/repository/UserNodeRepository.java

@@ -12,6 +12,6 @@ import org.springframework.data.jpa.repository.JpaRepository;
  */
 public interface UserNodeRepository extends JpaRepository<UserNode, Integer> {
     int countByNodeId(int nodeId);
-    UserNode findByNodeIdAndUserId(int nodeId, long userId);
-    Page<UserNode> findByUserId(long userId, Pageable pageable);
+    UserNode findByNodeIdAndUserId(int nodeId, int userId);
+    Page<UserNode> findByUserId(int userId, Pageable pageable);
 }

+ 5 - 0
oss-console/src/main/java/cn/reghao/oss/console/app/model/po/StoreNode.java

@@ -33,9 +33,14 @@ public class StoreNode extends BaseEntity {
     @ElementCollection(targetClass = StoreDisk.class)
     @LazyCollection(LazyCollectionOption.FALSE)
     private List<StoreDisk> storeDisks;
+
+    @Deprecated
     private String domain;
+    @Deprecated
     private String referer;
+    @Deprecated
     private String secretKey;
+
     private Boolean enabled;
 
     public StoreNode(StoreNodeDto storeNodeDto) {

+ 2 - 2
oss-console/src/main/java/cn/reghao/oss/console/app/model/po/UploadChannel.java

@@ -27,9 +27,9 @@ public class UploadChannel extends BaseEntity {
     private Boolean seturl;
     private Integer scope;
     private Integer nodeId;
-    private Long createBy;
+    private Integer createBy;
 
-    public UploadChannel(int channelId, UploadChannelDto uploadChannelDto, long createBy) {
+    public UploadChannel(int channelId, UploadChannelDto uploadChannelDto, int createBy) {
         this.channelId = channelId;
         this.name = uploadChannelDto.getName();
         this.prefix = uploadChannelDto.getChannelPrefix();

+ 1 - 1
oss-console/src/main/java/cn/reghao/oss/console/app/model/po/UserKey.java

@@ -22,5 +22,5 @@ public class UserKey extends BaseEntity {
     @Column(unique = true)
     private String accessKeyId;
     private String accessKeySecret;
-    private Long createBy;
+    private Integer createBy;
 }

+ 5 - 2
oss-console/src/main/java/cn/reghao/oss/console/app/model/po/UserNode.java

@@ -20,9 +20,12 @@ import javax.persistence.Entity;
 @Entity
 public class UserNode extends BaseEntity {
     private Integer nodeId;
-    private Long userId;
+    private String domain;
+    private String secretKey;
+    private String referer;
+    private Integer userId;
 
-    public UserNode(UserNodeDto userNodeDto, long userId) {
+    public UserNode(UserNodeDto userNodeDto, int userId) {
         this.nodeId = userNodeDto.getNodeId();
         this.userId = userId;
     }

+ 5 - 4
oss-console/src/main/java/cn/reghao/oss/console/app/model/vo/StoreNodeVO.java

@@ -5,6 +5,7 @@ import cn.reghao.tnb.file.api.dto.ObjectChannel;
 import cn.reghao.oss.storeapi.dto.StoreInfo;
 import lombok.Getter;
 
+import java.util.Collections;
 import java.util.List;
 
 /**
@@ -27,9 +28,9 @@ public class StoreNodeVO {
         this.httpPort = storeNode.getHttpPort();
         this.rpcPort = storeNode.getRpcPort();
         this.storeDisks = storeDisks;
-        this.domain = storeInfo.getStoreProperties().getDomain();
-        this.referer = storeInfo.getStoreProperties().getReferer();
-        this.secretKey = storeInfo.getStoreProperties().getSecretKey();
-        this.objectChannels = storeInfo.getObjectChannels();
+        this.domain = "";
+        this.referer = "";
+        this.secretKey = "";
+        this.objectChannels = Collections.emptyList();
     }
 }

+ 3 - 2
oss-console/src/main/java/cn/reghao/oss/console/app/rpc/MediaRpcService.java

@@ -34,7 +34,7 @@ public class MediaRpcService {
     }
 
     public List<ConvertedImageInfo> getWebpInfo(int channelId, List<String> imageFileIds) throws Exception {
-        long loginUser = AuthKeyContext.getUser();
+        int loginUser = AuthKeyContext.getUser();
         MediaService mediaService = getMediaService(channelId);
         return mediaService.getWebpInfo(channelId, imageFileIds);
     }
@@ -45,7 +45,8 @@ public class MediaRpcService {
     }
 
     private MediaService getMediaService(int channelId) throws Exception {
-        StoreNode storeNode = uploadChannelService.getStoreNodeByChannelId(channelId);
+        int loginUser = 1;
+        StoreNode storeNode = uploadChannelService.getStoreNodeByChannelId(loginUser, channelId);
         if (storeNode == null) {
             String errMsg = String.format("channel_id %s not associate with any store_node", channelId);
             throw new Exception(errMsg);

+ 4 - 3
oss-console/src/main/java/cn/reghao/oss/console/app/rpc/OssObjectService.java

@@ -37,7 +37,7 @@ public class OssObjectService {
     }
 
     public void deleteByObjectUrl(String objectUrl) throws Exception {
-        long loginUser = AuthKeyContext.getUser();
+        int loginUser = AuthKeyContext.getUser();
         String domain = objectUrl.replace("//", "").split("/")[0];
         String objectName = objectUrl.replace("//" + domain + "/", "");
         List<UploadChannel> uploadChannels = uploadChannelService.getByDomainAndCreateBy(domain, loginUser);
@@ -58,13 +58,14 @@ public class OssObjectService {
 
     public ObjectInfo getObjectInfo(int channelId, String objectId) throws Exception {
         ObjectService objectService = getObjectService(channelId);
-        long loginUser = AuthKeyContext.getUser();
+        int loginUser = AuthKeyContext.getUser();
         int expireSecond = 3600;
         return objectService.getObjectInfo(channelId, objectId);
     }
 
     private ObjectService getObjectService(int channelId) throws Exception {
-        StoreNode storeNode = uploadChannelService.getStoreNodeByChannelId(channelId);
+        int loginUser = 1;
+        StoreNode storeNode = uploadChannelService.getStoreNodeByChannelId(loginUser, channelId);
         if (storeNode == null) {
             String errMsg = String.format("channel_id %s not associate with any store_node", channelId);
             throw new Exception(errMsg);

+ 22 - 22
oss-console/src/main/java/cn/reghao/oss/console/app/rpc/OssService.java

@@ -1,12 +1,13 @@
 package cn.reghao.oss.console.app.rpc;
 
-import cn.reghao.oss.console.app.service.StoreNodeService;
+import cn.reghao.oss.console.app.model.po.UserNode;
 import cn.reghao.oss.console.app.service.UploadChannelService;
+import cn.reghao.oss.console.app.service.UserNodeService;
+import cn.reghao.oss.console.util.JwtUtil;
+import cn.reghao.oss.storeapi.dto.OssPayload;
 import cn.reghao.oss.storeapi.dto.ServerInfo;
-import cn.reghao.oss.storeapi.iface.StoreService;
-import cn.reghao.oss.console.app.model.po.StoreNode;
 import cn.reghao.oss.console.app.model.po.UploadChannel;
-import cn.reghao.oss.console.util.AuthKeyContext;
+import cn.reghao.tnb.file.api.constant.ChannelAction;
 import org.springframework.stereotype.Service;
 
 /**
@@ -16,36 +17,35 @@ import org.springframework.stereotype.Service;
 @Service
 public class OssService {
     private final UploadChannelService uploadChannelService;
-    private final StoreNodeService storeNodeService;
+    private final UserNodeService userNodeService;
 
-    public OssService(UploadChannelService uploadChannelService, StoreNodeService storeNodeService) {
+    public OssService(UploadChannelService uploadChannelService, UserNodeService userNodeService) {
         this.uploadChannelService = uploadChannelService;
-        this.storeNodeService = storeNodeService;
+        this.userNodeService = userNodeService;
     }
 
-    public ServerInfo getServerInfo(int channelId) throws Exception {
-        long userId = AuthKeyContext.getUser();
-        UploadChannel uploadChannel = uploadChannelService.getByChannelIdAndCreateBy(channelId, userId);
+    public ServerInfo getServerInfo(int loginUser, int channelId) throws Exception {
+        UploadChannel uploadChannel = uploadChannelService.getByChannelIdAndCreateBy(channelId, loginUser);
         if (uploadChannel == null) {
             String errMsg = String.format("channel_id %s not exist", channelId);
             throw new Exception(errMsg);
         }
 
-        String domain = storeNodeService.getById(uploadChannel.getNodeId()).getDomain();
-        String ossUrl = String.format("https://%s", domain);
-        long maxSize = uploadChannel.getMaxSize();
-
-        StoreNode storeNode = uploadChannelService.getStoreNodeByChannelId(channelId);
-        if (storeNode == null) {
+        UserNode userNode = userNodeService.getUserNode(uploadChannel.getNodeId(), loginUser);
+        if (userNode == null) {
             String errMsg = String.format("channel_id %s not associate with any store_node", channelId);
             throw new Exception(errMsg);
         }
 
-        String host = storeNode.getNodeAddr();
-        int port = storeNode.getRpcPort();
-        RemoteService<StoreService> remoteService = new RemoteService<>();
-        StoreService storeService = remoteService.getService(host, port, StoreService.class);
-        String token = storeService.getUploadToken(userId, channelId);
-        return new ServerInfo(ossUrl, channelId, maxSize, token);
+        String domain = userNode.getDomain();
+        String ossUrl = String.format("//%s", domain);
+        long maxSize = uploadChannel.getMaxSize();
+
+        String secretKey = userNode.getSecretKey();
+        String action = ChannelAction.upload.getName();
+        long expireAt = System.currentTimeMillis() + 3600*1000;
+        OssPayload ossPayload = new OssPayload(action, channelId, loginUser);
+        String uploadToken = JwtUtil.createToken(ossPayload, expireAt, secretKey);
+        return new ServerInfo(ossUrl, channelId, maxSize, uploadToken);
     }
 }

+ 0 - 4
oss-console/src/main/java/cn/reghao/oss/console/app/service/StoreNodeService.java

@@ -15,7 +15,6 @@ import cn.reghao.oss.console.app.rpc.RpcService;
 import cn.reghao.oss.storeapi.dto.StoreDiskDto;
 import cn.reghao.oss.storeapi.dto.StoreInfo;
 import cn.reghao.oss.storeapi.dto.StoreNodeDto;
-import cn.reghao.oss.storeapi.dto.StoreProperties;
 import cn.reghao.oss.storeapi.iface.StoreService;
 import org.springframework.data.domain.Page;
 import org.springframework.data.domain.PageRequest;
@@ -84,9 +83,6 @@ public class StoreNodeService {
         storeNode.setEnabled(true);
         storeNodeRepository.save(storeNode);
 
-        StoreProperties storeProperties = new StoreProperties(domain, secretKey, referer);
-        StoreService storeService = rpcService.getStoreService(storeNode);
-        storeService.updateStoreProperties(storeProperties);
         return Result.success();
     }
 

+ 11 - 12
oss-console/src/main/java/cn/reghao/oss/console/app/service/UploadChannelService.java

@@ -6,8 +6,8 @@ import cn.reghao.jutil.jdk.result.Result;
 import cn.reghao.oss.console.app.model.dto.ChannelProcessDto;
 import cn.reghao.oss.console.app.rpc.RemoteService;
 import cn.reghao.oss.console.util.AuthKeyContext;
-import cn.reghao.tnb.file.api.dto.ObjectChannel;
 import cn.reghao.oss.storeapi.iface.StoreService;
+import cn.reghao.tnb.file.api.dto.ObjectChannel;
 import cn.reghao.oss.console.account.service.UserContext;
 import cn.reghao.oss.console.app.db.repository.UploadChannelRepository;
 import cn.reghao.oss.console.app.model.dto.ChannelScopeDto;
@@ -47,7 +47,7 @@ public class UploadChannelService {
             return Result.fail(String.format("store_node with id %s not exist", nodeId));
         }
 
-        long createBy = UserContext.getUser().getId();
+        int createBy = UserContext.getUser().getId();
         //int createBy = 410;
         String channelPrefix = uploadChannelDto.getChannelPrefix();
         UploadChannel uploadChannel = uploadChannelRepository.findByPrefixAndCreateByAndNodeId(channelPrefix, createBy, nodeId);
@@ -80,7 +80,7 @@ public class UploadChannelService {
         return Result.success();
     }
 
-    private int getNextChannelId(long userId) {
+    private int getNextChannelId(int userId) {
         int channelId = 101;
         int total = uploadChannelRepository.countByCreateBy(userId);
         return channelId + total;
@@ -136,11 +136,11 @@ public class UploadChannelService {
         return uploadChannelRepository.findById(id).orElse(null);
     }
 
-    public UploadChannel getByChannelIdAndCreateBy(int channelId, long createBy) {
+    public UploadChannel getByChannelIdAndCreateBy(int channelId, int createBy) {
         return uploadChannelRepository.findByChannelIdAndCreateBy(channelId, createBy);
     }
 
-    public ObjectChannel getObjectChannelByChannelId(int channelId, long createBy) {
+    public ObjectChannel getObjectChannelByChannelId(int channelId, int createBy) {
         UploadChannel uploadChannel = uploadChannelRepository.findByChannelIdAndCreateBy(channelId, createBy);
         return getObjectChannel(uploadChannel);
     }
@@ -154,20 +154,19 @@ public class UploadChannelService {
         boolean seturl = uploadChannel.getSeturl();
         int scope = uploadChannel.getScope();
         String domain = storeNodeService.getById(uploadChannel.getNodeId()).getDomain();
-        long createBy = uploadChannel.getCreateBy();
+        int createBy = uploadChannel.getCreateBy();
         return new ObjectChannel(channelId, name, channelPrefix, maxSize, fileType, seturl, scope, domain, createBy);
     }
 
-    public StoreNode getStoreNodeByChannelId(int channelId) throws Exception {
-        long userId = AuthKeyContext.getUser();
-        UploadChannel uploadChannel = uploadChannelRepository.findByChannelIdAndCreateBy(channelId, userId);
+    public StoreNode getStoreNodeByChannelId(int loginUser, int channelId) throws Exception {
+        UploadChannel uploadChannel = uploadChannelRepository.findByChannelIdAndCreateBy(channelId, loginUser);
         if (uploadChannel == null) {
             String errMsg = String.format("channel_id %s not exist", channelId);
             throw new Exception(errMsg);
         }
 
         String domain = storeNodeService.getById(uploadChannel.getNodeId()).getDomain();
-        String ossUrl = String.format("https://%s", domain);
+        String ossUrl = String.format("//%s", domain);
         long maxSize = uploadChannel.getMaxSize();
 
         StoreNode storeNode = storeNodeService.getByDomain(domain);
@@ -179,11 +178,11 @@ public class UploadChannelService {
         return storeNode;
     }
 
-    public List<UploadChannel> getByNodeIdAndUserId(int nodeId, long userId) {
+    public List<UploadChannel> getByNodeIdAndUserId(int nodeId, int userId) {
         return uploadChannelRepository.findByNodeIdAndCreateBy(nodeId, userId);
     }
 
-    public List<UploadChannel> getByDomainAndCreateBy(String domain, long createBy) {
+    public List<UploadChannel> getByDomainAndCreateBy(String domain, int createBy) {
         StoreNode storeNode = storeNodeService.getByDomain(domain);
         int nodeId = storeNode.getId();
         return getByNodeIdAndUserId(nodeId, createBy);

+ 4 - 4
oss-console/src/main/java/cn/reghao/oss/console/app/service/UserKeyService.java

@@ -28,7 +28,7 @@ public class UserKeyService {
     }
 
     public Result create() {
-        long loginUser = UserContext.getUser().getId();
+        int loginUser = UserContext.getUser().getId();
         UserKey userKey = userKeyRepository.findByCreateBy(loginUser);
         if (userKey != null) {
             String errMsg = String.format("you already have key");
@@ -54,12 +54,12 @@ public class UserKeyService {
             return Result.fail("secret not matched");
         }
 
-        long loginUser = userKey.getCreateBy();
+        int loginUser = userKey.getCreateBy();
         String token = getToken(loginUser);
         return Result.success(token);
     }
 
-    public String getToken(long loginUser) {
+    public String getToken(int loginUser) {
         String secretKey = "ossconsole.reghao.cn";
         long timestamp = System.currentTimeMillis() + 3600*24*365*1000L;
         String action = ChannelAction.all.getName();
@@ -68,7 +68,7 @@ public class UserKeyService {
         return JwtUtil.createToken(ossPayload, timestamp, secretKey);
     }
 
-    public long getUserIdFromToken(String token) {
+    public int getUserIdFromToken(String token) {
         String secretKey = "ossconsole.reghao.cn";
         OssPayload ossPayload = JwtUtil.getOssPayload(token, secretKey);
         return ossPayload.getUserId();

+ 4 - 0
oss-console/src/main/java/cn/reghao/oss/console/app/service/UserNodeService.java

@@ -78,4 +78,8 @@ public class UserNodeService {
         List<Integer> nodeIds = list.stream().map(UserNode::getNodeId).collect(Collectors.toList());
         return storeNodeService.getByIds(nodeIds);
     }
+
+    public UserNode getUserNode(int nodeId, int loginUser) {
+        return userNodeRepository.findByNodeIdAndUserId(nodeId, loginUser);
+    }
 }

+ 1 - 1
oss-console/src/main/java/cn/reghao/oss/console/config/web/ConsoleAuthInterceptor.java

@@ -42,7 +42,7 @@ public class ConsoleAuthInterceptor implements HandlerInterceptor {
                 response.setStatus(403);
                 return false;
             } else {
-                long userId = userKeyService.getUserIdFromToken(token);
+                int userId = userKeyService.getUserIdFromToken(token);
                 log.info("{} access {}", userId, uri);
                 AuthKeyContext authKeyContext = new AuthKeyContext(userId);
             }

+ 84 - 0
oss-console/src/main/java/cn/reghao/oss/console/rpc/NodeServiceImpl.java

@@ -0,0 +1,84 @@
+package cn.reghao.oss.console.rpc;
+
+import cn.reghao.oss.console.app.db.repository.StoreNodeRepository;
+import cn.reghao.oss.console.app.db.repository.UserNodeRepository;
+import cn.reghao.oss.console.app.model.po.StoreNode;
+import cn.reghao.oss.console.app.model.po.UploadChannel;
+import cn.reghao.oss.console.app.model.po.UserNode;
+import cn.reghao.oss.console.app.service.StoreNodeService;
+import cn.reghao.oss.console.app.service.UploadChannelService;
+import cn.reghao.oss.storeapi.dto.NodeProperties;
+import cn.reghao.oss.storeapi.iface.NodeService;
+import cn.reghao.oss.storeapi.dto.StoreNodeDto;
+import cn.reghao.tnb.file.api.dto.ObjectChannel;
+import org.apache.dubbo.config.annotation.DubboService;
+import org.springframework.data.domain.PageRequest;
+import org.springframework.stereotype.Service;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * @author reghao
+ * @date 2024-07-02 10:58:51
+ */
+@DubboService
+@Service
+public class NodeServiceImpl implements NodeService {
+    private final StoreNodeRepository storeNodeRepository;
+    private final UserNodeRepository userNodeRepository;
+    private final UploadChannelService uploadChannelService;
+    private final StoreNodeService storeNodeService;
+
+    public NodeServiceImpl(StoreNodeRepository storeNodeRepository, UserNodeRepository userNodeRepository,
+                           UploadChannelService uploadChannelService, StoreNodeService storeNodeService) {
+        this.storeNodeRepository = storeNodeRepository;
+        this.userNodeRepository = userNodeRepository;
+        this.uploadChannelService = uploadChannelService;
+        this.storeNodeService = storeNodeService;
+    }
+
+    public void registerNode(StoreNodeDto storeNodeDto) {
+        storeNodeService.add(storeNodeDto);
+    }
+
+    @Override
+    public NodeProperties getNodeProperties(int owner, String nodeAddress) {
+        StoreNode storeNode = storeNodeRepository.findByNodeAddr(nodeAddress);
+        if (storeNode != null) {
+            int nodeId = storeNode.getId();
+            UserNode userNode = userNodeRepository.findByNodeIdAndUserId(nodeId, owner);
+            if (userNode != null) {
+                return new NodeProperties(userNode.getDomain(), userNode.getSecretKey(), userNode.getReferer());
+            }
+        }
+
+        return null;
+    }
+
+    @Override
+    public ObjectChannel getChannelById(int owner, int channelId) {
+        return uploadChannelService.getObjectChannelByChannelId(channelId, owner);
+    }
+
+    @Override
+    public int getChannelIdByUrl(int loginUser, String url) {
+        PageRequest pageRequest = PageRequest.of(0, 100);
+        List<UserNode> list = userNodeRepository.findByUserId(loginUser, pageRequest).getContent();
+        List<UploadChannel> uploadChannels = new ArrayList<>();
+        for (UserNode userNode : list) {
+            int nodeId = userNode.getNodeId();
+            uploadChannels.addAll(uploadChannelService.getByNodeIdAndUserId(nodeId, loginUser));
+        }
+
+        int idx = url.indexOf("/");
+        String objectName = url.substring(idx);
+        for (UploadChannel uploadChannel : uploadChannels) {
+            if (objectName.startsWith(uploadChannel.getPrefix())) {
+                return uploadChannel.getChannelId();
+            }
+        }
+
+        return 0;
+    }
+}

+ 3 - 3
oss-console/src/main/java/cn/reghao/oss/console/util/AuthKeyContext.java

@@ -5,13 +5,13 @@ package cn.reghao.oss.console.util;
  * @date 2023-06-02 10:48:59
  */
 public class AuthKeyContext implements AutoCloseable {
-    static final ThreadLocal<Long> CURRENT = new ThreadLocal<>();
+    static final ThreadLocal<Integer> CURRENT = new ThreadLocal<>();
 
-    public AuthKeyContext(Long user) {
+    public AuthKeyContext(int user) {
         CURRENT.set(user);
     }
 
-    public static long getUser() {
+    public static int getUser() {
         return CURRENT.get();
     }
 

+ 7 - 0
oss-console/src/main/resources/application.yml

@@ -1,4 +1,11 @@
 dubbo:
+  protocol:
+    name: dubbo
+    port: 8120
+  application:
+    name: oss-console-provider
+  scan:
+    base-packages: cn.reghao.oss.console.rpc
   registry:
     address: N/A
 server:

+ 1 - 1
oss-console/src/main/resources/templates/node/index.html

@@ -45,7 +45,7 @@
                     <td th:text="${item.domain}">应用名</td>
                     <td th:text="${item.enabled}">应用名</td>
                     <td>
-                        <a class="open-popup" data-title="设置存储节点属性" th:attr="data-url=@{'/store/node/config/'+${item.id}}"
+                        <a class="open-popup" data-title="设置存储节点" th:attr="data-url=@{'/store/node/config/'+${item.id}}"
                            data-size="640,480" href="#">设置</a>
                         <a class="open-popup" data-title="存储节点详细信息" th:attr="data-url=@{'/store/node/detail/'+${item.id}}"
                            data-size="720,540" href="#">详细</a>

+ 2 - 0
oss-console/src/main/resources/templates/usernode/index1.html

@@ -47,6 +47,8 @@
                     <td th:text="${item.domain}">节点域名</td>
                     <td th:text="${item.nodeAddr}">节点地址</td>
                     <td>
+                        <a class="open-popup" data-title="设置存储节点属性" th:attr="data-url=@{'/store/node/config/'+${item.id}}"
+                           data-size="640,480" href="#">设置</a>
                         <a class="open-popup" data-title="我的节点详细信息" th:attr="data-url=@{'/store/my/detail/'+${item.id}}"
                            data-size="640,480" href="#">详细</a>
                         <a class="ajax-delete" th:attr="data-msg='确定要删除 '+ ${item.domain}"

+ 3 - 29
oss-console/src/test/java/OssConsoleTest.java

@@ -1,8 +1,5 @@
-import cn.reghao.tnb.file.api.constant.ObjectScope;
 import cn.reghao.oss.console.OssConsoleApplication;
 import cn.reghao.oss.console.account.service.AccountService;
-import cn.reghao.oss.console.app.model.dto.UploadChannelDto;
-import cn.reghao.oss.console.app.service.UploadChannelService;
 import lombok.extern.slf4j.Slf4j;
 import org.junit.Test;
 import org.junit.runner.RunWith;
@@ -25,31 +22,8 @@ public class OssConsoleTest {
 
     @Test
     public void createUserAccount() {
-    }
-
-    @Autowired
-    UploadChannelService uploadChannelService;
-    @Test
-    public void initChannel() {
-        int nodeId = 1;
-        for (UploadChannel uploadChannel : UploadChannel.values()) {
-            String name = uploadChannel.name();
-            if (name.equals("disk")) {
-                continue;
-            }
-
-            long maxSize = uploadChannel.getMaxSize();
-            String prefix = uploadChannel.getPrefix();
-            int fileType = uploadChannel.getFileType();
-
-            UploadChannelDto uploadChannelDto = new UploadChannelDto();
-            uploadChannelDto.setChannelPrefix(prefix);
-            uploadChannelDto.setMaxSize(maxSize);
-            uploadChannelDto.setName(name);
-            uploadChannelDto.setFileType(fileType);
-            uploadChannelDto.setScope(ObjectScope.PRIVATE.getCode());
-            uploadChannelDto.setNodeId(nodeId);
-            uploadChannelService.add(uploadChannelDto);
-        }
+        int userId = 1;
+        String newPassword = "1234567890";
+        accountService.updateAccountPassword(userId, newPassword);
     }
 }

+ 0 - 67
oss-console/src/test/java/UploadChannel.java

@@ -1,67 +0,0 @@
-import java.util.HashMap;
-import java.util.Map;
-
-/**
- * @author reghao
- * @date 2023-05-23 10:43:25
- */
-@Deprecated
-public enum UploadChannel {
-    // 网盘上传(单个文件最大 20GiB)
-    disk(101, "file/", 1024L*1024*1024*20, 1005),
-    // 视频上传(单个文件最大 10GiB)
-    video(102, "video/playback/", 1024L*1024*1024*10, 1002),
-    // 音频上传(单个文件最大 1GiB)
-    audio(103, "audio/playback/", 1024L*1024*1024, 1003),
-    // 用户头像上传(单个文件最大 2MiB)
-    avatar(104, "image/a/", 1024L*1024*2, 1001),
-    // 图片上传(单个文件最大 10MiB)
-    image(105, "image/i/", 1024L*1024*10, 1001),
-    // 用户状态照片上传(单个文件最大 100MiB)
-    photo(106, "image/p/", 1024L*1024*100, 1001),
-    img(107, "img/", 1024L*1024*10, 1001);
-
-    private final int code;
-    private final String prefix;
-    private final long maxSize;
-    private final int fileType;
-    UploadChannel(int code, String prefix, long maxSize, int fileType) {
-        this.code = code;
-        this.prefix = prefix;
-        this.maxSize = maxSize;
-        this.fileType = fileType;
-    }
-
-    private static Map<Integer, UploadChannel> map = new HashMap<>();
-    private static Map<String, UploadChannel> map1 = new HashMap<>();
-    static {
-        for (UploadChannel channel : UploadChannel.values()) {
-            map.put(channel.code, channel);
-            map1.put(channel.prefix, channel);
-        }
-    }
-
-    public static UploadChannel getUploadChannel(int code) {
-        return map.get(code);
-    }
-
-    public static UploadChannel getUploadChannel(String prefix) {
-        return map1.get(prefix);
-    }
-
-    public int getCode() {
-        return code;
-    }
-
-    public String getPrefix() {
-        return prefix;
-    }
-
-    public long getMaxSize() {
-        return maxSize;
-    }
-
-    public int getFileType() {
-        return fileType;
-    }
-}

+ 2 - 2
oss-sdk/src/main/java/cn/reghao/oss/sdk/OssConsoleClient.java

@@ -2,7 +2,7 @@ package cn.reghao.oss.sdk;
 
 import cn.reghao.jutil.jdk.result.WebResult;
 import cn.reghao.jutil.jdk.serializer.JsonConverter;
-import cn.reghao.oss.sdk.model.OssStoreConfig;
+import cn.reghao.oss.sdk.model.OssConsoleConfig;
 import cn.reghao.tnb.file.api.dto.ObjectChannel;
 import cn.reghao.tnb.file.api.dto.ObjectInfo;
 import cn.reghao.oss.storeapi.dto.ServerInfo;
@@ -32,7 +32,7 @@ public class OssConsoleClient {
     private final String endpoint;
     private String token;
 
-    public OssConsoleClient(OssStoreConfig ossProperties) throws Exception {
+    public OssConsoleClient(OssConsoleConfig ossProperties) throws Exception {
         this.endpoint = ossProperties.getConsoleUrl();
         auth(ossProperties.getAccessKeyId(), ossProperties.getAccessKeySecret());
     }

+ 1 - 1
oss-sdk/src/main/java/cn/reghao/oss/sdk/model/OssStoreConfig.java → oss-sdk/src/main/java/cn/reghao/oss/sdk/model/OssConsoleConfig.java

@@ -9,7 +9,7 @@ import lombok.Getter;
  */
 @AllArgsConstructor
 @Getter
-public class OssStoreConfig {
+public class OssConsoleConfig {
     private String consoleUrl;
     private String accessKeyId;
     private String accessKeySecret;

+ 2 - 2
oss-sdk/src/test/java/OssConsoleClientTest.java

@@ -1,4 +1,4 @@
-import cn.reghao.oss.sdk.model.OssStoreConfig;
+import cn.reghao.oss.sdk.model.OssConsoleConfig;
 import cn.reghao.oss.storeapi.dto.ServerInfo;
 import cn.reghao.oss.storeapi.rest.UploadFileRet;
 import cn.reghao.oss.sdk.ObjectMultipartUploadService;
@@ -28,7 +28,7 @@ public class OssConsoleClientTest {
         String consoleUrl = "http://ossconsole.reghao.cn";
         String accessKeyId = "mWYMpbrL";
         String accessKeySecret = "uvuTJKKbRfaSxNPM38";
-        OssStoreConfig ossProperties = new OssStoreConfig(consoleUrl, accessKeyId, accessKeySecret);
+        OssConsoleConfig ossProperties = new OssConsoleConfig(consoleUrl, accessKeyId, accessKeySecret);
         OssConsoleClient ossConsoleClient = new OssConsoleClient(ossProperties);
 
         int channelId = 101;

+ 12 - 1
oss-store/README.md

@@ -3,4 +3,15 @@
 
 ## 依赖的第三方服务
 - mysql
-- zookeeper
+
+## 设计思路
+- oss-store
+> 存储节点
+- oss-console
+> 管理存储节点
+
+
+```
+store 启动时注册到 console -> 用户选择 store -> 用户配置 store 
+-> 用户在 store 上创建上传 channel -> 用户通过 channelId+accessKey+accessSecret 上传和访问文件
+``` 

+ 4 - 3
oss-store/bin/oss.yml

@@ -7,7 +7,8 @@ spring:
     username: dev
     password: Dev@123456
 oss:
-  consoleEndpoint: http://ossconsole.reghao.cn
-  host: 192.168.0.78
+  consoleHost: 127.0.0.1
+  consolePort: 8120
+  host: 192.168.0.212
   diskDirs:
-    - /opt/oss/disk/13f654c8-af87-4710-aac9-7aa086c99aec/
+    - /opt/disk/13f654c8-af87-4710-aac9-7aa086c99aec/

+ 0 - 5
oss-store/pom.xml

@@ -53,11 +53,6 @@
             <artifactId>store-api</artifactId>
             <version>1.0.0-SNAPSHOT</version>
         </dependency>
-        <dependency>
-            <groupId>cn.reghao.oss</groupId>
-            <artifactId>oss-sdk</artifactId>
-            <version>1.0.0-SNAPSHOT</version>
-        </dependency>
 
         <dependency>
             <groupId>org.projectlombok</groupId>

+ 7 - 3
oss-store/src/main/java/cn/reghao/oss/store/config/BeansConfig.java

@@ -1,7 +1,8 @@
 package cn.reghao.oss.store.config;
 
-import cn.reghao.oss.sdk.OssConsoleClient;
+import cn.reghao.oss.storeapi.iface.NodeService;
 import cn.reghao.oss.store.config.props.OssProperties;
+import cn.reghao.oss.store.rpc.RemoteService;
 import org.springframework.context.annotation.Bean;
 import org.springframework.context.annotation.Configuration;
 
@@ -12,7 +13,10 @@ import org.springframework.context.annotation.Configuration;
 @Configuration
 public class BeansConfig {
     @Bean
-    public OssConsoleClient ossConsoleClient(OssProperties ossProperties) {
-        return new OssConsoleClient(ossProperties.getConsoleEndpoint());
+    public NodeService nodeService(OssProperties ossProperties) {
+        RemoteService<NodeService> remoteService = new RemoteService<>();
+        String host = ossProperties.getConsoleHost();
+        int port = ossProperties.getConsolePort();
+        return remoteService.getService(host, port, NodeService.class);
     }
 }

+ 5 - 18
oss-store/src/main/java/cn/reghao/oss/store/config/SpringLifecycle.java

@@ -1,11 +1,8 @@
 package cn.reghao.oss.store.config;
 
-import cn.reghao.jutil.jdk.serializer.JsonConverter;
-import cn.reghao.oss.sdk.OssConsoleClient;
-import cn.reghao.tnb.file.api.dto.ObjectChannel;
+import cn.reghao.oss.store.config.props.DubboProperties;
 import cn.reghao.oss.storeapi.dto.StoreDiskDto;
 import cn.reghao.oss.storeapi.dto.StoreNodeDto;
-import cn.reghao.oss.storeapi.dto.StoreProperties;
 import cn.reghao.oss.store.config.props.SpringProperties;
 import cn.reghao.oss.store.service.FileStoreService;
 import cn.reghao.oss.store.service.StoreLocalService;
@@ -27,14 +24,12 @@ import java.util.stream.Collectors;
 public class SpringLifecycle implements ApplicationRunner, DisposableBean {
     private final SpringProperties springProperties;
     private final FileStoreService fileStoreService;
-    private final OssConsoleClient ossConsoleClient;
     private final StoreLocalService storeLocalService;
 
-    public SpringLifecycle(SpringProperties springProperties, FileStoreService fileStoreService,
-                           OssConsoleClient ossConsoleClient, StoreLocalService storeLocalService) {
+    public SpringLifecycle(SpringProperties springProperties, DubboProperties dubboProperties, FileStoreService fileStoreService,
+                           StoreLocalService storeLocalService) {
         this.springProperties = springProperties;
         this.fileStoreService = fileStoreService;
-        this.ossConsoleClient = ossConsoleClient;
         this.storeLocalService = storeLocalService;
     }
 
@@ -46,8 +41,6 @@ public class SpringLifecycle implements ApplicationRunner, DisposableBean {
     }
 
     private void initStoreNode() throws Exception {
-        log.info("初始化 StoreNode...");
-
         // 注册 oss-store 到 oss-console
         String nodeAddr = springProperties.getNodeAddress();
         int httpPort = springProperties.getHttpPort();
@@ -56,14 +49,8 @@ public class SpringLifecycle implements ApplicationRunner, DisposableBean {
                 .map(StoreDiskDto::new)
                 .collect(Collectors.toList());
         StoreNodeDto storeNodeDto = new StoreNodeDto(nodeAddr, httpPort, rpcPort, list);
-        String jsonPayload = JsonConverter.objectToJson(storeNodeDto);
-        //ossConsoleClient.registerNode(jsonPayload);
-
-        // 获取 oss-store 配置和默认 channel
-        StoreProperties storeProperties = ossConsoleClient.getStoreProperties(nodeAddr);
-        List<ObjectChannel> objectChannels = ossConsoleClient.getObjectChannels(nodeAddr);
-        storeLocalService.initChannels(storeProperties, objectChannels);
-        log.info("StoreNode 初始化完成...");
+        storeLocalService.register(storeNodeDto);
+        log.info("StoreNode 已注册到 oss-console...");
     }
 
     @Override

+ 2 - 1
oss-store/src/main/java/cn/reghao/oss/store/config/props/OssProperties.java

@@ -16,7 +16,8 @@ import java.util.List;
 @Component
 @ConfigurationProperties(prefix = "oss")
 public class OssProperties {
+    private String consoleHost;
+    private Integer consolePort;
     private String host;
-    private String consoleEndpoint;
     private List<String> diskDirs;
 }

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

@@ -80,16 +80,16 @@ public class ObjectGetController {
         }
 
         OssPayload ossPayload = JwtUtil.getOssPayload(token, storeLocalService.getSecretKey());
-        long loginUser = ossPayload.getUserId();
+        int loginUser = ossPayload.getUserId();
         int channelId = ossPayload.getChannelId();
-        ObjectChannel objectChannel = storeLocalService.getChannelByChannelId(loginUser, channelId);
+        ObjectChannel objectChannel = storeLocalService.getChannelById(loginUser, channelId);
         if (objectChannel == null) {
             String payload = String.format("channel_id %s not exist", channelId);
             getObjectService.writeResponse(HttpServletResponse.SC_FORBIDDEN, payload);
             return;
         }
 
-        long userId = ossPayload.getUserId();
+        int userId = ossPayload.getUserId();
         String prefix = objectChannel.getPrefix();
         if (!objectName.startsWith(prefix)) {
             String payload = String.format("channel prefix %s not matched", prefix);

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

@@ -11,7 +11,7 @@ import cn.reghao.jutil.jdk.security.DigestUtil;
 import cn.reghao.jutil.web.ServletUtil;
 import cn.reghao.oss.storeapi.dto.OssPayload;
 import cn.reghao.oss.storeapi.rest.UploadFileRet;
-import cn.reghao.oss.store.config.UserContext;
+import cn.reghao.oss.store.util.UserContext;
 import org.apache.commons.io.FileUtils;
 import org.springframework.http.HttpStatus;
 import org.springframework.http.MediaType;
@@ -73,15 +73,15 @@ public class ObjectUploadController {
                     .body(WebResult.failWithMsg("channel not match in token"));
         }
 
-        long loginUser = ossPayload.getUserId();
-        ObjectChannel objectChannel = storeLocalService.getChannelByChannelId(loginUser, channelId);
+        int loginUser = ossPayload.getUserId();
+        ObjectChannel objectChannel = storeLocalService.getChannelById(loginUser, channelId);
         if (objectChannel == null) {
             String errMsg = String.format("channel validate failed, channel %s not exist", channelId);
             return ResponseEntity.status(HttpStatus.FORBIDDEN)
                     .body(WebResult.failWithMsg(errMsg));
         }
 
-        long userId1 = ossPayload.getUserId();
+        int userId1 = ossPayload.getUserId();
         UserContext context = new UserContext(userId1);
 
         /* channel validate */

+ 0 - 5
oss-store/src/main/java/cn/reghao/oss/store/db/mapper/DataBlockMapper.java

@@ -1,6 +1,5 @@
 package cn.reghao.oss.store.db.mapper;
 
-import cn.reghao.jutil.jdk.store.SubDirCount;
 import cn.reghao.oss.store.model.po.DataBlock;
 import cn.reghao.jutil.jdk.db.BaseMapper;
 import org.apache.ibatis.annotations.Mapper;
@@ -14,10 +13,6 @@ import java.util.List;
  */
 @Mapper
 public interface DataBlockMapper extends BaseMapper<DataBlock> {
-    void updateParent(@Param("id") int id, @Param("relativeDir") String relativeDir);
-    void updateBatch(List<DataBlock> list);
-
     List<DataBlock> findDataBlocks(@Param("pageSize") int pageSize, @Param("nextId") int nextId);
     DataBlock findByContentId(String contentId);
-    List<SubDirCount> findSubDirCount(String baseDir);
 }

+ 2 - 27
oss-store/src/main/java/cn/reghao/oss/store/db/mapper/FileMetaMapper.java

@@ -1,11 +1,8 @@
 package cn.reghao.oss.store.db.mapper;
 
-import cn.reghao.oss.storeapi.dto.DeleteFile;
-import cn.reghao.oss.storeapi.dto.FileInfo;
 import cn.reghao.oss.store.model.po.FileMeta;
 import cn.reghao.oss.storeapi.dto.ObjectMeta;
 import cn.reghao.jutil.jdk.db.BaseMapper;
-import cn.reghao.jutil.jdk.db.Page;
 import org.apache.ibatis.annotations.Mapper;
 import org.apache.ibatis.annotations.Param;
 
@@ -18,38 +15,16 @@ import java.util.List;
 @Mapper
 public interface FileMetaMapper extends BaseMapper<FileMeta> {
     void updateScopeByObjectName(@Param("scope") int scope, @Param("objectName") String objectName);
-    void updateScopeByObjectNames(@Param("scope") int scope, @Param("list") List<String> list);
 
-    List<FileMeta> findFileMetaByPage(Page page);
     FileMeta findBySha256sum(String sha256sum);
     FileMeta findByObjectName(String objectName);
-    List<FileMeta> findByObjectNames(List<String> list);
     FileMeta findByObjectId(String objectId);
     List<FileMeta> findByContentId(String contentId);
     ObjectMeta findObjectMeta(String objectName);
     ObjectMeta findObjectMetaById(String objectName);
-    List<String> findObjectNames(List<String> list);
 
     /******************************************************************************************************************/
     List<FileMeta> findAll0(@Param("bucket") String bucket, @Param("max") Integer max, @Param("regex") String regex);
-    List<FileMeta> findAll1(@Param("bucket") String bucket, @Param("prefix") String prefix, @Param("max") Integer max);
-    List<FileMeta> findAll2(@Param("bucket") String bucket, @Param("prefix") String prefix, @Param("start") String start, @Param("max") Integer max);
-    void updateFilename(@Param("objectId") String objectId, @Param("filename") String filename);
-    void updateParent(@Param("objectId") String objectId, @Param("pid") String pid);
-    void updateBatch(List<FileMeta> list);
-
-    int countByPid(String pid);
-    List<FileInfo> findFileInfoByPage(Page page, @Param("pid") String pid);
-    List<FileInfo> findFileInfo1ByPage(Page page, @Param("pid") String pid);
-    List<FileInfo> findDirectories(String pid);
-
-    int countByKeyword(String keyword);
-    List<FileInfo> findKeywordByPage(Page page, @Param("keyword") String keyword);
-
-    int countDeletedFiles();
-    List<DeleteFile> findDeletedFileByPage(Page page);
-    List<FileMeta> findFileInfos(@Param("objectIds") List<String> objectIds);
-    List<FileMeta> findByFilename(@Param("pid") String pid, @Param("filename") String filename);
-    List<FileMeta> findByPid(String pid);
-    List<String> findObjectPrefix();
+    List<FileMeta> findAll2(@Param("bucket") String bucket, @Param("prefix") String prefix,
+                            @Param("start") String start, @Param("max") Integer max);
 }

+ 2 - 2
oss-store/src/main/java/cn/reghao/oss/store/inerceptor/TokenFilter.java

@@ -2,7 +2,7 @@ package cn.reghao.oss.store.inerceptor;
 
 import cn.reghao.oss.store.service.StoreLocalService;
 import cn.reghao.oss.store.util.JwtUtil;
-import cn.reghao.oss.store.config.UserContext;
+import cn.reghao.oss.store.util.UserContext;
 import cn.reghao.jutil.web.ServletUtil;
 import cn.reghao.oss.storeapi.dto.OssPayload;
 import org.springframework.stereotype.Component;
@@ -29,7 +29,7 @@ public class TokenFilter implements Filter {
     @Override
     public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
             throws IOException, ServletException {
-        long userId = -1;
+        int userId = -1;
         String token = ServletUtil.getBearerToken(request);
         if (token != null) {
             OssPayload ossPayload = JwtUtil.getOssPayload(token, storeLocalService.getSecretKey());

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

@@ -1,6 +1,6 @@
 package cn.reghao.oss.store.model.po;
 
-import cn.reghao.oss.store.config.UserContext;
+import cn.reghao.oss.store.util.UserContext;
 import cn.reghao.jutil.jdk.db.BaseObject;
 import lombok.Getter;
 import lombok.NoArgsConstructor;
@@ -26,7 +26,7 @@ public class FileMeta extends BaseObject<Integer> {
     private Integer fileType;
     private String contentType;
     private Integer scope;
-    private Long uploadBy;
+    private Integer uploadBy;
 
     // 目录对象
     public FileMeta(String objectName, String objectId, String filename, String pid, int scope) {

+ 3 - 3
oss-store/src/main/java/cn/reghao/oss/store/rpc/MediaServiceImpl.java

@@ -75,7 +75,7 @@ public class MediaServiceImpl implements MediaService {
 
     @Override
     public String getSignedUrl(int channelId, String objectId) {
-        long userId = getUserIdByChannelId(channelId);
+        int userId = getUserIdByChannelId(channelId);
 
         int expireSecond = 3600;
         FileMeta fileMeta = objectRepository.getByObjectId(objectId);
@@ -85,7 +85,7 @@ public class MediaServiceImpl implements MediaService {
         return signedUrl;
     }
 
-    private Long getUserIdByChannelId(int channelId) {
-        return 1L;
+    private int getUserIdByChannelId(int channelId) {
+        return 1;
     }
 }

+ 3 - 7
oss-store/src/main/java/cn/reghao/oss/store/rpc/ObjectServiceImpl.java

@@ -3,7 +3,6 @@ package cn.reghao.oss.store.rpc;
 import cn.reghao.tnb.file.api.constant.ObjectScope;
 import cn.reghao.oss.store.db.repository.ObjectRepository;
 import cn.reghao.oss.store.model.po.FileMeta;
-import cn.reghao.oss.store.service.ObjectNameService;
 import cn.reghao.tnb.file.api.dto.ObjectChannel;
 import cn.reghao.tnb.file.api.dto.ObjectInfo;
 import cn.reghao.oss.store.db.mapper.FileMetaMapper;
@@ -23,16 +22,13 @@ import java.util.List;
 @Service
 public class ObjectServiceImpl implements ObjectService {
     private final FileMetaMapper fileMetaMapper;
-    private final ObjectNameService objectNameService;
     private final ObjectRepository objectRepository;
     private final SignService signService;
     private final StoreLocalService storeLocalService;
 
-    public ObjectServiceImpl(FileMetaMapper fileMetaMapper, ObjectNameService objectNameService,
-                             ObjectRepository objectRepository, SignService signService,
-                             StoreLocalService storeLocalService) {
+    public ObjectServiceImpl(FileMetaMapper fileMetaMapper, ObjectRepository objectRepository,
+                             SignService signService, StoreLocalService storeLocalService) {
         this.fileMetaMapper = fileMetaMapper;
-        this.objectNameService = objectNameService;
         this.objectRepository = objectRepository;
         this.signService = signService;
         this.storeLocalService = storeLocalService;
@@ -67,7 +63,7 @@ public class ObjectServiceImpl implements ObjectService {
 
     @Override
     public ObjectInfo getObjectInfo(int channelId, String objectId) {
-        long loginUser = 1;
+        int loginUser = 1;
         int expireSecond = 3600;
 
         FileMeta fileMeta = fileMetaMapper.findByObjectId(objectId);

+ 33 - 0
oss-store/src/main/java/cn/reghao/oss/store/rpc/RemoteService.java

@@ -0,0 +1,33 @@
+package cn.reghao.oss.store.rpc;
+
+import org.apache.dubbo.config.ApplicationConfig;
+import org.apache.dubbo.config.ConsumerConfig;
+import org.apache.dubbo.config.ReferenceConfig;
+
+/**
+ * @author reghao
+ * @date 2024-02-23 13:19:20
+ */
+public class RemoteService<T> {
+    public T getService(String host, int port, Class<T> clazz) {
+        String serviceName = "remote-service";
+        String dubboUrl = String.format("dubbo://%s:%s/%s", host, port, clazz.getName());
+
+        // 当前应用配置
+        ApplicationConfig application = new ApplicationConfig();
+        application.setName(serviceName);
+
+        ConsumerConfig consumerConfig = new ConsumerConfig();
+        consumerConfig.setTimeout(60_000);
+
+        // 注意:ReferenceConfig为重对象,内部封装了与注册中心的连接,以及与服务提供方的连接
+        // 引用远程服务
+        // 此实例很重,封装了与注册中心的连接以及与提供者的连接,请自行缓存,否则可能造成内存和连接泄漏
+        ReferenceConfig<T> reference = new ReferenceConfig<>();
+        reference.setApplication(application);
+        reference.setInterface(clazz);
+        reference.setUrl(dubboUrl);
+        reference.setConsumer(consumerConfig);
+        return reference.get();
+    }
+}

+ 4 - 28
oss-store/src/main/java/cn/reghao/oss/store/rpc/StoreServiceImpl.java

@@ -3,13 +3,8 @@ package cn.reghao.oss.store.rpc;
 import cn.reghao.tnb.file.api.constant.ObjectScope;
 import cn.reghao.oss.store.service.FileStoreService;
 import cn.reghao.oss.store.service.ObjectNameService;
-import cn.reghao.oss.store.service.StoreLocalService;
-import cn.reghao.oss.store.util.JwtUtil;
-import cn.reghao.tnb.file.api.constant.ChannelAction;
-import cn.reghao.oss.storeapi.dto.OssPayload;
 import cn.reghao.oss.storeapi.dto.StoreDiskDto;
 import cn.reghao.oss.storeapi.dto.StoreInfo;
-import cn.reghao.oss.storeapi.dto.StoreProperties;
 import cn.reghao.oss.storeapi.iface.StoreService;
 import cn.reghao.tnb.file.api.dto.ObjectChannel;
 import org.apache.dubbo.config.annotation.DubboService;
@@ -25,44 +20,25 @@ import java.util.stream.Collectors;
 @DubboService
 @Service
 public class StoreServiceImpl implements StoreService {
-    private final StoreLocalService storeLocalService;
     private final ObjectNameService objectNameService;
     private final FileStoreService fileStoreService;
 
-    public StoreServiceImpl(StoreLocalService storeLocalService, ObjectNameService objectNameService,
-                            FileStoreService fileStoreService) {
-        this.storeLocalService = storeLocalService;
+    public StoreServiceImpl(ObjectNameService objectNameService, FileStoreService fileStoreService) {
         this.objectNameService = objectNameService;
         this.fileStoreService = fileStoreService;
     }
 
     @Override
-    public void updateStoreProperties(StoreProperties storeProperties) {
-        storeLocalService.updateStoreProperties(storeProperties);
-    }
-
-    @Override
-    public String getUploadToken(long userId, int channelId) {
-        String secretKey = storeLocalService.getSecretKey();
-        String action = ChannelAction.upload.getName();
-        long expireAt = System.currentTimeMillis() + 3600*1000;
-        OssPayload ossPayload = new OssPayload(action, channelId, userId);
-        return JwtUtil.createToken(ossPayload, expireAt, secretKey);
-    }
-
-    @Override
-    public void createChannel(long userId, ObjectChannel channel) {
+    public void createChannel(int userId, ObjectChannel channel) {
         String objectName = channel.getPrefix();
         objectNameService.createParentDirs(objectName, ObjectScope.PUBLIC.getCode());
-        storeLocalService.addObjectChannel(channel);
     }
 
     @Override
     public StoreInfo getStoreInfo() {
-        List<ObjectChannel> objectChannels = storeLocalService.getObjectChannels();
-        List<StoreDiskDto> list = fileStoreService.getStoreDisks().stream()
+        List<StoreDiskDto> diskDtos = fileStoreService.getStoreDisks().stream()
                 .map(StoreDiskDto::new)
                 .collect(Collectors.toList());
-        return new StoreInfo(storeLocalService.getStoreProperties(), objectChannels, list);
+        return new StoreInfo(diskDtos);
     }
 }

+ 1 - 0
oss-store/src/main/java/cn/reghao/oss/store/service/FileStoreService.java

@@ -63,6 +63,7 @@ public class FileStoreService {
         log.info("本地磁盘数据初始化完成...");
     }
 
+    // TODO 返回实时磁盘容量
     public List<LocalStore> getStoreDisks() {
         return LocalStores.getLocalStores();
     }

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

@@ -22,7 +22,7 @@ public class SignService {
         this.storeLocalService = storeLocalService;
     }
 
-    public String getSignedUrl(long loginUser, String url, int expire) {
+    public String getSignedUrl(int loginUser, String url, int expire) {
         long timestamp = System.currentTimeMillis() + expire*1000L;
         int channelId = storeLocalService.getChannelIdByUrl(loginUser, url);
 

+ 25 - 62
oss-store/src/main/java/cn/reghao/oss/store/service/StoreLocalService.java

@@ -1,91 +1,54 @@
 package cn.reghao.oss.store.service;
 
+import cn.reghao.oss.storeapi.dto.NodeProperties;
+import cn.reghao.oss.storeapi.iface.NodeService;
+import cn.reghao.oss.store.util.UserContext;
+import cn.reghao.oss.store.config.props.OssProperties;
+import cn.reghao.oss.storeapi.dto.StoreNodeDto;
 import cn.reghao.tnb.file.api.dto.ObjectChannel;
-import cn.reghao.oss.storeapi.dto.StoreProperties;
 import org.springframework.stereotype.Service;
 
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
 /**
  * @author reghao
  * @date 2024-03-08 09:20:27
  */
 @Service
 public class StoreLocalService {
-    private StoreProperties storeProperties;
-    private final Map<String, ObjectChannel> prefixMap = new HashMap<>();
-    private final Map<String, ObjectChannel> channelIdMap = new HashMap<>();
-
-    public void initChannels(StoreProperties storeProperties, List<ObjectChannel> list) {
-        this.storeProperties = storeProperties;
-        for (ObjectChannel channel : list) {
-            int createBy = channel.getCreateBy();
-
-            String prefix = channel.getPrefix();
-            Integer channelId = channel.getChannelId();
-            prefixMap.put(createBy + "-" + prefix, channel);
-            channelIdMap.put(createBy + "-" + channelId, channel);
-        }
-    }
+    private final NodeService nodeService;
+    private final String nodeAddress;
 
-    public void updateStoreProperties(StoreProperties storeProperties) {
-        this.storeProperties = storeProperties;
+    public StoreLocalService(OssProperties ossProperties, NodeService nodeService) {
+        this.nodeAddress = ossProperties.getHost();
+        this.nodeService = nodeService;
     }
 
-    public StoreProperties getStoreProperties() {
-        return storeProperties;
+    public void register(StoreNodeDto storeNodeDto) {
+        nodeService.registerNode(storeNodeDto);
     }
 
     public String getDomain() {
-        return storeProperties != null ? storeProperties.getDomain() : null;
+        int loginUser = UserContext.getUser();
+        NodeProperties nodeProperties = nodeService.getNodeProperties(loginUser, nodeAddress);
+        return nodeProperties != null ? nodeProperties.getDomain() : null;
     }
 
     public String getReferer() {
-        return storeProperties != null ? storeProperties.getReferer() : null;
+        int loginUser = UserContext.getUser();
+        NodeProperties nodeProperties = nodeService.getNodeProperties(loginUser, nodeAddress);
+        return nodeProperties != null ? nodeProperties.getReferer() : null;
     }
 
     public String getSecretKey() {
-        return storeProperties != null ? storeProperties.getSecretKey() : null;
-    }
-
-    public void addObjectChannel(ObjectChannel channel) {
-        int createBy = channel.getCreateBy();
-        String prefix = channel.getPrefix();
-        Integer channelId = channel.getChannelId();
-        prefixMap.put(createBy + "-" + prefix, channel);
-        channelIdMap.put(createBy + "-" + channelId, channel);
+        int loginUser = UserContext.getUser();
+        NodeProperties nodeProperties = nodeService.getNodeProperties(loginUser, nodeAddress);
+        return nodeProperties != null ? nodeProperties.getSecretKey() : null;
     }
 
-    public ObjectChannel getChannelByChannelId(long loginUser, int channelId) {
-        return channelIdMap.get(loginUser + "-" + channelId);
-    }
-
-    public ObjectChannel getChannelByUrl(long loginUser, String url) {
-        String domain = storeProperties.getDomain();
-        String objectName = url.replace("//" + domain + "/", "");
-        for (String key : prefixMap.keySet()) {
-            String prefix = key.split("-")[1];
-            if (objectName.startsWith(prefix)) {
-                return prefixMap.get(loginUser + "-" + prefix);
-            }
-        }
-
-        return null;
-    }
-
-    public int getChannelIdByUrl(long loginUser, String url) {
-        ObjectChannel objectChannel = getChannelByUrl(loginUser, url);
-        if (objectChannel == null) {
-            return -1;
-        }
-
-        return objectChannel.getChannelId();
+    public ObjectChannel getChannelById(int loginUser, int channelId) {
+        return nodeService.getChannelById(loginUser, channelId);
     }
 
-    public List<ObjectChannel> getObjectChannels() {
-        return new ArrayList<>(prefixMap.values());
+    public int getChannelIdByUrl(int loginUser, String url) {
+        return nodeService.getChannelIdByUrl(loginUser, url);
     }
 }

+ 4 - 4
oss-store/src/main/java/cn/reghao/oss/store/config/UserContext.java → oss-store/src/main/java/cn/reghao/oss/store/util/UserContext.java

@@ -1,17 +1,17 @@
-package cn.reghao.oss.store.config;
+package cn.reghao.oss.store.util;
 
 /**
  * @author reghao
  * @date 2023-06-02 10:48:59
  */
 public class UserContext implements AutoCloseable {
-    static final ThreadLocal<Long> CURRENT = new ThreadLocal<>();
+    static final ThreadLocal<Integer> CURRENT = new ThreadLocal<>();
 
-    public UserContext(Long user) {
+    public UserContext(int user) {
         CURRENT.set(user);
     }
 
-    public static long getUser() {
+    public static int getUser() {
         return CURRENT.get();
     }
 

+ 0 - 36
oss-store/src/main/resources/mapper/FileMetaMapper.xml

@@ -159,41 +159,13 @@
         from file_meta
         where pid=#{pid}
     </select>
-    <select id="findFileInfoByPage" resultType="cn.reghao.oss.storeapi.dto.FileInfo">
-        select file_meta.object_id as file_id,file_meta.filename,file_meta.file_type as type,file_meta.size,file_meta.update_time,file_type.icon
-        from file_meta
-        inner join file_type
-        on file_meta.deleted=0 and file_meta.file_type=file_type.id and file_meta.pid=#{pid}
-        order by file_type asc
-    </select>
-    <select id="findFileInfo1ByPage" resultType="cn.reghao.oss.storeapi.dto.FileInfo">
-        select file_meta.object_id as file_id,file_meta.filename,file_meta.file_type as type,file_meta.size,file_meta.update_time,file_type.icon_large as icon
-        from file_meta
-        inner join file_type
-        on file_meta.deleted=0 and file_meta.file_type=file_type.id and file_meta.pid=#{pid}
-        order by file_type asc
-    </select>
 
     <select id="countDeletedFiles" resultType="java.lang.Integer">
         select count(*)
         from file_meta
         where deleted=1
     </select>
-    <select id="findDeletedFileByPage" resultType="cn.reghao.oss.storeapi.dto.DeleteFile">
-        select file_meta.object_id as file_id,file_meta.filename,file_meta.file_type as type,file_meta.size,file_meta.update_time,file_type.icon
-        from file_meta
-        inner join file_type
-        on file_meta.deleted=1 and file_meta.file_type=file_type.id
-        order by file_type asc
-    </select>
 
-    <select id="findDirectories" resultType="cn.reghao.oss.storeapi.dto.FileInfo">
-        select file_meta.object_id as file_id,file_meta.filename,file_meta.file_type as type,file_meta.size,file_meta.update_time,file_type.icon
-        from file_meta
-        inner join file_type
-        on file_meta.deleted=0 and file_meta.file_type=file_type.id and file_meta.file_type=1000 and file_meta.pid=#{pid}
-        order by file_type asc
-    </select>
     <select id="findByFilename" resultType="cn.reghao.oss.store.model.po.FileMeta">
         select *
         from file_meta
@@ -218,14 +190,6 @@
         from file_meta
         where filename like concat('%',#{keyword},'%')
     </select>
-    <select id="findKeywordByPage" resultType="cn.reghao.oss.storeapi.dto.FileInfo">
-        select file_meta.object_id as file_id,file_meta.filename,file_meta.file_type as type,file_meta.size,file_meta.update_time,file_type.icon
-        from file_meta
-        inner join file_type
-        on file_meta.deleted=0 and file_meta.file_type=file_type.id and file_meta.filename like concat('%',#{keyword},'%')
-        order by file_type asc
-    </select>
-
     <select id="findFileMetaByPage" resultType="cn.reghao.oss.store.model.po.FileMeta">
         select * from file_meta
         where file_type!=1000

+ 1 - 147
oss-store/src/test/java/FileMetaTest.java

@@ -2,13 +2,7 @@ import cn.reghao.oss.store.OssStoreApplication;
 import cn.reghao.oss.store.db.mapper.DataBlockMapper;
 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.jutil.jdk.db.Page;
-import cn.reghao.jutil.jdk.security.DigestUtil;
-import cn.reghao.jutil.jdk.thread.ThreadPoolWrapper;
 import lombok.extern.slf4j.Slf4j;
-import org.apache.commons.io.FileUtils;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -16,16 +10,7 @@ import org.springframework.boot.test.context.SpringBootTest;
 import org.springframework.test.context.ActiveProfiles;
 import org.springframework.test.context.junit4.SpringRunner;
 
-import java.io.File;
-import java.io.IOException;
-import java.nio.file.FileVisitResult;
-import java.nio.file.FileVisitor;
-import java.nio.file.Files;
-import java.nio.file.Path;
-import java.nio.file.attribute.BasicFileAttributes;
-import java.security.NoSuchAlgorithmException;
 import java.util.List;
-import java.util.concurrent.ExecutorService;
 
 /**
  * @author reghao
@@ -55,102 +40,6 @@ public class FileMetaTest {
         }
     }
 
-    /**
-     * 分页处理
-     *
-     * @param
-     * @return
-     * @date 2023-05-30 00:26:07
-     */
-    @Test
-    public void processByPage() {
-        int pageSize = 10_000;
-        int pageNumber = 1;
-        Page page = new Page(pageNumber, pageSize);
-        List<FileMeta> list = fileMetaMapper.findFileMetaByPage(page);
-        while (!list.isEmpty()) {
-            list.forEach(fileMeta -> {
-
-            });
-
-            pageNumber++;
-            page = new Page(pageNumber, pageSize);
-            list = fileMetaMapper.findFileMetaByPage(page);
-            log.info("page -> {}", pageNumber);
-        }
-    }
-
-    public void walkDir(Path path) throws IOException {
-        Files.walkFileTree(path, new FileVisitor<>() {
-            @Override
-            public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException {
-                return FileVisitResult.CONTINUE;
-            }
-
-            @Override
-            public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
-                String absolutePath = file.toString();
-                process(absolutePath);
-                return FileVisitResult.CONTINUE;
-            }
-
-            @Override
-            public FileVisitResult visitFileFailed(Path file, IOException exc) throws IOException {
-                return FileVisitResult.CONTINUE;
-            }
-
-            @Override
-            public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException {
-                return FileVisitResult.CONTINUE;
-            }
-        });
-    }
-
-    private void process(String absolutePath) {
-        try {
-            String sha256sum = DigestUtil.sha256sum(absolutePath);
-            FileMeta fileMeta = fileMetaMapper.findBySha256sum(sha256sum);
-            if (fileMeta != null) {
-                FileUtils.deleteQuietly(new File(absolutePath));
-                log.info("{} 删除 {} -> {}", Thread.currentThread().getName(), total++, absolutePath);
-            } else {
-                //log.info("{} 在 db 中不存在", absolutePath);
-            }
-        } catch (IOException | NoSuchAlgorithmException e) {
-            e.printStackTrace();
-        }
-    }
-
-    ExecutorService threadPool = ThreadPoolWrapper.threadPool("delete-pool", 10);
-    int total = 1;
-    @Test
-    public void deleteFile() throws IOException, InterruptedException {
-        String baseDir = "";
-        Path path = Path.of(baseDir);
-        //walkDir(path);
-
-        threadPool.submit(new Task(baseDir));
-        Thread.sleep(3600_000*24*7);
-    }
-
-    class Task implements Runnable {
-        private final String baseDir;
-
-        public Task(String baseDir) {
-            this.baseDir = baseDir;
-        }
-
-        @Override
-        public void run() {
-            Path path = Path.of(baseDir);
-            try {
-                walkDir(path);
-            } catch (IOException e) {
-                e.printStackTrace();
-            }
-        }
-    }
-
     @Autowired
     DataBlockMapper dataBlockMapper;
     @Test
@@ -159,46 +48,11 @@ public class FileMetaTest {
         int nextId = 0;
         List<DataBlock> list = dataBlockMapper.findDataBlocks(pageSize, nextId);
         while (!list.isEmpty()) {
-            process1(list);
-            dataBlockMapper.updateBatch(list);
+            // process DataBlocks
 
             nextId = list.get(list.size()-1).getId();
             list = dataBlockMapper.findDataBlocks(pageSize, nextId);
             log.info("nextId -> {}", nextId);
         }
     }
-
-    private void process(List<DataBlock> list) {
-        for (DataBlock dataBlock : list) {
-            String contentId = dataBlock.getContentId();
-            List<FileMeta> list1 = fileMetaMapper.findByContentId(contentId);
-            if (list1.isEmpty()) {
-                log.info("{} not exist in file_meta", contentId);
-            }
-        }
-    }
-
-    private void process1(List<DataBlock> list) {
-        for (DataBlock dataBlock : list) {
-            int id = dataBlock.getId();
-            String absolutePath = dataBlock.getAbsolutePath();
-            int idx = absolutePath.lastIndexOf("/");
-            String parent = absolutePath.substring(0, idx);
-            String relativeDir = parent.replace("", "");
-            //dataBlock.setRelativeDir(relativeDir);
-
-            /*String contentId = dataBlock.getContentId();
-            List<FileMeta> list1 = fileMetaMapper.findByContentId(contentId);
-            if (list1.isEmpty()) {
-                log.info("{} not exist in file_meta", contentId);
-            }*/
-        }
-    }
-
-    @Test
-    public void test123() {
-        String baseDir = "";
-        List<SubDirCount> list = dataBlockMapper.findSubDirCount("");
-        System.out.println();
-    }
 }

+ 0 - 123
oss-store/src/test/java/LocalFileTest.java

@@ -1,123 +0,0 @@
-import cn.reghao.oss.store.util.FileType;
-import cn.reghao.jutil.media.FFmpegWrapper;
-import cn.reghao.jutil.media.MediaQuality;
-import cn.reghao.jutil.media.MediaResolution;
-import cn.reghao.jutil.media.model.AudioProps;
-import cn.reghao.jutil.media.model.MediaProps;
-import cn.reghao.jutil.media.model.VideoProps;
-import cn.reghao.jutil.jdk.security.DigestUtil;
-import lombok.extern.slf4j.Slf4j;
-import org.apache.commons.io.FileUtils;
-import org.junit.Test;
-
-import java.io.File;
-import java.io.IOException;
-import java.nio.file.FileVisitResult;
-import java.nio.file.FileVisitor;
-import java.nio.file.Files;
-import java.nio.file.Path;
-import java.nio.file.attribute.BasicFileAttributes;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-/**
- * @author reghao
- * @date 2023-03-22 16:19:12
- */
-@Slf4j
-public class LocalFileTest {
-    public void walkDir(Path path) throws IOException {
-        Files.walkFileTree(path, new FileVisitor<>() {
-            @Override
-            public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException {
-                return FileVisitResult.CONTINUE;
-            }
-
-            @Override
-            public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
-                String absolutePath = file.toString();
-                process(absolutePath);
-                return FileVisitResult.CONTINUE;
-            }
-
-            @Override
-            public FileVisitResult visitFileFailed(Path file, IOException exc) throws IOException {
-                return FileVisitResult.CONTINUE;
-            }
-
-            @Override
-            public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException {
-                return FileVisitResult.CONTINUE;
-            }
-        });
-    }
-
-    private void process(String absolutePath) {
-        String mediaType = FileType.getMediaType(absolutePath);
-        if (mediaType.startsWith("text")) {
-            FileUtils.deleteQuietly(new File(absolutePath));
-        }
-    }
-
-    private void getMediaInfo(String absolutePath) {
-        MediaProps mediaProps = FFmpegWrapper.getMediaProps(absolutePath);
-        if (mediaProps == null) {
-            log.error("{} 没有媒体信息", absolutePath);
-            return;
-        }
-
-        AudioProps audioProps = mediaProps.getAudioProps();
-        if (audioProps == null) {
-            log.error("{} 没有音频信息", absolutePath);
-            return;
-        }
-
-        VideoProps videoProps = mediaProps.getVideoProps();
-        if (videoProps == null) {
-            log.error("{} 没有视频信息", absolutePath);
-            return;
-        }
-
-        String audioCodec = audioProps.getCodecName();
-        String videoCodec = videoProps.getCodecName();
-        int width = videoProps.getCodedWidth().intValue();
-        int height = videoProps.getCodedHeight().intValue();
-        if ("aac".equals(audioCodec) && "h264".equals(videoCodec)) {
-            MediaResolution mediaResolution = MediaQuality.getQuality(width, height);
-        } else {
-            log.error("{} 不是 aac&h264", absolutePath);
-        }
-    }
-
-    Map<String, String> map = new HashMap<>();
-    List<String> list = new ArrayList<>();
-    private void unique(String absolutePath) {
-        try {
-            String sha256sum = DigestUtil.sha256sum(absolutePath);
-            String filePath = map.get(sha256sum);
-            if (filePath == null) {
-                map.put(sha256sum, filePath);
-            } else {
-                log.info("{} 已存在", filePath);
-                list.add(filePath);
-            }
-        } catch (Exception e) {
-            e.printStackTrace();
-        }
-    }
-
-    @Test
-    public void test22() throws IOException {
-        String baseDir = "";
-        Path path = Path.of(baseDir);
-        walkDir(path);
-
-        /*String filePath = "";
-        String filePath1 = "";
-        String mediaType = FileType.getMediaType(filePath);
-        MediaProps mediaProps = FFmpegWrapper.getMediaProps(filePath);
-        FFmpegWrapper.convertAudio(filePath, filePath1);*/
-    }
-}

+ 0 - 28
store-api/src/main/java/cn/reghao/oss/storeapi/dto/DeleteFile.java

@@ -1,28 +0,0 @@
-package cn.reghao.oss.storeapi.dto;
-
-import lombok.Getter;
-import lombok.Setter;
-
-import java.io.Serializable;
-
-/**
- * @author reghao
- * @date 2023-05-15 17:06:54
- */
-@Setter
-@Getter
-public class DeleteFile implements Serializable {
-    private static final long serialVersionUID = 1L;
-
-    private String fileId;
-    private String filename;
-    private int type;
-    private String icon;
-    private long size;
-    private String updateTime;
-    private int leftDays;
-
-    public DeleteFile() {
-        this.leftDays = 10;
-    }
-}

+ 0 - 23
store-api/src/main/java/cn/reghao/oss/storeapi/dto/FileInfo.java

@@ -1,23 +0,0 @@
-package cn.reghao.oss.storeapi.dto;
-
-import lombok.Getter;
-import lombok.Setter;
-
-import java.io.Serializable;
-
-/**
- * @author reghao
- * @date 2023-05-15 17:06:54
- */
-@Setter
-@Getter
-public class FileInfo implements Serializable {
-    private static final long serialVersionUID = 1L;
-
-    private String fileId;
-    private String filename;
-    private int type;
-    private String icon;
-    private long size;
-    private String updateTime;
-}

+ 33 - 0
store-api/src/main/java/cn/reghao/oss/storeapi/dto/NodeProperties.java

@@ -0,0 +1,33 @@
+package cn.reghao.oss.storeapi.dto;
+
+import java.io.Serializable;
+
+/**
+ * @author reghao
+ * @date 2024-03-01 09:22:17
+ */
+public class NodeProperties implements Serializable {
+    private static final long serialVersionUID = 1L;
+
+    private String domain;
+    private String secretKey;
+    private String referer;
+
+    public NodeProperties(String domain, String secretKey, String referer) {
+        this.domain = domain;
+        this.secretKey = secretKey;
+        this.referer = referer;
+    }
+
+    public String getDomain() {
+        return domain;
+    }
+
+    public String getSecretKey() {
+        return secretKey;
+    }
+
+    public String getReferer() {
+        return referer;
+    }
+}

+ 1 - 1
store-api/src/main/java/cn/reghao/oss/storeapi/dto/OssPayload.java

@@ -16,5 +16,5 @@ public class OssPayload implements Serializable {
 
     private String action;
     private int channelId;
-    private long userId;
+    private int userId;
 }

+ 0 - 3
store-api/src/main/java/cn/reghao/oss/storeapi/dto/StoreInfo.java

@@ -1,6 +1,5 @@
 package cn.reghao.oss.storeapi.dto;
 
-import cn.reghao.tnb.file.api.dto.ObjectChannel;
 import lombok.AllArgsConstructor;
 import lombok.Getter;
 
@@ -16,7 +15,5 @@ import java.util.List;
 public class StoreInfo implements Serializable {
     private static final long serialVersionUID = 1L;
 
-    private StoreProperties storeProperties;
-    private List<ObjectChannel> objectChannels;
     private List<StoreDiskDto> storeDisks;
 }

+ 16 - 0
store-api/src/main/java/cn/reghao/oss/storeapi/iface/NodeService.java

@@ -0,0 +1,16 @@
+package cn.reghao.oss.storeapi.iface;
+
+import cn.reghao.oss.storeapi.dto.NodeProperties;
+import cn.reghao.oss.storeapi.dto.StoreNodeDto;
+import cn.reghao.tnb.file.api.dto.ObjectChannel;
+
+/**
+ * @author reghao
+ * @date 2024-07-02 10:55:56
+ */
+public interface NodeService {
+    void registerNode(StoreNodeDto storeNodeDto);
+    NodeProperties getNodeProperties(int owner, String nodeAddress);
+    ObjectChannel getChannelById(int owner, int channelId);
+    int getChannelIdByUrl(int loginUser, String url);
+}

+ 1 - 4
store-api/src/main/java/cn/reghao/oss/storeapi/iface/StoreService.java

@@ -2,15 +2,12 @@ package cn.reghao.oss.storeapi.iface;
 
 import cn.reghao.tnb.file.api.dto.ObjectChannel;
 import cn.reghao.oss.storeapi.dto.StoreInfo;
-import cn.reghao.oss.storeapi.dto.StoreProperties;
 
 /**
  * @author reghao
  * @date 2023-08-01 14:51:50
  */
 public interface StoreService {
-    String getUploadToken(long userId, int channelId);
-    void createChannel(long userId, ObjectChannel channel);
-    void updateStoreProperties(StoreProperties storeProperties);
+    void createChannel(int userId, ObjectChannel channel);
     StoreInfo getStoreInfo();
 }