优化代码结构

This commit is contained in:
zhaojun
2022-08-26 18:17:58 +08:00
parent e8117c7d3b
commit 477c9dbdd2
11 changed files with 29 additions and 20 deletions

View File

@@ -28,7 +28,6 @@ public class GetS3BucketListRequest {
private String endPoint;
@ApiModelProperty(value = "Endpoint 接入点", required = true, example = "cn-beijing")
// @NotBlank(message = "地域不能为空")
private String region;
}

View File

@@ -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() {

View File

@@ -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;
}

View File

@@ -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();

View File

@@ -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<FileItemResult> fileItemList = fileContext.getFileItemList();
if (fileItemList == null) {
if (CollUtil.isEmpty(fileItemList)) {
return false;
}

View File

@@ -35,6 +35,10 @@ public class FileSortCommand implements Command {
List<FileItemResult> fileItemList = fileContext.getFileItemList();
FileListRequest fileListRequest = fileContext.getFileListRequest();
if (fileListRequest.getOrderBy() == null || fileListRequest.getOrderDirection() == null) {
return false;
}
// 创建副本, 防止排序和过滤对原数据产生影响
List<FileItemResult> copyList = new ArrayList<>(fileItemList);

View File

@@ -15,7 +15,7 @@ public abstract class ProxyDownloadService<P extends ProxyDownloadParam> extends
* 空实现.
*/
@Override
public void uploadFile(String path, InputStream inputStream) {
public void uploadFile(String pathAndName, InputStream inputStream) {
}
}

View File

@@ -89,14 +89,14 @@ public abstract class ProxyTransferService<P extends ProxyTransferParam> extends
/**
* 上传文件
*
* @param path
* 文件下载路径
* @param pathAndName
* 文件上传路径
*
* @param inputStream
* 文件流
*
*/
public abstract void uploadFile(String path, InputStream inputStream);
public abstract void uploadFile(String pathAndName, InputStream inputStream);
/**

View File

@@ -181,9 +181,9 @@ public class FtpServiceImpl extends ProxyTransferService<FtpParam> {
@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);
}

View File

@@ -156,9 +156,9 @@ public class SftpServiceImpl extends ProxyTransferService<SftpParam> {
@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);
}

View File

@@ -159,12 +159,12 @@ public class WebdavServiceImpl extends ProxyTransferService<WebdavParam> {
}
@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);
}
}