fix: 统一文本保存为 Unix LF 格式
This commit is contained in:
@@ -46,7 +46,9 @@ export async function handleSftpOperation(
|
|||||||
const fileContent = payload?.content ?? payload?.data ?? '';
|
const fileContent = payload?.content ?? payload?.data ?? '';
|
||||||
const encoding = payload?.encoding;
|
const encoding = payload?.encoding;
|
||||||
if (payload?.path) {
|
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);
|
sftpService.writefile(sessionId, payload.path, dataToSend, requestId, encoding);
|
||||||
} else throw new Error("Missing 'path' in payload for writefile");
|
} else throw new Error("Missing 'path' in payload for writefile");
|
||||||
break;
|
break;
|
||||||
|
|||||||
Reference in New Issue
Block a user