⚡ 修改文件预览逻辑.
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);
|
||||
|
||||
@@ -68,7 +68,7 @@
|
||||
</a-button>
|
||||
</a-tooltip>
|
||||
<!-- 编辑内容 -->
|
||||
<a-tooltip v-if="canEditable(record.size, record.attr)"
|
||||
<a-tooltip v-if="record.canPreview"
|
||||
position="top"
|
||||
:mini="true"
|
||||
:overlay-inverse="true"
|
||||
@@ -144,15 +144,13 @@
|
||||
<script lang="ts" setup>
|
||||
import type { TableData } from '@arco-design/web-vue/es/table/interface';
|
||||
import type { SftpFile, ISftpSession } from '../../types/define';
|
||||
import type { SftpSetting } from '@/api/system/setting';
|
||||
import { ref, computed, watch, inject, onMounted } from 'vue';
|
||||
import { ref, computed, watch, inject } from 'vue';
|
||||
import { useRowSelection } from '@/hooks/table';
|
||||
import { dateFormat } from '@/utils';
|
||||
import { setAutoFocus } from '@/utils/dom';
|
||||
import { copy } from '@/hooks/copy';
|
||||
import columns from './types/table.columns';
|
||||
import { FILE_TYPE, openSftpChmodModalKey, openSftpMoveModalKey } from '../../types/const';
|
||||
import { useCacheStore } from '@/store';
|
||||
|
||||
const props = defineProps<{
|
||||
session?: ISftpSession;
|
||||
@@ -169,8 +167,6 @@
|
||||
|
||||
const rowSelection = useRowSelection({ width: 40 });
|
||||
|
||||
const previewSize = ref(0);
|
||||
|
||||
// 切换页面自动清空过滤
|
||||
watch(() => props.list, () => {
|
||||
tableRef.value?.clearFilters();
|
||||
@@ -205,13 +201,6 @@
|
||||
record.hover = false;
|
||||
};
|
||||
|
||||
// 是否可编辑
|
||||
const canEditable = (size: number, attr: string) => {
|
||||
// 是普通文件 && 文件小于 配置大小(MB) 可以编辑
|
||||
return FILE_TYPE.NORMAL_FILE.value == formatFileType(attr).value
|
||||
&& size <= (previewSize.value || 0) * 1024 * 1024;
|
||||
};
|
||||
|
||||
// 点击文件名称
|
||||
const clickFilename = (record: TableData) => {
|
||||
if (record.isDir) {
|
||||
@@ -279,12 +268,6 @@
|
||||
}) || FILE_TYPE.NORMAL_FILE;
|
||||
};
|
||||
|
||||
// 加载配置
|
||||
onMounted(async () => {
|
||||
const { sftp } = await useCacheStore().loadSystemSetting();
|
||||
previewSize.value = sftp?.previewSize;
|
||||
});
|
||||
|
||||
</script>
|
||||
|
||||
<style lang="less" scoped>
|
||||
|
||||
@@ -369,6 +369,7 @@ export interface SftpFile {
|
||||
uid: number;
|
||||
gid: number;
|
||||
modifyTime: number;
|
||||
canPreview: boolean;
|
||||
}
|
||||
|
||||
// sftp 传输管理器定义
|
||||
|
||||
Reference in New Issue
Block a user