v1.7.0 #318

Merged
LukeGus merged 138 commits from dev-1.7.0 into main 2025-10-01 20:40:10 +00:00
2 changed files with 85 additions and 5 deletions
Showing only changes of commit 5ec9451ef2 - Show all commits
@@ -298,11 +298,53 @@ function FileManagerContent({ initialHost, onClose }: FileManagerModernProps) {
// 确保SSH连接有效 // 确保SSH连接有效
await ensureSSHConnection(); await ensureSSHConnection();
const targetPath = currentPath.endsWith('/') // 读取文件内容
? `${currentPath}${file.name}` const fileContent = await new Promise<string>((resolve, reject) => {
: `${currentPath}/${file.name}`; const reader = new FileReader();
reader.onerror = () => reject(reader.error);
await uploadSSHFile(sshSessionId, targetPath, file); // 检查文件类型,决定读取方式
const isTextFile = file.type.startsWith('text/') ||
file.type === 'application/json' ||
file.type === 'application/javascript' ||
file.type === 'application/xml' ||
file.name.match(/\.(txt|json|js|ts|jsx|tsx|css|html|htm|xml|yaml|yml|md|py|java|c|cpp|h|sh|bat|ps1)$/i);
if (isTextFile) {
reader.onload = () => {
if (reader.result) {
resolve(reader.result as string);
} else {
reject(new Error('Failed to read text file content'));
}
};
reader.readAsText(file);
} else {
reader.onload = () => {
if (reader.result instanceof ArrayBuffer) {
const bytes = new Uint8Array(reader.result);
let binary = '';
for (let i = 0; i < bytes.byteLength; i++) {
binary += String.fromCharCode(bytes[i]);
}
const base64 = btoa(binary);
resolve(base64);
} else {
reject(new Error('Failed to read binary file'));
}
};
reader.readAsArrayBuffer(file);
}
});
await uploadSSHFile(
sshSessionId,
currentPath,
file.name,
fileContent,
currentHost?.id,
undefined // userId - will be handled by backend
);
toast.success(t("fileManager.fileUploadedSuccessfully", { name: file.name })); toast.success(t("fileManager.fileUploadedSuccessfully", { name: file.name }));
loadDirectory(currentPath); loadDirectory(currentPath);
} catch (error: any) { } catch (error: any) {
@@ -80,7 +80,45 @@ export function FileManagerOperations({
); );
try { try {
const content = await uploadFile.text(); // 读取文件内容 - 支持文本和二进制文件
const content = await new Promise<string>((resolve, reject) => {
const reader = new FileReader();
reader.onerror = () => reject(reader.error);
// 检查文件类型,决定读取方式
const isTextFile = uploadFile.type.startsWith('text/') ||
uploadFile.type === 'application/json' ||
uploadFile.type === 'application/javascript' ||
uploadFile.type === 'application/xml' ||
uploadFile.name.match(/\.(txt|json|js|ts|jsx|tsx|css|html|htm|xml|yaml|yml|md|py|java|c|cpp|h|sh|bat|ps1)$/i);
if (isTextFile) {
reader.onload = () => {
if (reader.result) {
resolve(reader.result as string);
} else {
reject(new Error('Failed to read text file content'));
}
};
reader.readAsText(uploadFile);
} else {
reader.onload = () => {
if (reader.result instanceof ArrayBuffer) {
const bytes = new Uint8Array(reader.result);
let binary = '';
for (let i = 0; i < bytes.byteLength; i++) {
binary += String.fromCharCode(bytes[i]);
}
const base64 = btoa(binary);
resolve(base64);
} else {
reject(new Error('Failed to read binary file'));
}
};
reader.readAsArrayBuffer(uploadFile);
}
});
const { uploadSSHFile } = await import("@/ui/main-axios.ts"); const { uploadSSHFile } = await import("@/ui/main-axios.ts");
const response = await uploadSSHFile( const response = await uploadSSHFile(