Переглянути джерело

oss-store 的 ObjectService#setObjectsScope 方法传入 objectId 作为参数

reghao 2 роки тому
батько
коміт
8d951e2c16

+ 1 - 1
oss-console/src/main/java/cn/reghao/oss/console/app/model/dto/ObjectsScopeDto.java

@@ -14,5 +14,5 @@ import java.util.List;
 public class ObjectsScopeDto {
     private Integer channelId;
     private Integer scope;
-    private List<String> objectNames;
+    private List<String> objectIds;
 }

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

@@ -27,8 +27,8 @@ public class OssObjectService {
         int channelId = objectsScopeDto.getChannelId();
         ObjectService objectService = getObjectService(channelId);
         int scope = objectsScopeDto.getScope();
-        List<String> objectNames = objectsScopeDto.getObjectNames();
-        objectService.setObjectsScope(scope, objectNames);
+        List<String> objectIds = objectsScopeDto.getObjectIds();
+        objectService.setObjectsScope(scope, objectIds);
     }
 
     public void deleteByObjectNames(int channelId, List<String> objectNames) throws Exception {

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

@@ -233,12 +233,12 @@ public class OssConsoleClient {
         }
     }
 
-    public void setObjectsScope(int channelId, List<String> objectNames, int scope) throws Exception {
-        String objectNamesStr = objectNames.toString().replace("[", "").replace("]", "");
+    public void setObjectsScope(int channelId, List<String> objectIds, int scope) throws Exception {
+        String objectIdsStr = objectIds.toString().replace("[", "").replace("]", "");
         Map<String, String> formData = new HashMap<>();
         formData.put("channelId", channelId+"");
         formData.put("scope", scope+"");
-        formData.put("objectNames", objectNamesStr);
+        formData.put("objectIds", objectIdsStr);
 
         String api = String.format("%s/api/oss/object/scope/objects", endpoint);
         HttpRequest httpRequest = HttpRequest.newBuilder(new URI(api))

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

@@ -4,7 +4,6 @@ import cn.reghao.oss.store.api.dto.ObjectChannel;
 import cn.reghao.oss.store.model.vo.ObjectProp;
 import cn.reghao.oss.store.model.vo.ObjectResult;
 import cn.reghao.oss.store.service.*;
-import cn.reghao.oss.store.task.FileProcessor;
 import cn.reghao.oss.store.util.JwtUtil;
 import cn.reghao.jutil.jdk.result.Result;
 import cn.reghao.jutil.jdk.result.WebResult;
@@ -33,19 +32,16 @@ public class ObjectUploadController {
     private final FileStoreService fileStoreService;
     private final ObjectNameService objectNameService;
     private final PutObjectService putObjectService;
-    private final FileProcessor fileProcessor;
     private final StoreLocalCache storeLocalCache;
-    private StoreChannelService storeChannelService;
+    private final StoreChannelService storeChannelService;
 
     public ObjectUploadController(ChannelValidateService channelValidateService, FileStoreService fileStoreService,
                                   ObjectNameService objectNameService, PutObjectService putObjectService,
-                                  FileProcessor fileProcessor, StoreLocalCache storeLocalCache,
-                                  StoreChannelService storeChannelService) {
+                                  StoreLocalCache storeLocalCache, StoreChannelService storeChannelService) {
         this.channelValidateService = channelValidateService;
         this.fileStoreService = fileStoreService;
         this.objectNameService = objectNameService;
         this.putObjectService = putObjectService;
-        this.fileProcessor = fileProcessor;
         this.storeLocalCache = storeLocalCache;
         this.storeChannelService = storeChannelService;
     }
@@ -113,18 +109,10 @@ public class ObjectUploadController {
 
         ObjectProp objectProp = objectNameService.getObjectProp(objectChannel, filename);
         ObjectResult objectResult = putObjectService.putObject(objectProp, contentId, savedFile, filename, sha256sum1);
-        UploadFileRet uploadFileRet;
-        String errMsg;
-        try {
-            uploadFileRet = fileProcessor.process(objectResult, objectChannel);
-            return ResponseEntity.status(HttpStatus.OK).body(WebResult.success(uploadFileRet));
-        } catch (Exception e) {
-            e.printStackTrace();
-            errMsg = e.getMessage();
-        }
-
-        putObjectService.deleteObject(objectResult.getObjectId());
-        return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(errMsg);
+        String objectId = objectResult.getObjectId();
+        String objectUrl = objectNameService.getObjectUrl(objectResult.getObjectName());
+        UploadFileRet uploadFileRet = new UploadFileRet(objectId, objectUrl);
+        return ResponseEntity.status(HttpStatus.OK).body(WebResult.success(uploadFileRet));
     }
 
     @DeleteMapping(value = "/")

+ 0 - 5
oss-store/src/main/java/cn/reghao/oss/store/db/repository/ObjectRepository.java

@@ -40,11 +40,6 @@ public class ObjectRepository {
         dataBlockMapper.saveAll(list);
     }
 
-    public void updateObjectsScope(int scope, List<String> objectNames) {
-        //fileMetaMapper.updateScopeByObjectNames(scope, objectNames);
-        objectNames.forEach(objectName -> updateObjectScope(scope, objectName));
-    }
-
     @CacheEvict(cacheNames = "oss:store:objectMeta", key = "#objectName")
     public void updateObjectScope(int scope, String objectName) {
         fileMetaMapper.updateScopeByObjectName(scope, objectName);

+ 6 - 4
oss-store/src/main/java/cn/reghao/oss/store/rpc/ObjectServiceImpl.java

@@ -37,13 +37,15 @@ public class ObjectServiceImpl implements ObjectService {
     }
 
     @Override
-    public void setObjectsScope(int scope, List<String> objectNames) {
-        if (objectNames.isEmpty()) {
+    public void setObjectsScope(int scope, List<String> objectIds) {
+        if (objectIds.isEmpty()) {
             return;
         }
 
-        objectNames.forEach(objectName -> objectRepository.updateObjectScope(scope, objectName));
-        //objectRepository.updateObjectsScope(scope, objectNames);
+        objectIds.forEach(objectId -> {
+            FileMeta fileMeta = objectRepository.getByObjectId(objectId);
+            objectRepository.updateObjectScope(scope, fileMeta.getObjectName());
+        });
     }
 
     @Override