sanitize address
This commit is contained in:
@ -368,8 +368,8 @@ async function commitMessage(now, logDevice) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const time = moment.unix(logDevice.crt_d + TIMEFIX).format("DD MMM YYYY HH:mm:ss")
|
const time = moment.unix(logDevice.crt_d + TIMEFIX).format("DD MMM YYYY HH:mm:ss")
|
||||||
address = address.substring(0, 60)
|
address = sanitizeForGsm(address)
|
||||||
const rawMsg = `${nopol} | OVERSPEED | ${time} | ${logDevice.speed} km/h | ${address}`.trim()
|
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 rawMsg = `${nopol} | OVERSPEED | ${time} | ${logDevice.speed} km/h`.trim()
|
||||||
const countryCode = process.env.SMS_COUNTRY_CODE ?? "670"
|
const countryCode = process.env.SMS_COUNTRY_CODE ?? "670"
|
||||||
const smsHost = process.env.SMS_HOST ?? "http://192.168.40.2:8181"
|
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()
|
const object = new ListenController()
|
||||||
|
|
||||||
module.exports = object
|
module.exports = object
|
||||||
|
|||||||
Reference in New Issue
Block a user