⚡ 优化文件下载.
This commit is contained in:
@@ -21,6 +21,8 @@ server {
|
||||
proxy_set_header X-Real-IP $remote_addr;
|
||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||
proxy_set_header X-Forwarded-Proto $scheme;
|
||||
# web history 模式 404
|
||||
try_files $uri $uri/ /index.html;
|
||||
}
|
||||
|
||||
location /orion/api {
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.orion.ops.module.asset.handler.host.terminal.handler;
|
||||
|
||||
import com.orion.ops.framework.common.constant.Const;
|
||||
import com.orion.ops.framework.common.enums.BooleanBit;
|
||||
import com.orion.ops.module.asset.handler.host.terminal.enums.OutputTypeEnum;
|
||||
import com.orion.ops.module.asset.handler.host.terminal.model.request.SftpBaseRequest;
|
||||
@@ -27,7 +28,7 @@ public class SftpGetContentHandler extends AbstractTerminalHandler<SftpBaseReque
|
||||
ISftpSession session = terminalManager.getSession(channel.getId(), sessionId);
|
||||
String path = payload.getPath();
|
||||
log.info("SftpGetContentHandler-handle start sessionId: {}, path: {}", sessionId, path);
|
||||
String content = null;
|
||||
String content = Const.EMPTY;
|
||||
Exception ex = null;
|
||||
// 获取内容
|
||||
try {
|
||||
|
||||
@@ -116,10 +116,22 @@ public class SftpSession extends TerminalSession implements ISftpSession {
|
||||
@Override
|
||||
public String getContent(String path) {
|
||||
path = Valid.checkNormalize(path);
|
||||
try (InputStream in = executor.openInputStream(path)) {
|
||||
try {
|
||||
// 获取文件
|
||||
SftpFile file = executor.getFile(path);
|
||||
if (file == null || file.getSize() == 0L) {
|
||||
return Const.EMPTY;
|
||||
}
|
||||
// 读取文件
|
||||
InputStream in = executor.openInputStream(path);
|
||||
return Streams.toString(in, config.getFileContentCharset());
|
||||
} catch (Exception e) {
|
||||
throw Exceptions.ioRuntime(e);
|
||||
} finally {
|
||||
// 同关闭 transfer downloader
|
||||
// 关闭 inputStream 可能会被阻塞 ??..?? 只能关闭 executor
|
||||
Streams.close(this.executor);
|
||||
this.connect();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -107,7 +107,7 @@ public class TransferHandler implements ITransferHandler {
|
||||
ITransferHostSession session = sessions.get(sessionKey);
|
||||
if (session == null) {
|
||||
// 获取主机信息
|
||||
HostTerminalConnectDTO connectInfo = hostTerminalService.getTerminalConnectInfo(hostId, this.userId, HostConnectTypeEnum.SFTP);
|
||||
HostTerminalConnectDTO connectInfo = hostTerminalService.getTerminalConnectInfo(this.userId, hostId, HostConnectTypeEnum.SFTP);
|
||||
SessionStore sessionStore = hostTerminalService.openSessionStore(connectInfo);
|
||||
// 打开会话并初始化
|
||||
if (TransferOperatorType.UPLOAD.equals(type.getOperator())) {
|
||||
|
||||
@@ -46,6 +46,12 @@ public class DownloadSession extends TransferHostSession implements IDownloadSes
|
||||
// 检查文件是否存在
|
||||
SftpFile file = executor.getFile(path);
|
||||
Valid.notNull(file, ErrorMessage.FILE_ABSENT);
|
||||
if (file.getSize() == 0L) {
|
||||
// 文件为空
|
||||
log.info("DownloadSession.startDownload file empty channelId: {}, path: {}", channelId, path);
|
||||
TransferUtils.sendMessage(this.channel, TransferReceiverType.DOWNLOAD_FINISH, null);
|
||||
return;
|
||||
}
|
||||
// 打开输入流
|
||||
this.inputStream = executor.openInputStream(path);
|
||||
log.info("DownloadSession.startDownload open success channelId: {}, path: {}", channelId, path);
|
||||
@@ -92,7 +98,7 @@ public class DownloadSession extends TransferHostSession implements IDownloadSes
|
||||
|
||||
@Override
|
||||
protected void closeStream() {
|
||||
// 关闭 inputStream 会被阻塞 ??..?? 只能关闭 executor
|
||||
// 关闭 inputStream 可能会被阻塞 ??..?? 只能关闭 executor
|
||||
Streams.close(this.executor);
|
||||
this.executor = null;
|
||||
this.inputStream = null;
|
||||
|
||||
@@ -260,7 +260,7 @@
|
||||
setLoading(false);
|
||||
Message.success('修改成功');
|
||||
// 回调 props
|
||||
emits('submitted', { ...formModel.value });
|
||||
emits('submitted', { ...props.content, config: { ...formModel.value } });
|
||||
} catch (e) {
|
||||
} finally {
|
||||
setLoading(false);
|
||||
|
||||
@@ -30,8 +30,8 @@ const columns = [
|
||||
}, {
|
||||
title: '操作',
|
||||
slotName: 'handle',
|
||||
width: 180,
|
||||
align: 'right',
|
||||
width: 162,
|
||||
align: 'center',
|
||||
fixed: 'right',
|
||||
},
|
||||
] as TableColumnData[];
|
||||
|
||||
@@ -186,8 +186,8 @@
|
||||
|
||||
:deep(.arco-tabs-tab) {
|
||||
height: 100%;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
margin: 0 !important;
|
||||
padding: 0 !important;
|
||||
color: var(--color-panel-text-1);
|
||||
background: var(--color-bg-panel-tabs);
|
||||
position: relative;
|
||||
|
||||
@@ -68,7 +68,7 @@
|
||||
</span>
|
||||
</a-tooltip>
|
||||
<!-- 编辑内容 -->
|
||||
<a-tooltip v-if="canEditable(record.size, record.isDir)"
|
||||
<a-tooltip v-if="canEditable(record.size, record.attr)"
|
||||
position="top"
|
||||
:mini="true"
|
||||
:overlay-inverse="true"
|
||||
@@ -204,14 +204,15 @@
|
||||
};
|
||||
|
||||
// 是否可编辑
|
||||
const canEditable = (size: number, isDir: boolean) => {
|
||||
// 非文件夹并且文件小于 配置大小(MB) 可以编辑
|
||||
return !isDir && size <= previewSize * 1024 * 1024;
|
||||
const canEditable = (size: number, attr: string) => {
|
||||
// 是普通文件 && 文件小于 配置大小(MB) 可以编辑
|
||||
return FILE_TYPE.NORMAL_FILE.value == formatFileType(attr).value
|
||||
&& size <= previewSize * 1024 * 1024;
|
||||
};
|
||||
|
||||
// 点击文件名称
|
||||
const clickFilename = (record: TableData) => {
|
||||
if (FILE_TYPE.DIRECTORY.value === formatFileType(record.attr).value) {
|
||||
if (record.isDir) {
|
||||
// 进入文件夹
|
||||
emits('loadFile', record.path);
|
||||
} else {
|
||||
|
||||
@@ -121,6 +121,7 @@
|
||||
// 编辑文件
|
||||
const editFile = (name: string, path: string) => {
|
||||
setEditorLoading(true);
|
||||
setTableLoading(true);
|
||||
splitSize.value = 0.6;
|
||||
editorView.value = true;
|
||||
editorFileName.value = name;
|
||||
@@ -208,6 +209,7 @@
|
||||
|
||||
// 接收获取文件内容响应
|
||||
const resolveSftpGetContent = (path: string, result: string, content: string) => {
|
||||
setTableLoading(false);
|
||||
setEditorLoading(false);
|
||||
// 检查结果
|
||||
if (!checkResult(result, '加载失败')) {
|
||||
|
||||
Reference in New Issue
Block a user