From c3ca2f26a73dc5fc7dc6f652a159c2697abd53cf Mon Sep 17 00:00:00 2001
From: 13693261870 <252740454@qq.com>
Date: 星期一, 05 十二月 2022 22:01:44 +0800
Subject: [PATCH] 1

---
 src/main/java/com/lf/server/controller/data/MetaController.java |   59 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++--
 1 files changed, 57 insertions(+), 2 deletions(-)

diff --git a/src/main/java/com/lf/server/controller/data/MetaController.java b/src/main/java/com/lf/server/controller/data/MetaController.java
index 663138a..8d2e07f 100644
--- a/src/main/java/com/lf/server/controller/data/MetaController.java
+++ b/src/main/java/com/lf/server/controller/data/MetaController.java
@@ -21,6 +21,9 @@
 
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
+import java.io.File;
+import java.net.URLDecoder;
+import java.nio.charset.StandardCharsets;
 import java.util.List;
 
 /**
@@ -39,6 +42,8 @@
 
     @Autowired
     DownloadService downloadService;
+
+    private final static String EQ = "=";
 
     @SysLog()
     @ApiOperation(value = "鍒嗛〉鏌ヨ骞惰繑鍥炶褰曟暟")
@@ -274,15 +279,62 @@
             if (null == reqEntity.getIds() || reqEntity.getIds().isEmpty()) {
                 return fail("璇烽�夋嫨瑕佷笅杞界殑鏂囦欢");
             }
-            if (!downloadService.validatePwd(reqEntity)) {
+            if (!downloadService.decryptPwd(reqEntity)) {
+                return fail("瀵嗙爜瑙e瘑澶辫触", null);
+            }
+            if (!StringHelper.checkPwdValid(reqEntity.getPwd())) {
                 return fail("瀵嗙爜涓嶇鍚堣姹�");
             }
 
             List<MetaFileEntity> list = metaService.selectMetaFiles(reqEntity.getIds());
+            if (null == list || list.isEmpty()) {
+                return fail("娌℃湁鎵惧埌鍏冩暟鎹�");
+            }
 
-            return success(true);
+            UserEntity ue = tokenService.getCurrentUser(req);
+            String guid = downloadService.zipFiles(ue, list, reqEntity.getPwd());
+
+            return success(guid);
         } catch (Exception ex) {
             return fail(ex.getMessage(), null);
+        }
+    }
+
+    @SysLog()
+    @ApiOperation(value = "鏌ヨ涓嬭浇鏂囦欢")
+    @ApiImplicitParams({
+            @ApiImplicitParam(name = "guid", value = "鏂囦欢GUID", dataType = "String", paramType = "query"),
+            @ApiImplicitParam(name = "pwd", value = "瀵嗙爜", dataType = "String", paramType = "query")
+    })
+    @GetMapping(value = "/selectDownloadFile")
+    public ResponseMsg<Boolean> selectDownloadFile(String guid, String pwd) {
+        try {
+            if (StringHelper.isEmpty(guid) || StringHelper.isEmpty(pwd)) {
+                return fail("鏂囦欢ID鍜屽瘑鐮佷笉鑳戒负绌�", null);
+            }
+            if (!pwd.endsWith(EQ)) {
+                pwd = URLDecoder.decode(pwd, StandardCharsets.UTF_8.name());
+            }
+
+            String password = downloadService.decryptPwd(pwd);
+            if (null == password) {
+                return fail("瀵嗙爜瑙e瘑澶辫触", null);
+            }
+
+            DownloadEntity de = downloadService.selectByGuid(guid);
+            if (null == de) {
+                return fail("鏂囦欢涓嶅瓨鍦�", null);
+            }
+            if (!StringHelper.isNull(de.getPwd()) && !Md5Helper.validatePassword(password, de.getPwd())) {
+                return fail("瀵嗙爜涓嶆纭�", null);
+            }
+
+            String filePath = downloadService.getDownloadFilePath(de);
+            File file = new File(filePath);
+
+            return success(file.exists());
+        } catch (Exception ex) {
+            return fail(ex.getMessage(), false);
         }
     }
 
@@ -299,6 +351,9 @@
             if (StringHelper.isEmpty(guid) || StringHelper.isEmpty(pwd)) {
                 WebHelper.writeInfo(HttpStatus.BAD_REQUEST, "鏂囦欢ID鍜屽瘑鐮佷笉鑳戒负绌�", res);
             }
+            if (!pwd.endsWith(EQ)) {
+                pwd = URLDecoder.decode(pwd, StandardCharsets.UTF_8.name());
+            }
 
             String password = downloadService.decryptPwd(pwd);
             if (null == password) {

--
Gitblit v1.9.3