Jelajahi Sumber

oss-store 中直接调用 storeLocalCache.getDomain() 获取 domain 的值

reghao 2 tahun lalu
induk
melakukan
4476d0a988

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

@@ -66,8 +66,7 @@ public class ObjectGetController {
         }
 
         String queryString = String.format("token=%s&t=%s&nonce=%s", token, timestamp, nonce);
-        String domain = storeLocalCache.getDomain();
-        String url = String.format("//%s/%s", domain, objectName);
+        String url = String.format("//%s/%s", storeLocalCache.getDomain(), objectName);
         String requestString = String.format("%s%s?%s", "GET", url, queryString);
         boolean valid = SignatureUtil.valid(requestString, storeLocalCache.getSecretKey(), sign);
         if (!valid) {

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

@@ -26,12 +26,12 @@ import java.util.UUID;
 public class FileServiceImpl implements FileService {
     private final PutObjectService putObjectService;
     private final FileMetaMapper fileMetaMapper;
-    private final String domain;
+    private final StoreLocalCache storeLocalCache;
 
     public FileServiceImpl(PutObjectService putObjectService, FileMetaMapper fileMetaMapper, StoreLocalCache storeLocalCache) {
         this.fileMetaMapper = fileMetaMapper;
         this.putObjectService = putObjectService;
-        this.domain = storeLocalCache.getDomain();
+        this.storeLocalCache = storeLocalCache;
     }
 
     @Override
@@ -96,7 +96,7 @@ public class FileServiceImpl implements FileService {
         long size = fileMeta.getSize();
         String contentType = fileMeta.getContentType();
         String sha256sum = fileMeta.getSha256sum();
-        String url = String.format("https://%s/%s", domain, fileMeta.getObjectName());
+        String url = String.format("https://%s/%s", storeLocalCache.getDomain(), fileMeta.getObjectName());
         return new FileProp(path, filename, size, contentType, sha256sum, url);
     }
 

+ 3 - 3
oss-store/src/main/java/cn/reghao/oss/store/service/GetObjectService.java

@@ -24,11 +24,11 @@ public class GetObjectService {
     private final FileMetaMapper fileMetaMapper;
     // 1MiB
     private final int bufSize = 1024*1024;
-    private final String domain;
+    private final StoreLocalCache storeLocalCache;
 
     public GetObjectService(FileMetaMapper fileMetaMapper, StoreLocalCache storeLocalCache) {
         this.fileMetaMapper = fileMetaMapper;
-        this.domain = storeLocalCache.getDomain();
+        this.storeLocalCache = storeLocalCache;
     }
     
     public void headObject(String objectName) throws IOException {
@@ -79,7 +79,7 @@ public class GetObjectService {
             ContentRange contentRange = parseContentRange(range, len);
             writeContentRange(objectMeta, contentRange);
         } else {
-            if (host.contains(domain)) {
+            if (host.contains(storeLocalCache.getDomain())) {
                 writeWholeContent(objectMeta);
             } else {
                 writeDownloadContent(objectMeta);

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

@@ -33,7 +33,7 @@ public class ObjectMultipartUploadService {
     private final Map<String, PathUrl> pathMap = new HashMap<>();
     private final ObjectNameService objectNameService;
     private final PutObjectService putObjectService;
-    private final String domain;
+    private final StoreLocalCache storeLocalCache;
 
     public ObjectMultipartUploadService(FileMetaMapper fileMetaMapper, FileStoreService fileStoreService,
                                         ObjectNameService objectNameService, PutObjectService putObjectService,
@@ -42,7 +42,7 @@ public class ObjectMultipartUploadService {
         this.fileStoreService = fileStoreService;
         this.objectNameService = objectNameService;
         this.putObjectService = putObjectService;
-        this.domain = storeLocalCache.getDomain();
+        this.storeLocalCache = storeLocalCache;
     }
 
     public synchronized UploadPrepareRet prepareUpload(UploadPrepare uploadPrepare) {
@@ -52,7 +52,7 @@ public class ObjectMultipartUploadService {
             return new UploadPrepareRet("uploadId", PART_SIZE, false, null);
         } else {
             String objectName = fileMeta.getObjectName();
-            String url = String.format("https://%s/%s", domain, objectName);
+            String url = String.format("https://%s/%s", storeLocalCache.getDomain(), objectName);
             return new UploadPrepareRet("uploadId", PART_SIZE, false, url);
         }
     }
@@ -83,7 +83,7 @@ public class ObjectMultipartUploadService {
             ObjectProp objectProp = objectNameService.getObjectProp(objectChannel, suffix);
             putObjectService.copyObject(objectProp, filename, fileMeta);
 
-            String url = String.format("https://%s/%s", domain, objectProp);
+            String url = String.format("https://%s/%s", storeLocalCache.getDomain(), objectProp);
             return new UploadFileRet(sha256sum, url);
         }
 
@@ -125,7 +125,7 @@ public class ObjectMultipartUploadService {
 
             map.remove(sha256sum);
             pathMap.remove(sha256sum);
-            String url = String.format("https://%s/%s", domain, objectProp);
+            String url = String.format("https://%s/%s", storeLocalCache.getDomain(), objectProp);
             return new UploadFileRet(sha256sum, url);
         }
     }

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

@@ -18,15 +18,15 @@ import java.util.UUID;
 @Service
 public class ObjectNameService {
     private final ObjectRepository objectRepository;
-    private final String domain;
+    private final StoreLocalCache storeLocalCache;
 
     public ObjectNameService(ObjectRepository objectRepository, StoreLocalCache storeLocalCache) {
         this.objectRepository = objectRepository;
-        this.domain = storeLocalCache.getDomain();
+        this.storeLocalCache = storeLocalCache;
     }
 
     public String getObjectUrl(String objectName) {
-        return String.format("//%s/%s", domain, objectName);
+        return String.format("//%s/%s", storeLocalCache.getDomain(), objectName);
     }
 
     public ObjectProp getObjectProp(ObjectChannel channel, String filename) throws Exception {