- 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
PDB=mypassword@1A
SEND_EMAIL=0
SEND_EMAIL_ORDERS=1
PORT=3000
appTelegram_TEST=["1","17"]
appTelegram=["1","17"]
appTelegram_TEST=["1","13"]
appTelegram=["1","13"]
DOMAIN=mongodb://localhost:27017/
AUTH_MONGODB=true
MONGODB_USER=admin

View File

@@ -4240,46 +4240,81 @@ module.exports = {
const myval = value.toString();
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) {
if (!value) {
return '';
}
try {
let truncatedValue = value;
// Controllo se la lunghezza della stringa è maggiore di numchars
if (value.length > numchars) {
// Tronca la stringa alla lunghezza specificata, mantenendo i tag HTML
const tags = [];
let openTag = false;
for (let i = 0, count = 0; i < value.length && count < numchars; i++) {
if (value[i] === '<') {
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>`;
}
value = this.convertHTMLTagsForTelegram(value);
value = this.removeSpanAndDivTags(value);
truncatedValue = this.truncateString(value, numchars);
// Aggiungi il testo aggiuntivo per indicare il troncamento
if (continua) {
if (link) {
truncatedValue += `<em> (... <a href="${link}">continua sulla App</a>)</em>`;
} else {
truncatedValue += ' ...';
truncatedValue += `<em> (... continua sulla App)</em>`;
}
} else {
truncatedValue += ' ...';
}
return truncatedValue;
} catch (e) {
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) {
if (mystr && mystr[0] === '@') {
return mystr = mystr.substring(1);
@@ -4593,22 +4628,12 @@ module.exports = {
contributo = myrec.contribstr;
}
if (nuovo) {
if (tablerec === shared_consts.TABLES_MYGOODS) {
newdescr = i18n.__('NEW_GOOD', userorig, mydescr);
} else if (tablerec === shared_consts.TABLES_MYSKILLS) {
newdescr = i18n.__('NEW_SERVICE', userorig, mydescr);
} else if (tablerec === shared_consts.TABLES_MYHOSPS) {
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);
}
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 status = '';
@@ -4644,7 +4669,9 @@ module.exports = {
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)
out += this.addRowTelegram('📝', 'Descrizione ' + newdescr, descrcontent, true);
@@ -4674,6 +4701,8 @@ module.exports = {
out += this.addRowTelegram('', `👉🏻 Vedi Annuncio completo su RISO`, url, true, true);
console.log('out', out);
// out += i18n.__('ADDED_FROM', );
return { newdescr, newdescrtelegram: out }
@@ -4782,7 +4811,7 @@ module.exports = {
// return inputString.replace(/\\/g, '').replace(/"/g, '');
if (inputString)
return inputString.replace(/\\/g, '').replace(/"/g, '');
else
else
return '';
},