فهرست منبع

update file-service ConsoleServiceImpl

reghao 5 ماه پیش
والد
کامیت
af5c20624c

+ 16 - 5
file/file-service/src/main/java/cn/reghao/tnb/file/app/rpc/ConsoleServiceImpl.java

@@ -6,7 +6,9 @@ import cn.reghao.oss.api.dto.StoreNodeDto;
 import cn.reghao.oss.api.iface.ConsoleService;
 import cn.reghao.oss.api.iface.StoreService;
 import cn.reghao.oss.sdk.model.dto.ServerInfo;
-import cn.reghao.tnb.common.auth.UserContext;
+import cn.reghao.tnb.file.app.db.mapper.StoreConfigMapper;
+import cn.reghao.tnb.file.app.model.constant.OssType;
+import cn.reghao.tnb.file.app.model.po.StoreConfig;
 import cn.reghao.tnb.file.app.model.po.StoreNode;
 import cn.reghao.tnb.file.app.model.po.UploadChannel;
 import cn.reghao.tnb.file.app.model.po.UserNode;
@@ -16,6 +18,7 @@ import cn.reghao.tnb.file.app.service.UserNodeService;
 import org.apache.dubbo.config.annotation.DubboService;
 import org.springframework.stereotype.Service;
 
+import javax.annotation.PostConstruct;
 import java.util.List;
 
 /**
@@ -25,17 +28,26 @@ import java.util.List;
 @DubboService
 @Service
 public class ConsoleServiceImpl implements ConsoleService {
+    private int ossUser = -1;
     private final UploadChannelService uploadChannelService;
     private final StoreNodeService storeNodeService;
     private final UserNodeService userNodeService;
     private final RpcService rpcService;
+    private final StoreConfigMapper storeConfigMapper;
 
     public ConsoleServiceImpl(UploadChannelService uploadChannelService, StoreNodeService storeNodeService,
-                              UserNodeService userNodeService, RpcService rpcService) {
+                              UserNodeService userNodeService, RpcService rpcService, StoreConfigMapper storeConfigMapper) {
         this.uploadChannelService = uploadChannelService;
         this.storeNodeService = storeNodeService;
         this.userNodeService = userNodeService;
         this.rpcService = rpcService;
+        this.storeConfigMapper = storeConfigMapper;
+    }
+
+    @PostConstruct
+    public void postSetOwner() {
+        StoreConfig storeConfig = storeConfigMapper.findByOssType(OssType.localOss.getValue());
+        this.ossUser = Integer.parseInt(storeConfig.getAccessKeyId());
     }
 
     @Override
@@ -78,8 +90,7 @@ public class ConsoleServiceImpl implements ConsoleService {
 
     @Override
     public ServerInfo getUploadStore(int channelCode) {
-        long owner = UserContext.getUserId();
-        UploadChannel uploadChannel = uploadChannelService.getByChannelCodeAndCreateBy(channelCode, owner);
+        UploadChannel uploadChannel = uploadChannelService.getByChannelCodeAndCreateBy(channelCode, ossUser);
         if (uploadChannel == null) {
             String errMsg = String.format("channelCode %s not exist", channelCode);
             return null;
@@ -101,7 +112,7 @@ public class ConsoleServiceImpl implements ConsoleService {
 
             // 多少秒后 token 过期
             int expire = 3600;
-            String uploadToken = storeService.getUploadToken(channelCode, (int) owner, expire);
+            String uploadToken = storeService.getUploadToken(channelCode, ossUser, expire);
             return new ServerInfo(ossUrl, channelCode, maxSize, uploadToken);
         } catch (Exception e) {
             e.printStackTrace();

+ 1 - 1
file/file-service/src/main/java/cn/reghao/tnb/file/app/rpc/StoreServiceWrapperRouter.java

@@ -25,7 +25,7 @@ import javax.annotation.PostConstruct;
 @DubboService
 @Service
 public class StoreServiceWrapperRouter implements OssService {
-    private int owner = 10001;
+    private int owner = -1;
     private final int ossType;
     private final ConsoleService consoleService;
     private final StoreServiceWrapper storeServiceWrapper;