Bladeren bron

添加获取文件列表的接口

tianboguang 2 jaren geleden
bovenliggende
commit
a101f8c4cb

+ 27 - 1
4dkankan-utils-fyun-https/src/main/java/com/fdkankan/fyun/http/HttpFileService.java

@@ -2,6 +2,8 @@ package com.fdkankan.fyun.http;
 
 import cn.hutool.core.io.FileUtil;
 import com.alibaba.fastjson.JSONObject;
+import com.fdkankan.common.constant.ErrorCode;
+import com.fdkankan.common.exception.BusinessException;
 import com.fdkankan.common.util.FileUtils;
 import com.fdkankan.fyun.face.AbstractFYunFileService;
 import com.fdkankan.fyun.http.config.HttpFyunConfig;
@@ -294,7 +296,31 @@ public class HttpFileService extends AbstractFYunFileService {
 
     @Override
     public List<String> listRemoteFiles(String bucket, String sourcePath) {
-        throw new UnsupportedOperationException("不支持列举文件列表!");
+        try {
+
+            log.info("list files under path,bucket:{},sourcePath:{}", bucket, sourcePath);
+
+            Map<String, Object> params = new HashMap<>();
+            params.put("appName", fYunFileConfig.getKey());
+            params.put("secret", fYunFileConfig.getSecret());
+
+            params.put("targetDir", sourcePath);
+            String url = fYunFileConfig.getEndPoint() + httpFyunConfig.getListDir();
+
+            log.info("url:{},params:{}", url, JSONObject.toJSONString(params));
+
+            ResponseEntity<Result> responseEntity = restTemplate.postForEntity(url, params, Result.class);
+            log.info("Fyun Http Utils list dir,url:{},params:{},结果,{}", url, JSONObject.toJSONString(params), JSONObject.toJSONString(responseEntity.getBody()));
+            if (responseEntity.getStatusCode() != HttpStatus.OK || responseEntity.getBody().getCode() != Result.CODE_SUCCESS) {
+                log.error("Fyun Http Utils list dir failed!");
+                throw new BusinessException(ErrorCode.FAILURE_CODE_3002);
+            }
+            log.info("文件列举成功,path:{}", sourcePath);
+            return JSONObject.parseArray(JSONObject.toJSONString(responseEntity.getBody()),String.class);
+        } catch (Exception e) {
+            log.error("列举文件目录失败,key=" + sourcePath, e);
+            throw new BusinessException(ErrorCode.FAILURE_CODE_3002);
+        }
     }
 
     @Override

+ 7 - 0
4dkankan-utils-fyun-https/src/main/java/com/fdkankan/fyun/http/config/HttpFyunConfig.java

@@ -41,6 +41,9 @@ public class HttpFyunConfig {
     @Value("${fyun.https.dir.copy}")
     private String copyDir;
 
+    @Value("${fyun.https.dir.list:#{null}}")
+    private String listDir;
+
 
     @Value("${fyun.https.local_temp_path:/fyun/temp/}")
     private void setLocalTempPath(String localTempPath) {
@@ -95,4 +98,8 @@ public class HttpFyunConfig {
     public String getCopyDir() {
         return copyDir;
     }
+
+    public String getListDir() {
+        return listDir;
+    }
 }