2025-03-20 00:08:23 +08:00
|
|
|
import type { DataGrid, OrderDirection, Pagination } from '@/types/global';
|
2025-03-16 00:30:43 +08:00
|
|
|
import type { TableData } from '@arco-design/web-vue';
|
2024-06-04 20:01:05 +08:00
|
|
|
import { httpBaseUrl } from '@/utils/env';
|
2024-03-05 18:07:26 +08:00
|
|
|
import axios from 'axios';
|
|
|
|
|
import qs from 'query-string';
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* SFTP 操作日志 查询请求
|
|
|
|
|
*/
|
2025-03-20 00:08:23 +08:00
|
|
|
export interface TerminalSftpLogQueryRequest extends Pagination, OrderDirection {
|
2024-03-05 18:07:26 +08:00
|
|
|
userId?: number;
|
|
|
|
|
hostId?: number;
|
|
|
|
|
type?: string;
|
|
|
|
|
result?: number;
|
|
|
|
|
startTimeRange?: string[];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* SFTP 操作日志 查询响应
|
|
|
|
|
*/
|
2024-10-17 10:20:04 +08:00
|
|
|
export interface TerminalSftpLogQueryResponse extends TableData {
|
2024-03-05 18:07:26 +08:00
|
|
|
id: number;
|
|
|
|
|
userId: number;
|
|
|
|
|
username: number;
|
|
|
|
|
hostId: number;
|
|
|
|
|
hostName: string;
|
|
|
|
|
hostAddress: string;
|
|
|
|
|
address: string;
|
|
|
|
|
location: string;
|
|
|
|
|
userAgent: string;
|
|
|
|
|
paths: string[];
|
|
|
|
|
type: string;
|
|
|
|
|
result: string;
|
|
|
|
|
startTime: number;
|
2024-10-17 10:20:04 +08:00
|
|
|
extra: TerminalSftpLogExtra;
|
2024-03-05 18:07:26 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* SFTP 操作日志 拓展对象
|
|
|
|
|
*/
|
2024-10-17 10:20:04 +08:00
|
|
|
export interface TerminalSftpLogExtra {
|
2024-03-05 18:07:26 +08:00
|
|
|
mod: number;
|
|
|
|
|
target: string;
|
2024-07-14 21:24:53 +08:00
|
|
|
maxCount: number;
|
2024-03-05 18:07:26 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 分页查询 SFTP 操作日志
|
|
|
|
|
*/
|
2024-10-17 10:20:04 +08:00
|
|
|
export function getTerminalSftpLogPage(request: TerminalSftpLogQueryRequest) {
|
2025-06-25 14:49:36 +08:00
|
|
|
return axios.post<DataGrid<TerminalSftpLogQueryResponse>>('/terminal/terminal-sftp/query-log', request);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 查询 SFTP 操作日志数量
|
|
|
|
|
*/
|
|
|
|
|
export function getTerminalSftpLogCount(request: TerminalSftpLogQueryRequest) {
|
|
|
|
|
return axios.post<number>('/terminal/terminal-sftp/log-count', request);
|
2024-03-05 18:07:26 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 删除 SFTP 操作日志
|
|
|
|
|
*/
|
2024-10-17 10:20:04 +08:00
|
|
|
export function deleteTerminalSftpLog(idList: Array<number>) {
|
2025-06-25 14:49:36 +08:00
|
|
|
return axios.delete('/terminal/terminal-sftp/delete-log', {
|
2024-03-05 18:07:26 +08:00
|
|
|
params: { idList },
|
|
|
|
|
paramsSerializer: params => {
|
|
|
|
|
return qs.stringify(params, { arrayFormat: 'comma' });
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
2024-06-04 20:01:05 +08:00
|
|
|
|
2024-10-10 23:18:53 +08:00
|
|
|
/**
|
|
|
|
|
* 获取 SFTP 文件内容
|
|
|
|
|
*/
|
|
|
|
|
export function getSftpFileContent(token: string) {
|
2025-06-25 14:49:36 +08:00
|
|
|
return axios.get<string>('/terminal/terminal-sftp/get-content', {
|
2024-10-10 23:18:53 +08:00
|
|
|
unwrap: true,
|
|
|
|
|
params: { token },
|
|
|
|
|
timeout: 60000
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 设置 SFTP 文件内容
|
|
|
|
|
*/
|
|
|
|
|
export function setSftpFileContent(token: string, content: string) {
|
|
|
|
|
const formData = new FormData();
|
|
|
|
|
formData.append('token', token);
|
|
|
|
|
formData.append('file', new File([content], Date.now() + '', { type: 'text/plain' }));
|
2025-06-25 14:49:36 +08:00
|
|
|
return axios.post<boolean>('/terminal/terminal-sftp/set-content', formData, {
|
2024-10-10 23:18:53 +08:00
|
|
|
timeout: 60000,
|
|
|
|
|
headers: {
|
|
|
|
|
'Content-Type': 'multipart/form-data'
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2024-06-04 20:01:05 +08:00
|
|
|
/**
|
|
|
|
|
* 下载文件
|
|
|
|
|
*/
|
2024-06-11 12:31:16 +08:00
|
|
|
export function getDownloadTransferUrl(channelId: string, transferToken: string) {
|
2025-06-25 14:49:36 +08:00
|
|
|
return `${httpBaseUrl}/terminal/terminal-sftp/download?channelId=${channelId}&transferToken=${transferToken}`;
|
2024-06-04 20:01:05 +08:00
|
|
|
}
|