⚡ 修改文件预览逻辑.
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.constant.ExtraFieldConst;
|
||||||
import org.dromara.visor.common.enums.BooleanBit;
|
import org.dromara.visor.common.enums.BooleanBit;
|
||||||
import org.dromara.visor.framework.websocket.core.utils.WebSockets;
|
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.entity.dto.TerminalConnectDTO;
|
||||||
import org.dromara.visor.module.asset.enums.TerminalConnectStatusEnum;
|
import org.dromara.visor.module.asset.enums.TerminalConnectStatusEnum;
|
||||||
import org.dromara.visor.module.asset.enums.TerminalConnectTypeEnum;
|
import org.dromara.visor.module.asset.enums.TerminalConnectTypeEnum;
|
||||||
@@ -64,6 +65,9 @@ import java.util.Map;
|
|||||||
@Component
|
@Component
|
||||||
public class TerminalConnectHandler extends AbstractTerminalHandler<TerminalConnectRequest> {
|
public class TerminalConnectHandler extends AbstractTerminalHandler<TerminalConnectRequest> {
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private AppSftpConfig appSftpConfig;
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
private TerminalConnectLogService terminalConnectLogService;
|
private TerminalConnectLogService terminalConnectLogService;
|
||||||
|
|
||||||
@@ -136,6 +140,7 @@ public class TerminalConnectHandler extends AbstractTerminalHandler<TerminalConn
|
|||||||
.charset(connect.getCharset())
|
.charset(connect.getCharset())
|
||||||
.fileNameCharset(connect.getFileNameCharset())
|
.fileNameCharset(connect.getFileNameCharset())
|
||||||
.fileContentCharset(connect.getFileContentCharset())
|
.fileContentCharset(connect.getFileContentCharset())
|
||||||
|
.filePreviewSize(appSftpConfig.getPreviewSize())
|
||||||
.build();
|
.build();
|
||||||
// 建立连接
|
// 建立连接
|
||||||
SessionStore sessionStore = SessionStores.openSessionStore(connect);
|
SessionStore sessionStore = SessionStores.openSessionStore(connect);
|
||||||
|
|||||||
@@ -85,4 +85,9 @@ public class TerminalConfig {
|
|||||||
*/
|
*/
|
||||||
private String fileContentCharset;
|
private String fileContentCharset;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 文件预览大小
|
||||||
|
*/
|
||||||
|
private Integer filePreviewSize;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -92,4 +92,9 @@ public class SftpFileVO {
|
|||||||
*/
|
*/
|
||||||
private Date modifyTime;
|
private Date modifyTime;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 是否可预览
|
||||||
|
*/
|
||||||
|
private Boolean canPreview;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,6 +23,7 @@
|
|||||||
package org.dromara.visor.module.asset.handler.host.terminal.session;
|
package org.dromara.visor.module.asset.handler.host.terminal.session;
|
||||||
|
|
||||||
import cn.orionsec.kit.lang.utils.Exceptions;
|
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.Strings;
|
||||||
import cn.orionsec.kit.lang.utils.io.FileType;
|
import cn.orionsec.kit.lang.utils.io.FileType;
|
||||||
import cn.orionsec.kit.lang.utils.io.Files1;
|
import cn.orionsec.kit.lang.utils.io.Files1;
|
||||||
@@ -85,7 +86,7 @@ public class SftpSession extends TerminalSession implements ISftpSession {
|
|||||||
false,
|
false,
|
||||||
true);
|
true);
|
||||||
return files.stream()
|
return files.stream()
|
||||||
.map(SftpSession::fileMapping)
|
.map(this::fileMapping)
|
||||||
.sorted(Comparator.comparing(SftpFileVO::getName))
|
.sorted(Comparator.comparing(SftpFileVO::getName))
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
}
|
}
|
||||||
@@ -133,7 +134,7 @@ public class SftpSession extends TerminalSession implements ISftpSession {
|
|||||||
return Arrays.stream(paths)
|
return Arrays.stream(paths)
|
||||||
.map(s -> executor.listFiles(s, true, false))
|
.map(s -> executor.listFiles(s, true, false))
|
||||||
.flatMap(Collection::stream)
|
.flatMap(Collection::stream)
|
||||||
.map(SftpSession::fileMapping)
|
.map(this::fileMapping)
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -197,7 +198,7 @@ public class SftpSession extends TerminalSession implements ISftpSession {
|
|||||||
* @param sftpFile sftpFile
|
* @param sftpFile sftpFile
|
||||||
* @return file
|
* @return file
|
||||||
*/
|
*/
|
||||||
private static SftpFileVO fileMapping(SftpFile sftpFile) {
|
private SftpFileVO fileMapping(SftpFile sftpFile) {
|
||||||
SftpFileVO file = new SftpFileVO();
|
SftpFileVO file = new SftpFileVO();
|
||||||
file.setName(sftpFile.getName());
|
file.setName(sftpFile.getName());
|
||||||
file.setPath(sftpFile.getPath());
|
file.setPath(sftpFile.getPath());
|
||||||
@@ -212,7 +213,19 @@ public class SftpSession extends TerminalSession implements ISftpSession {
|
|||||||
.map(FileType.DIRECTORY::equals)
|
.map(FileType.DIRECTORY::equals)
|
||||||
.orElse(false);
|
.orElse(false);
|
||||||
file.setIsDir(isDir);
|
file.setIsDir(isDir);
|
||||||
|
file.setCanPreview(this.calcCanPreview(sftpFile));
|
||||||
return file;
|
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.model.OperatorLogModel;
|
||||||
import org.dromara.visor.framework.biz.operator.log.core.service.OperatorLogFrameworkService;
|
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.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.entity.dto.TerminalConnectDTO;
|
||||||
import org.dromara.visor.module.asset.handler.host.terminal.utils.TerminalUtils;
|
import org.dromara.visor.module.asset.handler.host.terminal.utils.TerminalUtils;
|
||||||
import org.dromara.visor.module.asset.handler.host.transfer.enums.TransferReceiver;
|
import org.dromara.visor.module.asset.handler.host.transfer.enums.TransferReceiver;
|
||||||
@@ -54,8 +53,6 @@ import java.util.Map;
|
|||||||
@Slf4j
|
@Slf4j
|
||||||
public abstract class TransferSession implements ITransferSession {
|
public abstract class TransferSession implements ITransferSession {
|
||||||
|
|
||||||
protected static final AppSftpConfig sftpConfig = SpringHolder.getBean(AppSftpConfig.class);
|
|
||||||
|
|
||||||
protected final TerminalConnectDTO connectInfo;
|
protected final TerminalConnectDTO connectInfo;
|
||||||
|
|
||||||
protected final SessionStore sessionStore;
|
protected final SessionStore sessionStore;
|
||||||
|
|||||||
@@ -62,7 +62,7 @@ public class UploadSession extends TransferSession {
|
|||||||
// 检查连接
|
// 检查连接
|
||||||
this.init();
|
this.init();
|
||||||
// 检查文件是否存在
|
// 检查文件是否存在
|
||||||
SftpUtils.checkUploadFilePresent(sftpConfig, executor, path);
|
SftpUtils.checkUploadFilePresent(executor, path);
|
||||||
// 打开输出流
|
// 打开输出流
|
||||||
this.outputStream = executor.openOutputStream(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.interfaces.FileClient;
|
||||||
import org.dromara.visor.common.utils.PathUtils;
|
import org.dromara.visor.common.utils.PathUtils;
|
||||||
import org.dromara.visor.module.asset.dao.UploadTaskFileDAO;
|
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.domain.UploadTaskFileDO;
|
||||||
import org.dromara.visor.module.asset.entity.dto.TerminalConnectDTO;
|
import org.dromara.visor.module.asset.entity.dto.TerminalConnectDTO;
|
||||||
import org.dromara.visor.module.asset.enums.HostOsTypeEnum;
|
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 UploadTaskFileDAO uploadTaskFileDAO = SpringHolder.getBean(UploadTaskFileDAO.class);
|
||||||
|
|
||||||
private static final AppSftpConfig sftpConfig = SpringHolder.getBean(AppSftpConfig.class);
|
|
||||||
|
|
||||||
private static final FileClient localFileClient = SpringHolder.getBean("localFileClient");
|
private static final FileClient localFileClient = SpringHolder.getBean("localFileClient");
|
||||||
|
|
||||||
private TerminalConnectDTO connectInfo;
|
private TerminalConnectDTO connectInfo;
|
||||||
@@ -189,7 +186,7 @@ public class FileUploader implements IFileUploader {
|
|||||||
String endpoint = EndpointDefine.UPLOAD_SWAP.format(taskId);
|
String endpoint = EndpointDefine.UPLOAD_SWAP.format(taskId);
|
||||||
String localPath = localFileClient.getReturnPath(endpoint + Const.SLASH + file.getFileId());
|
String localPath = localFileClient.getReturnPath(endpoint + Const.SLASH + file.getFileId());
|
||||||
// 检查文件是否存在
|
// 检查文件是否存在
|
||||||
SftpUtils.checkUploadFilePresent(sftpConfig, executor, path);
|
SftpUtils.checkUploadFilePresent(executor, path);
|
||||||
// 打开输出流
|
// 打开输出流
|
||||||
this.inputStream = localFileClient.getContentInputStream(localPath);
|
this.inputStream = localFileClient.getContentInputStream(localPath);
|
||||||
this.outputStream = executor.openOutputStream(path);
|
this.outputStream = executor.openOutputStream(path);
|
||||||
|
|||||||
@@ -68,7 +68,7 @@
|
|||||||
</a-button>
|
</a-button>
|
||||||
</a-tooltip>
|
</a-tooltip>
|
||||||
<!-- 编辑内容 -->
|
<!-- 编辑内容 -->
|
||||||
<a-tooltip v-if="canEditable(record.size, record.attr)"
|
<a-tooltip v-if="record.canPreview"
|
||||||
position="top"
|
position="top"
|
||||||
:mini="true"
|
:mini="true"
|
||||||
:overlay-inverse="true"
|
:overlay-inverse="true"
|
||||||
@@ -144,15 +144,13 @@
|
|||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
import type { TableData } from '@arco-design/web-vue/es/table/interface';
|
import type { TableData } from '@arco-design/web-vue/es/table/interface';
|
||||||
import type { SftpFile, ISftpSession } from '../../types/define';
|
import type { SftpFile, ISftpSession } from '../../types/define';
|
||||||
import type { SftpSetting } from '@/api/system/setting';
|
import { ref, computed, watch, inject } from 'vue';
|
||||||
import { ref, computed, watch, inject, onMounted } from 'vue';
|
|
||||||
import { useRowSelection } from '@/hooks/table';
|
import { useRowSelection } from '@/hooks/table';
|
||||||
import { dateFormat } from '@/utils';
|
import { dateFormat } from '@/utils';
|
||||||
import { setAutoFocus } from '@/utils/dom';
|
import { setAutoFocus } from '@/utils/dom';
|
||||||
import { copy } from '@/hooks/copy';
|
import { copy } from '@/hooks/copy';
|
||||||
import columns from './types/table.columns';
|
import columns from './types/table.columns';
|
||||||
import { FILE_TYPE, openSftpChmodModalKey, openSftpMoveModalKey } from '../../types/const';
|
import { FILE_TYPE, openSftpChmodModalKey, openSftpMoveModalKey } from '../../types/const';
|
||||||
import { useCacheStore } from '@/store';
|
|
||||||
|
|
||||||
const props = defineProps<{
|
const props = defineProps<{
|
||||||
session?: ISftpSession;
|
session?: ISftpSession;
|
||||||
@@ -169,8 +167,6 @@
|
|||||||
|
|
||||||
const rowSelection = useRowSelection({ width: 40 });
|
const rowSelection = useRowSelection({ width: 40 });
|
||||||
|
|
||||||
const previewSize = ref(0);
|
|
||||||
|
|
||||||
// 切换页面自动清空过滤
|
// 切换页面自动清空过滤
|
||||||
watch(() => props.list, () => {
|
watch(() => props.list, () => {
|
||||||
tableRef.value?.clearFilters();
|
tableRef.value?.clearFilters();
|
||||||
@@ -205,13 +201,6 @@
|
|||||||
record.hover = false;
|
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) => {
|
const clickFilename = (record: TableData) => {
|
||||||
if (record.isDir) {
|
if (record.isDir) {
|
||||||
@@ -279,12 +268,6 @@
|
|||||||
}) || FILE_TYPE.NORMAL_FILE;
|
}) || FILE_TYPE.NORMAL_FILE;
|
||||||
};
|
};
|
||||||
|
|
||||||
// 加载配置
|
|
||||||
onMounted(async () => {
|
|
||||||
const { sftp } = await useCacheStore().loadSystemSetting();
|
|
||||||
previewSize.value = sftp?.previewSize;
|
|
||||||
});
|
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style lang="less" scoped>
|
<style lang="less" scoped>
|
||||||
|
|||||||
@@ -369,6 +369,7 @@ export interface SftpFile {
|
|||||||
uid: number;
|
uid: number;
|
||||||
gid: number;
|
gid: number;
|
||||||
modifyTime: number;
|
modifyTime: number;
|
||||||
|
canPreview: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
// sftp 传输管理器定义
|
// sftp 传输管理器定义
|
||||||
|
|||||||
Reference in New Issue
Block a user