From 71b9f6ee58dec62f8f90704cab365f55e36ae99c Mon Sep 17 00:00:00 2001 From: 13693261870 <252740454@qq.com> Date: 星期二, 29 十一月 2022 10:53:17 +0800 Subject: [PATCH] 1 --- src/main/java/com/lf/server/controller/data/MetaController.java | 91 +++++++++++++++++++++++++++++++++++++-------- 1 files changed, 74 insertions(+), 17 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 494e1e4..ac009c7 100644 --- a/src/main/java/com/lf/server/controller/data/MetaController.java +++ b/src/main/java/com/lf/server/controller/data/MetaController.java @@ -10,7 +10,6 @@ import com.lf.server.entity.data.MetaFileEntity; import com.lf.server.entity.sys.UserEntity; import com.lf.server.helper.Md5Helper; -import com.lf.server.helper.RsaHelper; import com.lf.server.helper.StringHelper; import com.lf.server.helper.WebHelper; import com.lf.server.service.data.DownloadService; @@ -22,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; /** @@ -151,7 +153,8 @@ @GetMapping(value = "/delete") public ResponseMsg<Integer> delete(int id) { try { - int count = metaService.delete(id); + // int count = metaService.delete(id) + int count = metaService.deleteCascade(String.valueOf(id)); return success(count); } catch (Exception ex) { @@ -171,7 +174,9 @@ return fail("id鏁扮粍涓嶈兘涓虹┖", -1); } - int count = metaService.deletes(ids); + // int count = metaService.deletes(ids) + String idStr = StringHelper.join(ids, ","); + int count = metaService.deleteCascade(idStr); return success(count); } catch (Exception ex) { @@ -272,41 +277,93 @@ 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 = "涓嬭浇鏂囦欢") + @ApiOperation(value = "鏌ヨ涓嬭浇鏂囦欢") @ApiImplicitParams({ - @ApiImplicitParam(name = "guid", value = "鏂囦欢GUID", dataType = "String", paramType = "query") + @ApiImplicitParam(name = "guid", value = "鏂囦欢GUID", dataType = "String", paramType = "query"), + @ApiImplicitParam(name = "pwd", value = "瀵嗙爜", dataType = "String", paramType = "query") }) - @ResponseBody - @RequestMapping(value = "/downloadFile", method = RequestMethod.GET) - public void downloadFile(@RequestBody DownloadReqEntity reqEntity, HttpServletRequest req, HttpServletResponse res) { + @GetMapping(value = "/selectDownloadFile") + public ResponseMsg<Boolean> selectDownloadFile(String guid, String pwd) { try { - if (null == reqEntity || StringHelper.isEmpty(reqEntity.getPwd())) { - WebHelper.writeInfo(HttpStatus.BAD_REQUEST, "瀵嗙爜涓嶈兘涓虹┖", res); + if (StringHelper.isEmpty(guid) || StringHelper.isEmpty(pwd)) { + return fail("鏂囦欢ID鍜屽瘑鐮佷笉鑳戒负绌�", null); } - if (StringHelper.isEmpty(reqEntity.getGuid())) { - WebHelper.writeInfo(HttpStatus.BAD_REQUEST, "鎵句笉鍒版枃浠禝D", res); - return; + if (!pwd.endsWith("=")) { + pwd = URLDecoder.decode(pwd, StandardCharsets.UTF_8.name()); } - DownloadEntity de = downloadService.selectByGuid(reqEntity.getGuid()); + 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); + } + } + + @SysLog() + @ApiOperation(value = "涓嬭浇鏂囦欢") + @ApiImplicitParams({ + @ApiImplicitParam(name = "guid", value = "鏂囦欢GUID", dataType = "String", paramType = "query"), + @ApiImplicitParam(name = "pwd", value = "瀵嗙爜", dataType = "String", paramType = "query") + }) + @ResponseBody + @GetMapping(value = "/downloadFile") + public void downloadFile(String guid, String pwd, HttpServletRequest req, HttpServletResponse res) { + try { + if (StringHelper.isEmpty(guid) || StringHelper.isEmpty(pwd)) { + WebHelper.writeInfo(HttpStatus.BAD_REQUEST, "鏂囦欢ID鍜屽瘑鐮佷笉鑳戒负绌�", res); + } + if (!pwd.endsWith("=")) { + pwd = URLDecoder.decode(pwd, StandardCharsets.UTF_8.name()); + } + + String password = downloadService.decryptPwd(pwd); + if (null == password) { + WebHelper.writeInfo(HttpStatus.BAD_REQUEST, "瀵嗙爜瑙e瘑澶辫触", res); + } + + DownloadEntity de = downloadService.selectByGuid(guid); if (null == de) { WebHelper.writeInfo(HttpStatus.NOT_FOUND, "鏂囦欢涓嶅瓨鍦�", res); return; } - if (!StringHelper.isNull(de.getPwd()) && !Md5Helper.validatePassword(reqEntity.getPwd(), de.getPwd())) { + if (!StringHelper.isNull(de.getPwd()) && !Md5Helper.validatePassword(password, de.getPwd())) { WebHelper.writeInfo(HttpStatus.UNAUTHORIZED, "瀵嗙爜涓嶆纭�", res); } -- Gitblit v1.9.3