sanitize address

This commit is contained in:
pringgosutono
2026-05-23 20:12:06 +09:00
parent d4dffb5138
commit 42924d1d50

View File

@ -368,8 +368,8 @@ async function commitMessage(now, logDevice) {
}
const time = moment.unix(logDevice.crt_d + TIMEFIX).format("DD MMM YYYY HH:mm:ss")
address = address.substring(0, 60)
const rawMsg = `${nopol} | OVERSPEED | ${time} | ${logDevice.speed} km/h | ${address}`.trim()
address = sanitizeForGsm(address)
const rawMsg = `${nopol} | OVERSPEED | ${time} | ${logDevice.speed} km/h | ${address}`.substring(0, 150).trim()
// const rawMsg = `${nopol} | OVERSPEED | ${time} | ${logDevice.speed} km/h`.trim()
const countryCode = process.env.SMS_COUNTRY_CODE ?? "670"
const smsHost = process.env.SMS_HOST ?? "http://192.168.40.2:8181"
@ -839,6 +839,29 @@ class ListenController {
}
}
function sanitizeForGsm(text) {
// 1. Map symbols and ligatures that do not normalize cleanly
const customMap = {
'€': 'EUR', '£': 'GBP', '¥': 'JPY',
'ß': 'ss', 'æ': 'ae', 'Æ': 'AE', 'œ': 'oe', 'Œ': 'OE',
'“': '"', '”': '"', '': "'", '': "'", '…': '...',
'': '-', '—': '-'
};
// Replace custom mapped characters
let mappedText = text.replace(
/[€£¥ßæÆœŒ“”‘’…–—]/g,
match => customMap[match]
);
// 2. Normalize and strip diacritics
// .normalize('NFD') splits characters like 'é' into 'e' + '´'
// The regex /[\u0300-\u036f]/g matches and removes those detached accent marks
let cleanText = mappedText.normalize('NFD').replace(/[\u0300-\u036f]/g, '');
return cleanText;
}
const object = new ListenController()
module.exports = object