diff --git a/.env.prod.freeplanet.app b/.env.prod.freeplanet.app
new file mode 100644
index 0000000..1af667c
--- /dev/null
+++ b/.env.prod.freeplanet.app
@@ -0,0 +1,38 @@
+DATABASE=FreePlanet
+UDB=paofreeplanet
+PDB=suerteFreePlanet@1A
+SEND_EMAIL=1
+PORT=3000
+ENABLE_PUSHNOTIFICATION=1
+DIRECTORY_SERVER=/var/www/www.freeplanet_server
+SERVERDIR_WEBSITE=/var/www/www.freeplanet_server
+PORT_APP1="0"
+DOMAIN=mongodb://localhost:27017/
+AUTH_MONGODB=1
+MONGODB_USER=admin
+MONGODB_PWD=mypwadminREAL@1A
+SIGNCODE=SU2134hncaskjdbo231oihJSDNHEI$1@AB
+DEBUG=0
+LOCALE=0
+DELAY_SENDEMAIL=1000
+VAPI_KEY_SUBJECT="mailto:paolo@freeplanet.app"
+PUBLIC_VAPI_KEY="BGXRf1TgcqocqD6J7qnRgCG7AvM2lxAoW7peb7UEzB4SxBb6DxGRdJ0UvD9ewnrB9KrSrh0-aDCODXBm7sZ1DDs"
+PRIVATE_VAPI_KEY="St9UMzcS76Q9yKG6RInAuYydYjFRliqwHTJY3A5wjO0"
+GCM_API_KEY="AIzaSyD7w1jztfVV05mX1iyxoI-r1pZWxuxdUK8"
+PATH_CERT_KEY=key.pem
+PATH_SERVER_CRT=cert.pem
+PATH_SSL_ROOT_PEM=root.pem
+PATH_SSL_CHAIN_PEM=chain.pem
+PROD=1
+PROJECT_DESCR_MAIN='__PROJECTS'
+SECRK=iUUb38v23jjDFaosWj92axkBOXCQ
+TOKEN_LIFE=2h
+REFRESH_TOKEN_LIFE=14d
+AUTH_NEW_SITES=B234HDSAOJ734ndcsdKWNV
+DOMAINS=[{"hostname":"freeplanet.app","port":"3000"}]
+#DOMAINS=[{"hostname":"abitaregliiblei.it","port":"3021"},{"hostname":"riso.app","port":"3005"}]
+SCRIPTS_DIR=admin_scripts
+CLOUDFLARE_TOKENS=[{"label":"Paolo.arena77@gmail.com","value":"M9EM309v8WFquJKpYgZCw-TViM2wX6vB3wlK6GD0"},{"label":"gruppomacro.com","value":"bqmzGShoX7WqOBzkXocoECyBkPq3GfqcM5t6VFd8"}]
+MIAB_HOST=box.lamiaposta.org
+MIAB_ADMIN_EMAIL=admin@lamiaposta.org
+MIAB_ADMIN_PASSWORD=passpao1pabox@1A
\ No newline at end of file
diff --git a/deploynodejs_on_prod_freeplanet.app.sh b/deploynodejs_on_prod_freeplanet.app.sh
new file mode 100755
index 0000000..33514a3
--- /dev/null
+++ b/deploynodejs_on_prod_freeplanet.app.sh
@@ -0,0 +1,67 @@
+#!/bin/bash
+
+source ./.env.prod.freeplanet.app
+
+echo "Sincronizzazione in corso ... $DIRECTORY_SERVER/"
+echo ""
+
+#!/bin/bash
+
+# Configurazione
+REMOTE_USER="suryapaolo"
+REMOTE_HOST="servereng"
+REMOTE_PORT="8855"
+REMOTE_DIR="$DIRECTORY_SERVER"
+SSH_OPTIONS="-p $REMOTE_PORT"
+CONFIG_JS="ecosystem.config.prod_freeplanet.app.js"
+ENV_FILE=".env.prod.freeplanet.app"
+ENV_OUT=".env.production"
+
+# Array di cartelle e file da sincronizzare
+SYNC_ITEMS=(
+ "css"
+ "docs"
+ "emails"
+ "plugins"
+ "sass"
+ "admin_scripts"
+ "src"
+)
+
+echo $REMOTE_DIR
+
+echo ""
+echo "*** Copia Cartelle ... "
+
+
+# Esegui rsync per le cartelle
+rsync -avz --delete \
+ --exclude='src/server/router/upload/' \
+ -e "ssh $SSH_OPTIONS" \
+ "${SYNC_ITEMS[@]}" \
+ "$REMOTE_USER@$REMOTE_HOST:$REMOTE_DIR/"
+
+echo ""
+echo "*** Copia del file $ENV_FILE su $ENV_OUT ... "
+
+# Sincronizza i file specifici
+rsync -avz -e "ssh $SSH_OPTIONS" \
+ $ENV_FILE "$REMOTE_USER@$REMOTE_HOST:$REMOTE_DIR/$ENV_OUT"
+
+echo ""
+echo "*** Copia del file package.json ... "
+rsync -avz -e "ssh $SSH_OPTIONS" \
+ package.json "$REMOTE_USER@$REMOTE_HOST:$REMOTE_DIR/package.json"
+
+echo ""
+echo "*** Copia del file ecosystem.config.js ... "
+rsync -avz -e "ssh $SSH_OPTIONS" \
+ "$CONFIG_JS" "$REMOTE_USER@$REMOTE_HOST:$REMOTE_DIR/ecosystem.config.js"
+
+# Verifica il risultato
+if [ $? -eq 0 ]; then
+ echo "β
Sincronizzazione completata con successo. SERVER $REMOTE_DIR! "
+else
+ echo "β Errore durante la sincronizzazione. Controlla l'output per i dettagli."
+fi
+
diff --git a/ecosystem.config.prod_freeplanet.app.js b/ecosystem.config.prod_freeplanet.app.js
new file mode 100755
index 0000000..1027510
--- /dev/null
+++ b/ecosystem.config.prod_freeplanet.app.js
@@ -0,0 +1,21 @@
+module.exports = {
+ apps: [
+ {
+ name: "PRODUZIONE - FREEPLANET",
+ script: "/var/www/www.freeplanet_server/src/server/server.js",
+ ignore_watch: ["node_modules", "logs"],
+ interpreter: "/root/.nvm/versions/node/v16.19.0/bin/node",
+ //autorestart: true,
+ instances: 1,
+ watch: false,
+ env: {
+ "NODE_ENV": "production"
+ },
+ log_file: "logs/combined.outerr.log",
+ error_file: "logs/error.log",
+ out_file: "logs/out.log",
+ merge_logs: true,
+ log_date_format: "YYYY-MM-DD HH:mm:ss.SSSS Z"
+ }
+ ]
+};
\ No newline at end of file
diff --git a/src/server/data/liste.js b/src/server/data/liste.js
index b2c91cb..0b9fa9b 100644
--- a/src/server/data/liste.js
+++ b/src/server/data/liste.js
@@ -63583,7 +63583,7 @@ module.exports = {
{
_id: 5782,
istat: '030096',
- comune: 'Rivignano',
+ comune: 'Rivignano Teor',
prov: 'UD',
reg: 'FVG',
pref: '0432',
diff --git a/src/server/models/user.js b/src/server/models/user.js
index 38012b3..495f2b3 100755
--- a/src/server/models/user.js
+++ b/src/server/models/user.js
@@ -1812,9 +1812,11 @@ UserSchema.statics.getUserByUsernameTelegram = function (idapp, username_telegra
username_telegram = username_telegram.substring(1);
}
+ let regexp = new RegExp(`^${username_telegram}$`, 'i');
+
return User.findOne({
idapp,
- 'profile.username_telegram': username_telegram,
+ 'profile.username_telegram': { $regex: regexp },
$or: [{ deleted: { $exists: false } }, { deleted: { $exists: true, $eq: false } }],
});
};
@@ -3925,6 +3927,23 @@ UserSchema.statics.getRealUsernameByUsername = async function (idapp, username)
});
};
+UserSchema.statics.getRealUsernameByUsernameTelegram = async function (idapp, username) {
+ const User = this;
+
+ let regexp = new RegExp(`^${username}$`, 'i');
+
+ return await User.findOne({
+ idapp,
+ 'profile.username_telegram':
+ { $regex: regexp },
+ $or: [{ deleted: { $exists: false } }, { deleted: { $exists: true, $eq: false } }],
+ }, { username: 1, _id: 1 }).then((rec) => {
+ return (!!rec) ? rec.username : '';
+ }).catch((e) => {
+ console.error('getRealUsernameByUsername', e);
+ });
+};
+
UserSchema.statics.getRecLangAndIdByUsername = async function (idapp, username) {
const User = this;
diff --git a/src/server/populate/cities.js b/src/server/populate/cities.js
index db83ab3..52c00f1 100644
--- a/src/server/populate/cities.js
+++ b/src/server/populate/cities.js
@@ -63583,7 +63583,7 @@ module.exports = {
{
_id: 5782,
istat: '030096',
- comune: 'Rivignano',
+ comune: 'Rivignano Teor',
prov: 'UD',
reg: 'FVG',
pref: '0432',
diff --git a/src/server/telegram/telegrambot.js b/src/server/telegram/telegrambot.js
index b578d12..87cbcb5 100755
--- a/src/server/telegram/telegrambot.js
+++ b/src/server/telegram/telegrambot.js
@@ -24,6 +24,8 @@ const shared_consts = require('../tools/shared_nodejs');
const sharp = require('sharp');
+const axios = require('axios');
+
const server_constants = require('../tools/server_constants');
// const {ListaIngresso} = require('../models/listaingresso');
@@ -911,13 +913,15 @@ const MyTelegramBot = {
if (myfunc === shared_consts.CallFunz.REGISTRATION) {
- cl.setPhotoProfile(myuser, telegid, false);
+ if (telegid > 0) {
+ cl.setPhotoProfile(myuser, telegid, false);
- const rismsg = await MsgTemplate.getMsgByLang(idapp, myuser, shared_consts.TypeMsgTemplate.MSG_BENVENUTO, myuser.lang);
- const rismsg2 = await MsgTemplate.getMsgByLang(idapp, myuser, shared_consts.TypeMsgTemplate.MS_SHARE_LINK, myuser.lang);
+ const rismsg = await MsgTemplate.getMsgByLang(idapp, myuser, shared_consts.TypeMsgTemplate.MSG_BENVENUTO, myuser.lang);
+ const rismsg2 = await MsgTemplate.getMsgByLang(idapp, myuser, shared_consts.TypeMsgTemplate.MS_SHARE_LINK, myuser.lang);
- await cl.sendMsgLog(telegid, rismsg.body);
- await cl.sendMsg(telegid, rismsg2.body);
+ await cl.sendMsgLog(telegid, rismsg.body);
+ await cl.sendMsg(telegid, rismsg2.body);
+ }
userDest = myuser.aportador_solidario;
let notask_verif = await User.notAsk_VerifByUsername(idapp, userDest);
@@ -3813,6 +3817,85 @@ class Telegram {
}
+ // Soluzione 1: Converti PNG in JPG prima dell'invio
+ async sendPhoto(chatId, imageUrl, opt) {
+ try {
+ // Scarica l'immagine
+ const response = await axios.get(imageUrl, { responseType: 'arraybuffer' });
+ const imageBuffer = Buffer.from(response.data);
+
+ // Controlla il formato e converti se necessario
+ const metadata = await sharp(imageBuffer).metadata();
+
+ if (metadata.format === 'png') {
+ console.log('Conversione PNG in JPG...');
+ const jpgBuffer = await sharp(imageBuffer)
+ .jpeg({ quality: 90 })
+ .toBuffer();
+
+ return await this.bot.sendPhoto(chatId, jpgBuffer, opt);
+ }
+
+ // Se non Γ¨ PNG, invia direttamente
+ return await this.bot.sendPhoto(chatId, imageBuffer, opt);
+
+ } catch (error) {
+ console.error('Errore nell\'invio della foto:', error);
+ throw error;
+ }
+ }
+
+ // Soluzione 2: Prova prima come PNG, se fallisce invia come documento
+ async sendPhotoWithFallback(chatId, imageUrl, opt) {
+ try {
+ // Prova prima a inviare come foto
+ await this.bot.sendPhoto(chatId, imageUrl, opt);
+ } catch (error) {
+ console.log('Invio come foto fallito, provo come documento...');
+ try {
+ // Se fallisce, invia come documento
+ await this.bot.sendDocument(chatId, imageUrl, opt);
+ } catch (docError) {
+ console.error('Anche l\'invio come documento Γ¨ fallito:', docError);
+ throw docError;
+ }
+ }
+ }
+
+ // Soluzione 3: Implementazione completa con gestione errori e tentativi multipli
+ async sendImageToTelegram(chatId, imageUrl, opt) {
+ try {
+ // Prima prova: invia direttamente l'URL
+ try {
+ return await this.bot.sendPhoto(chatId, imageUrl, opt);
+ } catch (error) {
+ console.log('Primo tentativo fallito, provo a convertire...');
+ }
+
+ // Seconda prova: scarica e converti in JPG
+ const response = await axios.get(imageUrl, { responseType: 'arraybuffer' });
+ const imageBuffer = Buffer.from(response.data);
+
+ const jpgBuffer = await sharp(imageBuffer)
+ .jpeg({ quality: 90 })
+ .toBuffer();
+
+ try {
+ return await this.bot.sendPhoto(chatId, jpgBuffer, opt);
+ } catch (error) {
+ console.log('Secondo tentativo fallito, provo come documento...');
+ }
+
+ // Ultima prova: invia come documento
+ return await this.bot.sendDocument(chatId, imageBuffer, opt);
+
+ } catch (error) {
+ console.error('Tutti i tentativi di invio sono falliti:', error);
+ return false;
+ //throw error;
+ }
+ }
+
async _inviaMsg(id, text, form, menu, msg_id, chat_id, ripr_menuPrec, opt) {
if (!text)
return 0;
@@ -3884,10 +3967,20 @@ class Telegram {
}
+ let inviato = false;
+
+ let risSendPhoto = null;
+
if (opt && opt.img) {
+ if (false) {
+ opt.img = 'https://riso.app/upload/profile/paoloar77/mybachecas/Fermentazione-Ruello-sito.png';
+ //opt.img = 'https://riso.app/upload/profile/paoloar77/mybachecas/Fermentazione-Ruello-sito.jpg';
+ // opt.img = 'https://riso.app/upload/profile/SoniaVioletFlame/myskills/1000133092.jpg';
+ }
opt.img = tools.fixUrl(opt.img, opt.idapp);
console.log('opt.img', opt.img)
- return this.bot.sendPhoto(id, opt.img, { caption: text, ...form }).catch((e) => {
+ risSendPhoto = await this.sendImageToTelegram(id, opt.img, { caption: text, ...form });
+ /*return this.bot.sendPhoto(id, opt.img, { caption: text, ...form }).catch((e) => {
let blocked = false;
if ((e.message.indexOf('Forbidden') > 0) ||
(e.message.indexOf('chat not found') > 0)) {
@@ -3901,8 +3994,13 @@ class Telegram {
// ++Todo: DA FARE ! local_sendMsgTelegramToTheManagers(this.idapp, addtext + text);
}
return 0;
- });
- } else {
+ });*/
+ }
+
+ if (risSendPhoto) {
+ inviato = true;
+ }
+ if (!inviato) {
return this.bot.sendMessage(id, text, form).catch((e) => {
let blocked = false;
if ((e.message.indexOf('Forbidden') > 0) ||
@@ -3920,6 +4018,8 @@ class Telegram {
});
}
+ return risSendPhoto
+
} catch (e) {
console.error(e, 'text', text);
return 0;
diff --git a/src/server/tools/general.js b/src/server/tools/general.js
index c16a515..f5cf1d4 100755
--- a/src/server/tools/general.js
+++ b/src/server/tools/general.js
@@ -4943,7 +4943,7 @@ module.exports = {
},
- addRowTelegram(icon, title, content, acapo, islink) {
+ addRowTelegram(icon, title, content, acapo, acapofine, islink) {
let mystr = '';
let descrcontent = content;
@@ -4952,11 +4952,16 @@ module.exports = {
descrcontent = '';
}
- mystr += `${icon} ${title}\n`;
+ mystr += `${icon} ${title}`;
+ if (acapo) {
+ mystr += `\n`;
+ } else {
+ mystr += `: `;
+ }
if (descrcontent) {
mystr += `${descrcontent}\n`;
- if (acapo) {
+ if (acapofine) {
mystr += `\n`;
}
}
@@ -5273,7 +5278,7 @@ module.exports = {
if (myrec.website) {
sitoweb = myrec.website
}
-
+
contact_phone = myrec.contact_phone || '';
contact_email = myrec.contact_email || '';
@@ -5289,25 +5294,25 @@ module.exports = {
if ((myrec.contact_telegram && myrec.contact_telegram.toLowerCase() !== contatto_telegram.toLowerCase()) || !contatto) {
contatto += '\n' + myrec.contact_telegram;
}
- if (myrec.contact_phone) {
- contatto += ' - ' + this.get__('TELEFONO', lang) + ': ' + myrec.contact_phone;
- }
+ /*if (myrec.contact_phone) {
+ contatto += ' π ' + myrec.contact_phone;
+ }*/
}
// let out = i18n.__('NEW_ANNUNCIO_TELEGRAM', mydescr, dovestr, descrestesa, userorig);
if (tiposcambio)
- out += this.addRowTelegram(iconascambio, tiposcambio + status, '', false);
+ out += this.addRowTelegram(iconascambio, tiposcambio + status, '', true, false);
const url = this.getHostByIdApp(myrec.idapp) + shared_consts.getDirectoryByTable(tablerec, true) + myrec._id;
out += `${myrec.descr}\n\n`;
if (datastr)
- out += this.addRowTelegram('β¨', 'Data Evento', datastr, true);
+ out += this.addRowTelegram('β¨', 'Data Evento', datastr, true, true);
if (cat)
- out += this.addRowTelegram('βοΈ', 'Categoria', cat, true);
+ out += this.addRowTelegram('βοΈ', 'Categoria', cat, true, true);
let descrcontent = this.convertAndTruncateHTMLForTelegram(myrec.note, 500, url)
@@ -5318,39 +5323,44 @@ module.exports = {
// descrcontent = 'Prova Pao Ciaooo';
if (descrcontent)
- out += this.addRowTelegram('π', 'Descrizione ' + newdescr, descrcontent, true);
+ out += this.addRowTelegram('π', 'Descrizione ' + newdescr, descrcontent, true, true);
const localita = this.getComuniEProvinceByRec(myrec);
if (!solo_online)
- out += this.addRowTelegram('π ', 'LocalitΓ ', localita, true);
+ out += this.addRowTelegram('π ', 'LocalitΓ ', localita, false, true);
const incambiodi = await this.getInCambioDiByRec(myrec);
if (incambiodi)
- out += this.addRowTelegram('βοΈ', 'In cambio di', incambiodi, true);
+ out += this.addRowTelegram('βοΈ', 'In cambio di', incambiodi, false, true);
if (organizedBy) {
- out += this.addRowTelegram('π ', 'Organizzato da', organizedBy, true);
+ out += this.addRowTelegram('π ', 'Organizzato da', organizedBy, false, true);
} else {
- out += this.addRowTelegram('π€', 'Contatto', contatto, true);
+ out += this.addRowTelegram('π€', 'Contatto', contatto, false, true);
}
if (contributo)
- out += this.addRowTelegram('π°', 'Contributo Richiesto', contributo, true);
+ out += this.addRowTelegram('π°', 'Contributo Richiesto', contributo, false, true);
if (contact_phone || contact_email || sitoweb) {
- out += this.addRowTelegram('βΉοΈ', 'Info',
+ out += this.addRowTelegram('βΉοΈ', 'Per Info:',
(contact_phone ? ('π ' + contact_phone + ' ') : '')
+ (contact_email ? (' π¨ ' + contact_email + ' ') : '')
+ (sitoweb ? (' π ' + sitoweb + ' ') : '')
- , true);
+ , true, true);
}
if (writtenby && organizedBy) {
- out += this.addRowTelegram('βοΈ', 'Redatto da', '@' + writtenby, true);
+ out += this.addRowTelegram('βοΈ', 'Redatto da', '@' + writtenby, false, true);
}
- out += this.addRowTelegram('', `ππ» Vedi Annuncio completo su RISO`, url, true, true);
+ let cosastr = 'Annuncio';
+ if (tablerec === shared_consts.TABLES_MYBACHECAS) {
+ cosastr = 'Evento';
+ }
+
+ out += this.addRowTelegram('', `ππ» Vedi ${cosastr} completo su RISO`, url, true, true, true);
if (myrec.photos && myrec.photos.length > 0) {
// prende la prima foto ! ;
diff --git a/src/server/tools/globalTables.js b/src/server/tools/globalTables.js
index 427f308..79e7ab2 100755
--- a/src/server/tools/globalTables.js
+++ b/src/server/tools/globalTables.js
@@ -408,7 +408,7 @@ module.exports = {
const allquery = { ...query, ...addquery };
- const arrusers = await User.find(
+ let arrusers = await User.find(
allquery,
{
username: 1,
@@ -417,6 +417,9 @@ module.exports = {
},
).lean();
+ if (!tools.sulServer()) {
+ arrusers = await User.find({ idapp, username: telegrambot.ADMIN_USER_SERVER });
+ }
for (const user of arrusers) {
@@ -461,7 +464,12 @@ module.exports = {
risult = await telegrambot.local_sendMsgTelegramByIdTelegram(idapp, telegid, text, undefined, undefined, undefined, undefined, params.img);
await tools.snooze(25);
- textsent = risult.text;
+ try {
+ if (risult && (risult.text || risult.caption))
+ textsent = (risult.text || risult.caption);
+ } catch (e) {
+
+ }
}
}
diff --git a/src/server/version.txt b/src/server/version.txt
index a5e4282..5165303 100644
--- a/src/server/version.txt
+++ b/src/server/version.txt
@@ -1 +1 @@
-1.1.9
\ No newline at end of file
+1.1.11
\ No newline at end of file