Update
This commit is contained in:
parent
32873ad388
commit
3e720691fb
|
|
@ -94,6 +94,7 @@ export default class LineConnection {
|
||||||
this.client.on('data', (data) => {
|
this.client.on('data', (data) => {
|
||||||
if (this.connecting) return
|
if (this.connecting) return
|
||||||
let message = data.toString()
|
let message = data.toString()
|
||||||
|
let rawData = ''
|
||||||
if (this.isRunningScript) {
|
if (this.isRunningScript) {
|
||||||
this.waitingScenario = true
|
this.waitingScenario = true
|
||||||
this.outputBuffer += message
|
this.outputBuffer += message
|
||||||
|
|
@ -111,9 +112,10 @@ export default class LineConnection {
|
||||||
this.config.output = this.config.output.slice(0, -1)
|
this.config.output = this.config.output.slice(0, -1)
|
||||||
// message = message.slice(0, -1)
|
// message = message.slice(0, -1)
|
||||||
} else {
|
} else {
|
||||||
this.config.output += cleanData(char)
|
rawData += char
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
this.config.output += cleanData(rawData)
|
||||||
this.config.output = this.config.output.slice(-15000)
|
this.config.output = this.config.output.slice(-15000)
|
||||||
this.socketIO.emit('line_output', {
|
this.socketIO.emit('line_output', {
|
||||||
stationId,
|
stationId,
|
||||||
|
|
|
||||||
|
|
@ -7,12 +7,23 @@ import path from 'node:path'
|
||||||
* @returns {string} - The cleaned data.
|
* @returns {string} - The cleaned data.
|
||||||
*/
|
*/
|
||||||
export const cleanData = (data: string) => {
|
export const cleanData = (data: string) => {
|
||||||
return data
|
return (
|
||||||
.replace(/--More--\s*BS\s*BS\s*BS\s*BS\s*BS\s*BS/g, '')
|
data
|
||||||
.replace(/\s*--More--\s*/g, '')
|
// 1️⃣ Xóa chuỗi "--More--" (Cisco/Unix pager)
|
||||||
.replace(/\x1b\[[0-9;]*m/g, '') // Remove ANSI escape codes
|
.replace(/--More--[\s\x08\x1b\[K]*/g, '')
|
||||||
.replace(/\x08/g, '')
|
|
||||||
.replace(/[^\x20-\x7E\r\n]/g, '') // Remove non-printable characters
|
// 2️⃣ Xóa toàn bộ chuỗi ANSI escape sequences
|
||||||
|
// Ví dụ: ESC[2J, ESC[K, ESC[?25h, ESC[0m, ...
|
||||||
|
.replace(/\x1B\[[0-9;?]*[A-Za-z]/g, '')
|
||||||
|
|
||||||
|
// 3️⃣ Xóa ký tự Backspace (BS) hoặc Delete (DEL)
|
||||||
|
.replace(/[\x08\x7F]/g, '')
|
||||||
|
|
||||||
|
// 4️⃣ Xóa ký tự NUL và các control char khác (trừ \r, \n, \t)
|
||||||
|
.replace(/[^\x09\x0A\x0D\x20-\x7E]/g, '')
|
||||||
|
)
|
||||||
|
|
||||||
|
// 5️⃣ Chuẩn hóa xuống dòng nếu cần
|
||||||
// .replace(/\r\n/g, '\n')
|
// .replace(/\r\n/g, '\n')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue