⚡ 修改文件预览逻辑.
This commit is contained in:
@@ -34,6 +34,7 @@ import org.dromara.visor.common.constant.ErrorMessage;
|
||||
import org.dromara.visor.common.constant.ExtraFieldConst;
|
||||
import org.dromara.visor.common.enums.BooleanBit;
|
||||
import org.dromara.visor.framework.websocket.core.utils.WebSockets;
|
||||
import org.dromara.visor.module.asset.define.config.AppSftpConfig;
|
||||
import org.dromara.visor.module.asset.entity.dto.TerminalConnectDTO;
|
||||
import org.dromara.visor.module.asset.enums.TerminalConnectStatusEnum;
|
||||
import org.dromara.visor.module.asset.enums.TerminalConnectTypeEnum;
|
||||
@@ -64,6 +65,9 @@ import java.util.Map;
|
||||
@Component
|
||||
public class TerminalConnectHandler extends AbstractTerminalHandler<TerminalConnectRequest> {
|
||||
|
||||
@Resource
|
||||
private AppSftpConfig appSftpConfig;
|
||||
|
||||
@Resource
|
||||
private TerminalConnectLogService terminalConnectLogService;
|
||||
|
||||
@@ -136,6 +140,7 @@ public class TerminalConnectHandler extends AbstractTerminalHandler<TerminalConn
|
||||
.charset(connect.getCharset())
|
||||
.fileNameCharset(connect.getFileNameCharset())
|
||||
.fileContentCharset(connect.getFileContentCharset())
|
||||
.filePreviewSize(appSftpConfig.getPreviewSize())
|
||||
.build();
|
||||
// 建立连接
|
||||
SessionStore sessionStore = SessionStores.openSessionStore(connect);
|
||||
|
||||
@@ -85,4 +85,9 @@ public class TerminalConfig {
|
||||
*/
|
||||
private String fileContentCharset;
|
||||
|
||||
/**
|
||||
* 文件预览大小
|
||||
*/
|
||||
private Integer filePreviewSize;
|
||||
|
||||
}
|
||||
|
||||
@@ -92,4 +92,9 @@ public class SftpFileVO {
|
||||
*/
|
||||
private Date modifyTime;
|
||||
|
||||
/**
|
||||
* 是否可预览
|
||||
*/
|
||||
private Boolean canPreview;
|
||||
|
||||
}
|
||||
|
||||
@@ -23,6 +23,7 @@
|
||||
package org.dromara.visor.module.asset.handler.host.terminal.session;
|
||||
|
||||
import cn.orionsec.kit.lang.utils.Exceptions;
|
||||
import cn.orionsec.kit.lang.utils.Objects1;
|
||||
import cn.orionsec.kit.lang.utils.Strings;
|
||||
import cn.orionsec.kit.lang.utils.io.FileType;
|
||||
import cn.orionsec.kit.lang.utils.io.Files1;
|
||||
@@ -85,7 +86,7 @@ public class SftpSession extends TerminalSession implements ISftpSession {
|
||||
false,
|
||||
true);
|
||||
return files.stream()
|
||||
.map(SftpSession::fileMapping)
|
||||
.map(this::fileMapping)
|
||||
.sorted(Comparator.comparing(SftpFileVO::getName))
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
@@ -133,7 +134,7 @@ public class SftpSession extends TerminalSession implements ISftpSession {
|
||||
return Arrays.stream(paths)
|
||||
.map(s -> executor.listFiles(s, true, false))
|
||||
.flatMap(Collection::stream)
|
||||
.map(SftpSession::fileMapping)
|
||||
.map(this::fileMapping)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@@ -197,7 +198,7 @@ public class SftpSession extends TerminalSession implements ISftpSession {
|
||||
* @param sftpFile sftpFile
|
||||
* @return file
|
||||
*/
|
||||
private static SftpFileVO fileMapping(SftpFile sftpFile) {
|
||||
private SftpFileVO fileMapping(SftpFile sftpFile) {
|
||||
SftpFileVO file = new SftpFileVO();
|
||||
file.setName(sftpFile.getName());
|
||||
file.setPath(sftpFile.getPath());
|
||||
@@ -212,7 +213,19 @@ public class SftpSession extends TerminalSession implements ISftpSession {
|
||||
.map(FileType.DIRECTORY::equals)
|
||||
.orElse(false);
|
||||
file.setIsDir(isDir);
|
||||
file.setCanPreview(this.calcCanPreview(sftpFile));
|
||||
return file;
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查是否可预览
|
||||
*
|
||||
* @param file file
|
||||
* @return canPreview
|
||||
*/
|
||||
private boolean calcCanPreview(SftpFile file) {
|
||||
// 检查文件类型及大小
|
||||
return file.isRegularFile() && file.getSize() <= Objects1.def(config.getFilePreviewSize(), Const.N_2) * 1024 * 1024;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -34,7 +34,6 @@ import lombok.extern.slf4j.Slf4j;
|
||||
import org.dromara.visor.framework.biz.operator.log.core.model.OperatorLogModel;
|
||||
import org.dromara.visor.framework.biz.operator.log.core.service.OperatorLogFrameworkService;
|
||||
import org.dromara.visor.framework.biz.operator.log.core.utils.OperatorLogs;
|
||||
import org.dromara.visor.module.asset.define.config.AppSftpConfig;
|
||||
import org.dromara.visor.module.asset.entity.dto.TerminalConnectDTO;
|
||||
import org.dromara.visor.module.asset.handler.host.terminal.utils.TerminalUtils;
|
||||
import org.dromara.visor.module.asset.handler.host.transfer.enums.TransferReceiver;
|
||||
@@ -54,8 +53,6 @@ import java.util.Map;
|
||||
@Slf4j
|
||||
public abstract class TransferSession implements ITransferSession {
|
||||
|
||||
protected static final AppSftpConfig sftpConfig = SpringHolder.getBean(AppSftpConfig.class);
|
||||
|
||||
protected final TerminalConnectDTO connectInfo;
|
||||
|
||||
protected final SessionStore sessionStore;
|
||||
|
||||
@@ -62,7 +62,7 @@ public class UploadSession extends TransferSession {
|
||||
// 检查连接
|
||||
this.init();
|
||||
// 检查文件是否存在
|
||||
SftpUtils.checkUploadFilePresent(sftpConfig, executor, path);
|
||||
SftpUtils.checkUploadFilePresent(executor, path);
|
||||
// 打开输出流
|
||||
this.outputStream = executor.openOutputStream(path);
|
||||
// 响应结果
|
||||
|
||||
@@ -38,7 +38,6 @@ import org.dromara.visor.common.enums.EndpointDefine;
|
||||
import org.dromara.visor.common.interfaces.FileClient;
|
||||
import org.dromara.visor.common.utils.PathUtils;
|
||||
import org.dromara.visor.module.asset.dao.UploadTaskFileDAO;
|
||||
import org.dromara.visor.module.asset.define.config.AppSftpConfig;
|
||||
import org.dromara.visor.module.asset.entity.domain.UploadTaskFileDO;
|
||||
import org.dromara.visor.module.asset.entity.dto.TerminalConnectDTO;
|
||||
import org.dromara.visor.module.asset.enums.HostOsTypeEnum;
|
||||
@@ -70,8 +69,6 @@ public class FileUploader implements IFileUploader {
|
||||
|
||||
private static final UploadTaskFileDAO uploadTaskFileDAO = SpringHolder.getBean(UploadTaskFileDAO.class);
|
||||
|
||||
private static final AppSftpConfig sftpConfig = SpringHolder.getBean(AppSftpConfig.class);
|
||||
|
||||
private static final FileClient localFileClient = SpringHolder.getBean("localFileClient");
|
||||
|
||||
private TerminalConnectDTO connectInfo;
|
||||
@@ -189,7 +186,7 @@ public class FileUploader implements IFileUploader {
|
||||
String endpoint = EndpointDefine.UPLOAD_SWAP.format(taskId);
|
||||
String localPath = localFileClient.getReturnPath(endpoint + Const.SLASH + file.getFileId());
|
||||
// 检查文件是否存在
|
||||
SftpUtils.checkUploadFilePresent(sftpConfig, executor, path);
|
||||
SftpUtils.checkUploadFilePresent(executor, path);
|
||||
// 打开输出流
|
||||
this.inputStream = localFileClient.getContentInputStream(localPath);
|
||||
this.outputStream = executor.openOutputStream(path);
|
||||
|
||||
Reference in New Issue
Block a user