This commit is contained in:
nguyentrungthat 2025-11-11 09:57:07 +07:00
parent 32873ad388
commit 3e720691fb
2 changed files with 20 additions and 7 deletions

View File

@ -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,

View File

@ -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')
} }