From f6620edc357ad6945a57564df29863aac33e805d Mon Sep 17 00:00:00 2001 From: nguyentrungthat <80239428+nguentrungthat@users.noreply.github.com> Date: Thu, 15 Jan 2026 09:52:54 +0700 Subject: [PATCH] Update load license --- BACKEND/app/services/line_connection.ts | 14 ++++++- BACKEND/app/ultils/helper.ts | 55 +++++++++++++++++++++++-- 2 files changed, 64 insertions(+), 5 deletions(-) diff --git a/BACKEND/app/services/line_connection.ts b/BACKEND/app/services/line_connection.ts index b8e326d..deb6164 100644 --- a/BACKEND/app/services/line_connection.ts +++ b/BACKEND/app/services/line_connection.ts @@ -13,6 +13,7 @@ import { mapErrorsToRows, mapToLineFormat, normalizeInterface, + parseLicenseReport, sendMessageToMail, sleep, TestSession, @@ -204,7 +205,7 @@ export default class LineConnection { } if (this.outputLoadIosLicense) { if (this.outputLoadIosLicense === true) this.outputLoadIosLicense = '' - this.outputLoadIosLicense += message + this.outputLoadIosLicense += cleanData(data.toString()) } if (this.config.runningPhysical) { this.outputPhysicalTest += message @@ -1217,7 +1218,7 @@ export default class LineConnection { IOS : ${nameIos}
Started At : ${startTime}
Finished At : ${dataFormat}
- ────────────────────────────────
+
`.trim() await sendMessageToMail( @@ -1238,6 +1239,10 @@ export default class LineConnection { async sendEmailLoadLicense(nameLicense: string, startTime: string) { const timeZone = process.env.TIME_ZONE || 'Australia/Sydney' const dataFormat = momentTZ().tz(timeZone).format('YYYY/MM/DD, HH:mm:ss') + const report = parseLicenseReport( + typeof this.outputLoadIosLicense === 'string' ? this.outputLoadIosLicense : '' + ) + const body = ` Load License Report
────────────────────────────────
@@ -1247,6 +1252,11 @@ export default class LineConnection { Started At : ${startTime}
Finished At : ${dataFormat}
────────────────────────────────
+ Summary licenses: ${report.summary.join(', ')}
+ Successful: ${report.imported.join(', ')}
+ Exist: ${report.exist.join(', ')}
+ Failed: ${report.failed.join(', ')}
+
`.trim() await sendMessageToMail( diff --git a/BACKEND/app/ultils/helper.ts b/BACKEND/app/ultils/helper.ts index 0cc1250..94a8225 100644 --- a/BACKEND/app/ultils/helper.ts +++ b/BACKEND/app/ultils/helper.ts @@ -892,7 +892,7 @@ export function buildBody( repeat: '1', note: '', }, - { expect: '', send: ``, delay: '1', repeat: '1', note: '' }, + { expect: '', send: ``, delay: '4', repeat: '1', note: '' }, { expect: '#', send: listDeviceIos?.includes(fileName) ? '' : `copy tftp: flash:`, @@ -1073,7 +1073,7 @@ export function buildBody( { expect: '', send: ``, - delay: '2', + delay: '4', repeat: '1', note: '', }, @@ -1234,7 +1234,7 @@ export function buildBody( { expect: '', send: ``, - delay: '2', + delay: '4', repeat: '1', note: '', }, @@ -1337,3 +1337,52 @@ export function buildBody( return [] } } + +export function parseLicenseReport(output: string) { + const summary = [] + const imported = [] + const exist = [] + const failed = [] + + // lấy toàn bộ feature + const allFeatureRegex = /Feature:([a-z0-9_]+)/gi + let match + while ((match = allFeatureRegex.exec(output))) { + summary.push(match[1]) + } + + // split theo từng dòng install + const lines = output.split('\n') + + for (let i = 0; i < lines.length; i++) { + const line = lines[i] + + // success + const successMatch = line.match(/Feature:([a-z0-9_]+)\.\.\.Successful/i) + if (successMatch) { + imported.push(successMatch[1]) + continue + } + + // failed + const failedMatch = line.match(/Feature:([a-z0-9_]+)\.\.\.Failed:/i) + if (failedMatch) { + const feature = failedMatch[1] + + // check duplicate ở dòng sau + const nextLine = lines[i + 1] || '' + if (/Duplicate license/i.test(nextLine)) { + exist.push(feature) + } else { + failed.push(feature) + } + } + } + + return { + summary: [...summary], + imported: [...imported], + exist: [...exist], + failed: [...failed], + } +}