fix: 统一文本保存为 Unix LF 格式

This commit is contained in:
Baobhan Sith
2025-05-14 09:11:20 +08:00
parent 38b841d52b
commit 15d279e6f5
@@ -46,7 +46,9 @@ export async function handleSftpOperation(
const fileContent = payload?.content ?? payload?.data ?? '';
const encoding = payload?.encoding;
if (payload?.path) {
const dataToSend = (typeof fileContent === 'string') ? fileContent : '';
let dataToSend = (typeof fileContent === 'string') ? fileContent : '';
// Convert only true line endings (CRLF and standalone CR not followed by LF) to LF to ensure Unix-compatible line endings
dataToSend = dataToSend.replace(/\r\n/g, '\n').replace(/\r(?!\n)/g, '\n');
sftpService.writefile(sessionId, payload.path, dataToSend, requestId, encoding);
} else throw new Error("Missing 'path' in payload for writefile");
break;