Browse Source

add support video upload

guozhaoshun 6 years ago
parent
commit
f3ca8a50f5

+ 15 - 9
rankin-resource-service/src/main/java/cn/rankin/resourceservice/controller/ResourceController.java

@@ -60,20 +60,26 @@ public class ResourceController {
 
     @RequestMapping(method = RequestMethod.POST)
     public APIResult<Resource> create(@RequestBody Resource resource) {
-        if (StringUtils.isEmpty(resource.getCode()) || StringUtils.isEmpty(resource.getPath())) {
-            return APIResult.error(APICode.PARAMETER_ERROR);
-        }
 
-        if (resourceService.exists(resource.getCode())) {
-            return APIResult.error(APICode.ALREADY_EXISTS);
-        }
 
-        Resource result = resourceService.save(resource);
+        if(resource.getType().intValue() == ResourceType.VIDEO){
+            //视频类型   存远程资源库
+            return  resourceService.saveRemoteResource(resource);
+        }else {
+            if (StringUtils.isEmpty(resource.getCode()) || StringUtils.isEmpty(resource.getPath())) {
+                return APIResult.error(APICode.PARAMETER_ERROR);
+            }
 
-        return APIResult.ok(result);
-    }
+            if (resourceService.exists(resource.getCode())) {
+                return APIResult.error(APICode.ALREADY_EXISTS);
+            }
 
+            //图片类型  存本地
+            Resource result = resourceService.save(resource);
+            return APIResult.ok(result);
+        }
 
+    }
 
     @RequestMapping(value = "/batch", method = RequestMethod.GET)
     public APIResult<Map<String, Resource>> getBatch(@RequestParam("id") List<String> ids) {

+ 3 - 0
rankin-resource-service/src/main/java/cn/rankin/resourceservice/proxy/RemoteResourceProxy.java

@@ -28,4 +28,7 @@ public interface RemoteResourceProxy {
     @RequestMapping(value = "rcenter/v1/resources/files", method = RequestMethod.GET)
     APIResult<List<ResourceDetail>> getBatch(@RequestParam("ids") List<String> ids);
 
+    @RequestMapping(value = "/rcenter/v1/resources/mgt", method = RequestMethod.POST)
+    APIResult<ResourceDetail> saveResources(@RequestParam Map<String, Object> map);
+
 }

+ 38 - 0
rankin-resource-service/src/main/java/cn/rankin/resourceservice/service/ResourceService.java

@@ -234,5 +234,43 @@ public class ResourceService {
         targetResouce.setPath(resource.getPath());
         resourceRepository.save(targetResouce);
     }
+
+    /**
+     * upload  ViDEO
+     * @param resource
+     * @return
+     */
+    public APIResult<Resource> saveRemoteResource(Resource resource) {
+
+        List<Map<String, Object>> videos = new ArrayList<>();
+        Map<String, Object> video = new HashMap<>();
+        video.put("bucket","");
+        video.put("path",resource.getPath());
+        video.put("format",resource.getFormat());
+        video.put("quality",resource.getQuality());
+        video.put("size",resource.getSize());
+
+        videos.add(video);
+
+        APIResult<ResourceDetail> apiResult = resourceProxy.saveResources(new HashMap<String, Object>(){
+            {
+                this.put("no", resource.getCode());
+                this.put("title", resource.getName());
+                this.put("type", resource.getType());
+                this.put("videos", videos);
+            }
+        });
+
+        if (!apiResult.getSuccess()) {
+            log.error("Remote Server Error: code={}, message={}", apiResult.getCode(), apiResult.getMessage());
+            APIResult errResult = APIResult.error(APICode.REMOTE_SERVER_ERROR);
+            apiResult.setMessage(apiResult.getMessage());
+            return errResult;
+        }
+
+        Resource result = apiResult.getData().toNativeResource();
+        return APIResult.ok(result);
+    }
+
 }