Browse Source

1.注释 DataBlock 中没有使用的字段
2.DataBlock 的构造函数中添加 host 参数

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

+ 1 - 1
oss-console/src/main/java/cn/reghao/oss/console/app/service/OssStoreService.java

@@ -45,6 +45,6 @@ public class OssStoreService {
         String domain = storeNode.getDomain();
         String referer = storeNode.getReferer();
         String secretKey = storeNode.getSecretKey();
-        return new StoreProperties(domain, referer, secretKey);
+        return new StoreProperties(nodeAddr, domain, referer, secretKey);
     }
 }

+ 2 - 1
oss-console/src/main/java/cn/reghao/oss/console/app/service/StoreNodeService.java

@@ -64,6 +64,7 @@ public class StoreNodeService {
             return Result.success();
         }
 
+        String nodeAddr = storeNode.getNodeAddr();
         String secretKey = nodeUpdateDto.getSecretKey();
         String referer = nodeUpdateDto.getReferer();
         storeNode.setDomain(domain);
@@ -72,7 +73,7 @@ public class StoreNodeService {
         storeNode.setEnabled(true);
         storeNodeRepository.save(storeNode);
 
-        StoreProperties storeProperties = new StoreProperties(domain, secretKey, referer);
+        StoreProperties storeProperties = new StoreProperties(nodeAddr, domain, secretKey, referer);
         StoreService storeService = rpcService.getStoreService(storeNode);
         storeService.updateStoreProperties(storeProperties);
         return Result.success();

+ 8 - 11
oss-store/src/main/java/cn/reghao/oss/store/model/po/DataBlock.java

@@ -1,7 +1,6 @@
 package cn.reghao.oss.store.model.po;
 
 import cn.reghao.jutil.jdk.db.BaseObject;
-import lombok.AllArgsConstructor;
 import lombok.Getter;
 import lombok.NoArgsConstructor;
 import lombok.Setter;
@@ -11,27 +10,25 @@ import lombok.Setter;
  * @date 2022-11-24 10:25:18
  */
 @NoArgsConstructor
-@AllArgsConstructor
 @Setter
 @Getter
 public class DataBlock extends BaseObject<Integer> {
     private String contentId;
-    private int index;
     private String blockId;
     private String host;
-    private String baseDir;
-    private String relativeDir;
     private String absolutePath;
     private long size;
-    private long start;
-    private long end;
-    @Deprecated
-    private String objectId;
+    //private String baseDir;
+    //private String relativeDir;
+    //private int index;
+    //private long start;
+    //private long end;
+    //private String objectId;
 
-    public DataBlock(String contentId, int index, String blockId, String absolutePath, long size) {
+    public DataBlock(String contentId, String blockId, String host, String absolutePath, long size) {
         this.contentId = contentId;
-        this.index = index;
         this.blockId = blockId;
+        this.host = host;
         this.absolutePath = absolutePath;
         this.size = size;
     }

+ 5 - 2
oss-store/src/main/java/cn/reghao/oss/store/service/PutObjectService.java

@@ -25,10 +25,13 @@ import java.util.UUID;
 public class PutObjectService {
     private final ObjectRepository objectRepository;
     private final ObjectNameService objectNameService;
+    private final String host;
 
-    public PutObjectService(ObjectRepository objectRepository, ObjectNameService objectNameService) {
+    public PutObjectService(ObjectRepository objectRepository, ObjectNameService objectNameService,
+                            StoreLocalCache storeLocalCache) {
         this.objectRepository = objectRepository;
         this.objectNameService = objectNameService;
+        this.host = storeLocalCache.getHost();
     }
 
     public ObjectResult putObject(ObjectProp objectProp, String contentId, File savedFile, String originalFilename, String sha256sum) {
@@ -48,7 +51,7 @@ public class PutObjectService {
             fileMeta = new FileMeta(objectName, objectId, contentId, originalFilename, size,
                     fileType, contentType, sha256sum, pid, scope);
             String blockId = UUID.randomUUID().toString();
-            List<DataBlock> list = List.of(new DataBlock(contentId, 0, blockId, savedPath, size));
+            List<DataBlock> list = List.of(new DataBlock(contentId, blockId, host, savedPath, size));
             objectRepository.saveObject(fileMeta, list);
             return new ObjectResult(objectName, objectId, fileType, savedPath);
         }

+ 4 - 0
oss-store/src/main/java/cn/reghao/oss/store/service/StoreLocalCache.java

@@ -32,6 +32,10 @@ public class StoreLocalCache {
         this.storeProperties = storeProperties;
     }
 
+    public String getHost() {
+        return storeProperties != null ? storeProperties.getHost() : null;
+    }
+
     public String getDomain() {
         return storeProperties != null ? storeProperties.getDomain() : null;
     }

+ 4 - 4
oss-store/src/main/resources/mapper/DataBlockMapper.xml

@@ -4,16 +4,16 @@
 <mapper namespace="cn.reghao.oss.store.db.mapper.DataBlockMapper">
     <insert id="save" useGeneratedKeys="true" keyProperty="id">
         insert into data_block
-        (`content_id`,`index`,`block_id`,`host`,`base_dir`,`relative_dir`,`absolute_path`,`size`,`start`,`end`)
+        (`content_id`,`block_id`,`host`,`absolute_path`,`size`)
         values
-        (#{contentId},#{index},#{blockId},#{host},#{baseDir},#{relativeDir},#{absolutePath},#{size},#{start},#{end})
+        (#{contentId},#{blockId},#{host},#{absolutePath},#{size})
     </insert>
     <insert id="saveAll" useGeneratedKeys="true" keyProperty="id">
         insert into data_block
-        (`content_id`,`index`,`block_id`,`host`,`base_dir`,`relative_dir`,`absolute_path`,`size`,`start`,`end`)
+        (`content_id`,`block_id`,`host`,`absolute_path`,`size`)
         values
         <foreach collection="list" item="item" index="index" separator=",">
-            (#{item.contentId},#{item.index},#{item.blockId},#{item.host},#{item.baseDir},#{item.relativeDir},#{item.absolutePath},#{item.size},#{item.start},#{item.end})
+            (#{item.contentId},#{item.blockId},#{item.host},#{item.absolutePath},#{item.size})
         </foreach>
     </insert>
 

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

@@ -185,7 +185,7 @@ public class FileMetaTest {
             int idx = absolutePath.lastIndexOf("/");
             String parent = absolutePath.substring(0, idx);
             String relativeDir = parent.replace("", "");
-            dataBlock.setRelativeDir(relativeDir);
+            //dataBlock.setRelativeDir(relativeDir);
 
             /*String contentId = dataBlock.getContentId();
             List<FileMeta> list1 = fileMetaMapper.findByContentId(contentId);

+ 1 - 0
store-api/src/main/java/cn/reghao/oss/store/api/dto/StoreProperties.java

@@ -14,6 +14,7 @@ import java.io.Serializable;
 public class StoreProperties implements Serializable {
     private static final long serialVersionUID = 1L;
 
+    private String host;
     private String domain;
     private String referer;
     private String secretKey;