From 477c9dbdd2c751491430d87d34bb1a8cb280bc06 Mon Sep 17 00:00:00 2001 From: zhaojun <873019219@qq.com> Date: Fri, 26 Aug 2022 18:17:58 +0800 Subject: [PATCH] =?UTF-8?q?:sparkles:=20=E4=BC=98=E5=8C=96=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E7=BB=93=E6=9E=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../admin/model/request/s3/GetS3BucketListRequest.java | 1 - .../zfile/common/schedule/AccessTokenRefreshSchedule.java | 2 +- .../zhaojun/zfile/common/util/ProxyDownloadUrlUtils.java | 6 ++++++ .../java/im/zhaojun/zfile/common/util/StringUtils.java | 2 +- .../zfile/home/chain/command/FileHiddenCommand.java | 6 +++--- .../zhaojun/zfile/home/chain/command/FileSortCommand.java | 4 ++++ .../zfile/home/service/base/ProxyDownloadService.java | 2 +- .../zfile/home/service/base/ProxyTransferService.java | 6 +++--- .../zhaojun/zfile/home/service/impl/FtpServiceImpl.java | 6 +++--- .../zhaojun/zfile/home/service/impl/SftpServiceImpl.java | 6 +++--- .../zfile/home/service/impl/WebdavServiceImpl.java | 8 ++++---- 11 files changed, 29 insertions(+), 20 deletions(-) diff --git a/src/main/java/im/zhaojun/zfile/admin/model/request/s3/GetS3BucketListRequest.java b/src/main/java/im/zhaojun/zfile/admin/model/request/s3/GetS3BucketListRequest.java index 752d7d1..179e3ef 100644 --- a/src/main/java/im/zhaojun/zfile/admin/model/request/s3/GetS3BucketListRequest.java +++ b/src/main/java/im/zhaojun/zfile/admin/model/request/s3/GetS3BucketListRequest.java @@ -28,7 +28,6 @@ public class GetS3BucketListRequest { private String endPoint; @ApiModelProperty(value = "Endpoint 接入点", required = true, example = "cn-beijing") - // @NotBlank(message = "地域不能为空") private String region; } \ No newline at end of file diff --git a/src/main/java/im/zhaojun/zfile/common/schedule/AccessTokenRefreshSchedule.java b/src/main/java/im/zhaojun/zfile/common/schedule/AccessTokenRefreshSchedule.java index e8cd80c..d03573a 100644 --- a/src/main/java/im/zhaojun/zfile/common/schedule/AccessTokenRefreshSchedule.java +++ b/src/main/java/im/zhaojun/zfile/common/schedule/AccessTokenRefreshSchedule.java @@ -24,7 +24,7 @@ public class AccessTokenRefreshSchedule { private StorageSourceContext storageSourceContext; /** - * 项目启动 30 秒后, 每 15 分钟执行一次刷新 OneDrive Token 的定时任务. + * 项目启动 30 秒后, 每 10 分钟执行一次刷新 OneDrive Token 的定时任务. */ @Scheduled(fixedRate = 1000 * 60 * 10, initialDelay = 1000 * 10) public void autoRefreshAccessToken() { diff --git a/src/main/java/im/zhaojun/zfile/common/util/ProxyDownloadUrlUtils.java b/src/main/java/im/zhaojun/zfile/common/util/ProxyDownloadUrlUtils.java index 295332c..568a13d 100644 --- a/src/main/java/im/zhaojun/zfile/common/util/ProxyDownloadUrlUtils.java +++ b/src/main/java/im/zhaojun/zfile/common/util/ProxyDownloadUrlUtils.java @@ -8,6 +8,7 @@ import cn.hutool.crypto.symmetric.SymmetricAlgorithm; import cn.hutool.crypto.symmetric.SymmetricCrypto; import cn.hutool.extra.spring.SpringUtil; import im.zhaojun.zfile.admin.service.SystemConfigService; +import lombok.extern.slf4j.Slf4j; import java.util.Date; import java.util.List; @@ -17,6 +18,7 @@ import java.util.List; * * @author zhaojun */ +@Slf4j public class ProxyDownloadUrlUtils { private static SystemConfigService systemConfigService; @@ -70,13 +72,17 @@ public class ProxyDownloadUrlUtils { String storageId = split.get(0); String pathAndName = split.get(1); String expiredSecond = split.get(2); + // 校验存储源 ID 和文件路径及是否过期. if (StrUtil.equals(storageId, Convert.toStr(expectedStorageId)) && StrUtil.equals(StringUtils.concat(pathAndName), StringUtils.concat(expectedPathAndName)) && new Date().getTime() < Convert.toLong(expiredSecond)) { return true; } + + log.debug("校验链接已过期或不匹配, storageId={}, pathAndName={}, expiredSecond={}, now:={}", storageId, pathAndName, expiredSecond, new Date().getTime()); } catch (Exception e) { + log.error("校验链接是否过期异常", e); return false; } diff --git a/src/main/java/im/zhaojun/zfile/common/util/StringUtils.java b/src/main/java/im/zhaojun/zfile/common/util/StringUtils.java index 6f851d9..44757cd 100644 --- a/src/main/java/im/zhaojun/zfile/common/util/StringUtils.java +++ b/src/main/java/im/zhaojun/zfile/common/util/StringUtils.java @@ -272,7 +272,7 @@ public class StringUtils { * * @return 生成结果 */ - public static String generatorLink(String storageKey, String fullPath) { + public static String generatorPathLink(String storageKey, String fullPath) { SystemConfigService systemConfigService = SpringUtil.getBean(SystemConfigService.class); SystemConfigDTO systemConfig = systemConfigService.getSystemConfig(); String domain = systemConfig.getDomain(); diff --git a/src/main/java/im/zhaojun/zfile/home/chain/command/FileHiddenCommand.java b/src/main/java/im/zhaojun/zfile/home/chain/command/FileHiddenCommand.java index 8241568..14cfe10 100644 --- a/src/main/java/im/zhaojun/zfile/home/chain/command/FileHiddenCommand.java +++ b/src/main/java/im/zhaojun/zfile/home/chain/command/FileHiddenCommand.java @@ -1,8 +1,9 @@ package im.zhaojun.zfile.home.chain.command; -import im.zhaojun.zfile.home.chain.FileContext; +import cn.hutool.core.collection.CollUtil; import im.zhaojun.zfile.admin.service.FilterConfigService; import im.zhaojun.zfile.common.util.StringUtils; +import im.zhaojun.zfile.home.chain.FileContext; import im.zhaojun.zfile.home.model.result.FileItemResult; import org.apache.commons.chain.Command; import org.apache.commons.chain.Context; @@ -38,8 +39,7 @@ public class FileHiddenCommand implements Command { FileContext fileContext = (FileContext) context; Integer storageId = fileContext.getStorageId(); List fileItemList = fileContext.getFileItemList(); - - if (fileItemList == null) { + if (CollUtil.isEmpty(fileItemList)) { return false; } diff --git a/src/main/java/im/zhaojun/zfile/home/chain/command/FileSortCommand.java b/src/main/java/im/zhaojun/zfile/home/chain/command/FileSortCommand.java index 085ee45..7fd5414 100644 --- a/src/main/java/im/zhaojun/zfile/home/chain/command/FileSortCommand.java +++ b/src/main/java/im/zhaojun/zfile/home/chain/command/FileSortCommand.java @@ -35,6 +35,10 @@ public class FileSortCommand implements Command { List fileItemList = fileContext.getFileItemList(); FileListRequest fileListRequest = fileContext.getFileListRequest(); + if (fileListRequest.getOrderBy() == null || fileListRequest.getOrderDirection() == null) { + return false; + } + // 创建副本, 防止排序和过滤对原数据产生影响 List copyList = new ArrayList<>(fileItemList); diff --git a/src/main/java/im/zhaojun/zfile/home/service/base/ProxyDownloadService.java b/src/main/java/im/zhaojun/zfile/home/service/base/ProxyDownloadService.java index 8972786..2a800e8 100644 --- a/src/main/java/im/zhaojun/zfile/home/service/base/ProxyDownloadService.java +++ b/src/main/java/im/zhaojun/zfile/home/service/base/ProxyDownloadService.java @@ -15,7 +15,7 @@ public abstract class ProxyDownloadService

extends * 空实现. */ @Override - public void uploadFile(String path, InputStream inputStream) { + public void uploadFile(String pathAndName, InputStream inputStream) { } } \ No newline at end of file diff --git a/src/main/java/im/zhaojun/zfile/home/service/base/ProxyTransferService.java b/src/main/java/im/zhaojun/zfile/home/service/base/ProxyTransferService.java index 35b6f24..01ea202 100644 --- a/src/main/java/im/zhaojun/zfile/home/service/base/ProxyTransferService.java +++ b/src/main/java/im/zhaojun/zfile/home/service/base/ProxyTransferService.java @@ -89,14 +89,14 @@ public abstract class ProxyTransferService

extends /** * 上传文件 * - * @param path - * 文件下载路径 + * @param pathAndName + * 文件上传路径 * * @param inputStream * 文件流 * */ - public abstract void uploadFile(String path, InputStream inputStream); + public abstract void uploadFile(String pathAndName, InputStream inputStream); /** diff --git a/src/main/java/im/zhaojun/zfile/home/service/impl/FtpServiceImpl.java b/src/main/java/im/zhaojun/zfile/home/service/impl/FtpServiceImpl.java index c635309..ec7d64a 100644 --- a/src/main/java/im/zhaojun/zfile/home/service/impl/FtpServiceImpl.java +++ b/src/main/java/im/zhaojun/zfile/home/service/impl/FtpServiceImpl.java @@ -181,9 +181,9 @@ public class FtpServiceImpl extends ProxyTransferService { @Override - public synchronized void uploadFile(String path, InputStream inputStream) { - String fullPath = StringUtils.concat(param.getBasePath(), path); - String fileName = FileUtil.getName(path); + public synchronized void uploadFile(String pathAndName, InputStream inputStream) { + String fullPath = StringUtils.concat(param.getBasePath(), pathAndName); + String fileName = FileUtil.getName(pathAndName); String folderName = FileUtil.getParent(fullPath, 1); ftp.upload(folderName, fileName, inputStream); } diff --git a/src/main/java/im/zhaojun/zfile/home/service/impl/SftpServiceImpl.java b/src/main/java/im/zhaojun/zfile/home/service/impl/SftpServiceImpl.java index 415a45a..52bde53 100644 --- a/src/main/java/im/zhaojun/zfile/home/service/impl/SftpServiceImpl.java +++ b/src/main/java/im/zhaojun/zfile/home/service/impl/SftpServiceImpl.java @@ -156,9 +156,9 @@ public class SftpServiceImpl extends ProxyTransferService { @Override - public synchronized void uploadFile(String path, InputStream inputStream) { - String fullPath = StringUtils.concat(param.getBasePath(), path); - String fileName = FileUtil.getName(path); + public synchronized void uploadFile(String pathAndName, InputStream inputStream) { + String fullPath = StringUtils.concat(param.getBasePath(), pathAndName); + String fileName = FileUtil.getName(pathAndName); String folderName = FileUtil.getParent(fullPath, 1); sftp.upload(folderName, fileName, inputStream); } diff --git a/src/main/java/im/zhaojun/zfile/home/service/impl/WebdavServiceImpl.java b/src/main/java/im/zhaojun/zfile/home/service/impl/WebdavServiceImpl.java index 7e94a21..134a7c0 100644 --- a/src/main/java/im/zhaojun/zfile/home/service/impl/WebdavServiceImpl.java +++ b/src/main/java/im/zhaojun/zfile/home/service/impl/WebdavServiceImpl.java @@ -159,12 +159,12 @@ public class WebdavServiceImpl extends ProxyTransferService { } @Override - public void uploadFile(String path, InputStream inputStream) { + public void uploadFile(String pathAndName, InputStream inputStream) { try { - path = getRequestPath(path); - sardine.put(path, inputStream); + pathAndName = getRequestPath(pathAndName); + sardine.put(pathAndName, inputStream); } catch (IOException e) { - throw new FileUploadException(getStorageTypeEnum(), storageId, path, e); + throw new FileUploadException(getStorageTypeEnum(), storageId, pathAndName, e); } }