- fix troncamento stringa , i TAG HTML non venivano chiusi. ora li ho tolti

This commit is contained in:
Surya Paolo
2024-03-06 20:46:00 +01:00
parent b5dbaafa91
commit c94d5dc844
2 changed files with 75 additions and 46 deletions

View File

@@ -1,11 +1,11 @@
DATABASE=test_PiuCheBuono DATABASE=test_FreePlanet
UDB=paofreeplanet UDB=paofreeplanet
PDB=mypassword@1A PDB=mypassword@1A
SEND_EMAIL=0 SEND_EMAIL=0
SEND_EMAIL_ORDERS=1 SEND_EMAIL_ORDERS=1
PORT=3000 PORT=3000
appTelegram_TEST=["1","17"] appTelegram_TEST=["1","13"]
appTelegram=["1","17"] appTelegram=["1","13"]
DOMAIN=mongodb://localhost:27017/ DOMAIN=mongodb://localhost:27017/
AUTH_MONGODB=true AUTH_MONGODB=true
MONGODB_USER=admin MONGODB_USER=admin

View File

@@ -4240,46 +4240,81 @@ module.exports = {
const myval = value.toString(); const myval = value.toString();
return myval.charAt(0).toUpperCase() + myval.slice(1); return myval.charAt(0).toUpperCase() + myval.slice(1);
}, },
truncateString(str, maxLength) {
if (str.length > maxLength) {
return str.slice(0, maxLength) + '...';
} else {
return str;
}
},
removeSpanAndDivTags(text) {
// Rimozione dei tag <span> e </span> dalla stringa di testo
const spanRegex = /<span[^>]*>|<\/span>/gi;
const cleanedText = text.replace(spanRegex, '');
// Rimozione dei tag <div> e </div> dalla stringa di testo
const divRegex = /<div[^>]*>|<\/div>/gi;
const finalText = cleanedText.replace(divRegex, '');
return finalText;
},
firstchars(value, numchars = 200, continua, link) { firstchars(value, numchars = 200, continua, link) {
if (!value) { if (!value) {
return ''; return '';
} }
try { try {
let truncatedValue = value; value = this.convertHTMLTagsForTelegram(value);
// Controllo se la lunghezza della stringa è maggiore di numchars value = this.removeSpanAndDivTags(value);
if (value.length > numchars) { truncatedValue = this.truncateString(value, numchars);
// Tronca la stringa alla lunghezza specificata, mantenendo i tag HTML
const tags = []; // Aggiungi il testo aggiuntivo per indicare il troncamento
let openTag = false; if (continua) {
for (let i = 0, count = 0; i < value.length && count < numchars; i++) { if (link) {
if (value[i] === '<') { truncatedValue += `<em> (... <a href="${link}">continua sulla App</a>)</em>`;
openTag = true;
} else if (value[i] === '>') {
openTag = false;
}
if (!openTag) {
count++;
}
truncatedValue = value.substring(0, i + 1);
}
// Aggiungi il testo aggiuntivo per indicare il troncamento
if (continua) {
if (link) {
truncatedValue += `<em> (... <a href="${link}">continua sulla App</a>)</em>`;
} else {
truncatedValue += `<em> (... continua sulla App)</em>`;
}
} else { } else {
truncatedValue += ' ...'; truncatedValue += `<em> (... continua sulla App)</em>`;
} }
} else {
truncatedValue += ' ...';
} }
return truncatedValue; return truncatedValue;
} catch (e) { } catch (e) {
return value; return value;
} }
}, },
convertHTMLTagsForTelegram(text) {
const htmlTagsMap = {
'<font': '<span',
'</font>': '</span>',
'<i>': '',
'</i>': '',
'<u>': '',
'</u>': '',
};
// Sostituzione dei tag HTML con quelli Markdown supportati da Telegram
let convertedText = text;
for (const htmlTag in htmlTagsMap) {
const regex = new RegExp(htmlTag, 'g');
convertedText = convertedText.replace(regex, htmlTagsMap[htmlTag]);
}
return convertedText;
},
removeFontTags(text) {
// Rimozione dei tag <font> e </font> dalla stringa di testo
const regex = /<font[^>]*>|<\/font>/gi;
const cleanedText = text.replace(regex, '');
return cleanedText;
},
removeAtChar(mystr) { removeAtChar(mystr) {
if (mystr && mystr[0] === '@') { if (mystr && mystr[0] === '@') {
return mystr = mystr.substring(1); return mystr = mystr.substring(1);
@@ -4593,22 +4628,12 @@ module.exports = {
contributo = myrec.contribstr; contributo = myrec.contribstr;
} }
if (nuovo) { if (tablerec === shared_consts.TABLES_MYGOODS) {
if (tablerec === shared_consts.TABLES_MYGOODS) { newdescr = i18n.__('Good', userorig, mydescr);
newdescr = i18n.__('NEW_GOOD', userorig, mydescr); } else if (tablerec === shared_consts.TABLES_MYSKILLS) {
} else if (tablerec === shared_consts.TABLES_MYSKILLS) { newdescr = i18n.__('Service', userorig, mydescr);
newdescr = i18n.__('NEW_SERVICE', userorig, mydescr); } else if (tablerec === shared_consts.TABLES_MYHOSPS) {
} else if (tablerec === shared_consts.TABLES_MYHOSPS) { newdescr = i18n.__('Hosp', userorig, mydescr);
newdescr = i18n.__('NEW_HOSP', userorig, mydescr);
}
} else {
if (tablerec === shared_consts.TABLES_MYGOODS) {
newdescr = i18n.__('Good', userorig, mydescr);
} else if (tablerec === shared_consts.TABLES_MYSKILLS) {
newdescr = i18n.__('Service', userorig, mydescr);
} else if (tablerec === shared_consts.TABLES_MYHOSPS) {
newdescr = i18n.__('Hosp', userorig, mydescr);
}
} }
let cat = ''; let cat = '';
let status = ''; let status = '';
@@ -4644,7 +4669,9 @@ module.exports = {
let note = this.convertHTMLTagsToText(myrec.note) let note = this.convertHTMLTagsToText(myrec.note)
let descrcontent = this.firstchars(this.removeLastSpaceAndACapo(note), 175, true, url); let descrcontent = this.firstchars(this.removeLastSpaceAndACapo(note), 400, true, url);
// descrcontent = '<span size="3"><b>Prova Pao</b> Ciaooo</span>';
if (descrcontent) if (descrcontent)
out += this.addRowTelegram('📝', 'Descrizione ' + newdescr, descrcontent, true); out += this.addRowTelegram('📝', 'Descrizione ' + newdescr, descrcontent, true);
@@ -4674,6 +4701,8 @@ module.exports = {
out += this.addRowTelegram('', `👉🏻 Vedi Annuncio completo su RISO`, url, true, true); out += this.addRowTelegram('', `👉🏻 Vedi Annuncio completo su RISO`, url, true, true);
console.log('out', out);
// out += i18n.__('ADDED_FROM', ); // out += i18n.__('ADDED_FROM', );
return { newdescr, newdescrtelegram: out } return { newdescr, newdescrtelegram: out }