Procházet zdrojové kódy

上传接口统一返回 UploadFileRet 对象

reghao před 2 roky
rodič
revize
4b07d25e43

+ 11 - 2
dfs-store/src/main/java/cn/reghao/dfs/store/controller/ObjectUploadController.java

@@ -6,6 +6,7 @@ import cn.reghao.dfs.store.util.ObjectUtil;
 import cn.reghao.jutil.jdk.result.WebResult;
 import cn.reghao.jutil.jdk.security.DigestUtil;
 import cn.reghao.jutil.web.ServletUtil;
+import cn.reghao.oss.common.UploadFileRet;
 import org.apache.commons.io.FileUtils;
 import org.springframework.web.bind.annotation.PostMapping;
 import org.springframework.web.bind.annotation.PutMapping;
@@ -56,7 +57,11 @@ public class ObjectUploadController {
             putObjectService.putObject(pid, objectName, contentId, savedFile, originalFilename, sha256sum);
             // TODO PutMessageConverter 中生成的文件需要显式删除
             FileUtils.deleteQuietly(file);
-            return WebResult.success();
+
+            String uploadId = sha256sum;
+            String url = String.format("https://oss.reghao.cn/%s", objectName);
+            UploadFileRet uploadFileRet = new UploadFileRet(uploadId, url);
+            return WebResult.success(uploadFileRet);
         } catch (Exception e) {
             FileUtils.deleteQuietly(file);
             String errMsg = e.getMessage();
@@ -78,6 +83,10 @@ public class ObjectUploadController {
         String pid = putObjectService.getPid(objectName);
         String originalFilename = file.getOriginalFilename();
         putObjectService.putObject(pid, objectName, contentId, savedFile, originalFilename, sha256sum);
-        return WebResult.success();
+
+        String uploadId = sha256sum;
+        String url = String.format("https://oss.reghao.cn/%s", objectName);
+        UploadFileRet uploadFileRet = new UploadFileRet(uploadId, url);
+        return WebResult.success(uploadFileRet);
     }
 }

+ 1 - 1
dfs-store/src/main/java/cn/reghao/dfs/store/rpc/FileServiceImpl.java

@@ -97,7 +97,7 @@ public class FileServiceImpl implements FileService {
         long size = fileMeta.getSize();
         String contentType = fileMeta.getContentType();
         String sha256sum = fileMeta.getSha256sum();
-        String url = String.format("https://file.reghao.cn/%s", fileMeta.getObjectName());
+        String url = String.format("https://oss.reghao.cn/%s", fileMeta.getObjectName());
         return new FileProp(path, filename, size, contentType, sha256sum, url);
     }
 

+ 4 - 3
dfs-store/src/main/java/cn/reghao/dfs/store/service/ObjectMultipartUploadService.java

@@ -45,7 +45,7 @@ public class ObjectMultipartUploadService {
             return new UploadPrepareRet("uploadId", PART_SIZE, false, null);
         } else {
             String objectName = fileMeta.getObjectName();
-            String url = String.format("https://file.reghao.cn/%s", objectName);
+            String url = String.format("https://oss.reghao.cn/%s", objectName);
             return new UploadPrepareRet("uploadId", PART_SIZE, false, url);
         }
     }
@@ -72,7 +72,8 @@ public class ObjectMultipartUploadService {
         if (fileMeta != null) {
             String objectName = ObjectUtil.getObjectName(uploadFilePart.getChannelId());
             putObjectService.copyObject(objectName, filename, fileMeta);
-            String url = String.format("https://file.reghao.cn/%s", objectName);
+
+            String url = String.format("https://oss.reghao.cn/%s", objectName);
             return new UploadFileRet(sha256sum, url);
         }
 
@@ -113,7 +114,7 @@ public class ObjectMultipartUploadService {
 
             map.remove(sha256sum);
             pathMap.remove(sha256sum);
-            String url = String.format("https://file.reghao.cn/%s", objectName);
+            String url = String.format("https://oss.reghao.cn/%s", objectName);
             return new UploadFileRet(sha256sum, url);
         }
     }

+ 1 - 1
dfs-store/src/main/java/cn/reghao/dfs/store/task/ImageFileService.java

@@ -76,7 +76,7 @@ public class ImageFileService {
         String tmpPath = "/opt/tmp/tomcat/" + UUID.randomUUID().toString().replace("-", "");
         saveFile(tmpPath, bytes);
         File file = new File(tmpPath);
-        return String.format("//file.reghao.cn/%s", objectKey);
+        return String.format("//oss.reghao.cn/%s", objectKey);
     }
 
     private void saveFile(String absolutePath, byte[] bytes) throws IOException {