- check updates

- risolto problema della generazione dei PDF, avevo modificato in CMyPageElem , se si cambia qualcosa occorre stare attenti a mettere !hideHeader
This commit is contained in:
Surya Paolo
2025-11-01 12:00:57 +01:00
parent 38c13eef28
commit 8d1dd45648
26 changed files with 660 additions and 556 deletions

View File

@@ -1,12 +1,12 @@
DATABASE=test_FreePlanet DATABASE=test_PiuCheBuono
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","13"] appTelegram_TEST=["1","17"]
appTelegram=["1","13"] appTelegram=["1","17"]
appTelegram_DEVELOP=["13"] appTelegram_DEVELOP=["17"]
DOMAIN=mongodb://localhost:27017/ DOMAIN=mongodb://localhost:27017/
AUTH_MONGODB=0 AUTH_MONGODB=0
ENABLE_PUSHNOTIFICATION=1 ENABLE_PUSHNOTIFICATION=1
@@ -29,7 +29,7 @@ GCM_API_KEY=""
PROD=0 PROD=0
PROJECT_DESCR_MAIN='__PROJECTS' PROJECT_DESCR_MAIN='__PROJECTS'
SECRK=Askb38v23jjDFaoskBOWj92axXCQ SECRK=Askb38v23jjDFaoskBOWj92axXCQ
TOKEN_LIFE=1m TOKEN_LIFE=2h
REFRESH_TOKEN_LIFE=14d REFRESH_TOKEN_LIFE=14d
FTPSERVER_HOST=139.162.166.31 FTPSERVER_HOST=139.162.166.31
FTPSERVER_PORT=21 FTPSERVER_PORT=21
@@ -38,4 +38,9 @@ FTPSERVER_PWD=ftpmypwd@1A_
AUTH_NEW_SITES=123123123 AUTH_NEW_SITES=123123123
SCRIPTS_DIR=admin_scripts SCRIPTS_DIR=admin_scripts
CLOUDFLARE_TOKENS=[{"label":"Paolo.arena77@gmail.com","value":"M9EM309v8WFquJKpYgZCw-TViM2wX6vB3wlK6GD0"},{"label":"gruppomacro.com","value":"bqmzGShoX7WqOBzkXocoECyBkPq3GfqcM5t6VFd8"}] 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
DS_API_KEY="sk-222e3addb3d8455d8b0516d93906eec7" DS_API_KEY="sk-222e3addb3d8455d8b0516d93906eec7"
SERVER_A_URL="http://51.77.156.69:3000"
API_KEY_MSSQL="m68yADSr123MIVIDA@154$DSAGVOK"

1
aggiornaserver.txt Executable file
View File

@@ -0,0 +1 @@
Aggiornamento Server...

View File

@@ -72,6 +72,11 @@ if [[ $risposta == "Y" || $risposta == "y" ]]; then
rsync -avz -e "ssh $SSH_OPTIONS" \ rsync -avz -e "ssh $SSH_OPTIONS" \
$CONFIG_JS "$REMOTE_USER@$REMOTE_HOST:$REMOTE_DIR/ecosystem.config.js" $CONFIG_JS "$REMOTE_USER@$REMOTE_HOST:$REMOTE_DIR/ecosystem.config.js"
echo ""
echo "*** Copia del file aggiornaserver.txt ... "
rsync -avz -e "ssh $SSH_OPTIONS" \
aggiornaserver.txt "$REMOTE_USER@$REMOTE_HOST:$REMOTE_DIR/aggiornaserver.txt"
# Verifica il risultato # Verifica il risultato
if [ $? -eq 0 ]; then if [ $? -eq 0 ]; then
echo "Sincronizzazione completata con successo. SERVER PCB PRODUZIONE! " echo "Sincronizzazione completata con successo. SERVER PCB PRODUZIONE! "

View File

@@ -72,6 +72,11 @@ if [[ $risposta == "Y" || $risposta == "y" ]]; then
rsync -avz -e "ssh $SSH_OPTIONS" \ rsync -avz -e "ssh $SSH_OPTIONS" \
$CONFIG_JS "$REMOTE_USER@$REMOTE_HOST:$REMOTE_DIR/ecosystem.config.js" $CONFIG_JS "$REMOTE_USER@$REMOTE_HOST:$REMOTE_DIR/ecosystem.config.js"
echo ""
echo "*** Copia del file aggiornaserver.txt ... "
rsync -avz -e "ssh $SSH_OPTIONS" \
aggiornaserver.txt "$REMOTE_USER@$REMOTE_HOST:$REMOTE_DIR/aggiornaserver.txt"
# Verifica il risultato # Verifica il risultato
if [ $? -eq 0 ]; then if [ $? -eq 0 ]; then
echo "Sincronizzazione completata con successo. SERVER PCB TEST! " echo "Sincronizzazione completata con successo. SERVER PCB TEST! "

View File

@@ -67,6 +67,12 @@ if [[ $risposta == "Y" || $risposta == "y" ]]; then
rsync -avz -e "ssh $SSH_OPTIONS" \ rsync -avz -e "ssh $SSH_OPTIONS" \
"$CONFIG_JS" "$REMOTE_USER@$REMOTE_HOST:$REMOTE_DIR/ecosystem.config.js" "$CONFIG_JS" "$REMOTE_USER@$REMOTE_HOST:$REMOTE_DIR/ecosystem.config.js"
echo ""
echo "*** Copia del file aggiornaserver.txt ... "
rsync -avz -e "ssh $SSH_OPTIONS" \
aggiornaserver.txt "$REMOTE_USER@$REMOTE_HOST:$REMOTE_DIR/aggiornaserver.txt"
# Verifica il risultato # Verifica il risultato
if [ $? -eq 0 ]; then if [ $? -eq 0 ]; then
echo "✅ Sincronizzazione completata con successo. SERVER $REMOTE_DIR! " echo "✅ Sincronizzazione completata con successo. SERVER $REMOTE_DIR! "

View File

@@ -75,6 +75,11 @@ if [[ $risposta == "Y" || $risposta == "y" ]]; then
rsync -avz -e "ssh $SSH_OPTIONS" \ rsync -avz -e "ssh $SSH_OPTIONS" \
$CONFIG_JS "$REMOTE_USER@$REMOTE_HOST:$REMOTE_DIR/ecosystem.config.js" $CONFIG_JS "$REMOTE_USER@$REMOTE_HOST:$REMOTE_DIR/ecosystem.config.js"
echo ""
echo "*** Copia del file aggiornaserver.txt ... "
rsync -avz -e "ssh $SSH_OPTIONS" \
aggiornaserver.txt "$REMOTE_USER@$REMOTE_HOST:$REMOTE_DIR/aggiornaserver.txt"
# Verifica il risultato # Verifica il risultato
if [ $? -eq 0 ]; then if [ $? -eq 0 ]; then

View File

@@ -1,10 +1,10 @@
module.exports = { module.exports = {
apps: [ apps: [
{ {
name: "PiuCheBuono (Prod)", name: "PCB-PROD",
script: "/var/www/nodejs_piuchebuono_server/src/server/server.js", script: "/var/www/nodejs_piuchebuono_server/src/server/server.js",
ignore_watch: ["node_modules", "logs"], ignore_watch: ["node_modules", "logs"],
interpreter: "/root/.nvm/versions/node/v22.13.1/bin/node", // interpreter: "/root/.nvm/versions/node/v22.13.1/bin/node",
//autorestart: true, //autorestart: true,
instances: 1, instances: 1,
watch: false, watch: false,

View File

@@ -1,10 +1,10 @@
module.exports = { module.exports = {
apps: [ apps: [
{ {
name: "PiuCheBuono (TEST)", name: "PCB-TEST",
script: "/var/www/nodejs_test.piuchebuono_server/src/server/server.js", script: "/var/www/nodejs_test.piuchebuono_server/src/server/server.js",
ignore_watch: ["node_modules", "logs"], ignore_watch: ["node_modules", "logs"],
interpreter: "/root/.nvm/versions/node/v22.13.1/bin/node", // interpreter: "/root/.nvm/versions/node/v22.13.1/bin/node",
instances: 1, instances: 1,
watch: false, watch: false,
env: { env: {

View File

@@ -4,7 +4,7 @@ module.exports = {
name: "PRODUZIONE - FREEPLANET", name: "PRODUZIONE - FREEPLANET",
script: "/var/www/www.freeplanet_server/src/server/server.js", script: "/var/www/www.freeplanet_server/src/server/server.js",
ignore_watch: ["node_modules", "logs"], ignore_watch: ["node_modules", "logs"],
interpreter: "/root/.nvm/versions/node/v16.19.0/bin/node", // interpreter: "/root/.nvm/versions/node/v16.19.0/bin/node",
//autorestart: true, //autorestart: true,
instances: 1, instances: 1,
watch: false, watch: false,

View File

@@ -1,10 +1,10 @@
module.exports = { module.exports = {
apps: [ apps: [
{ {
name: "RISO (Prod)", name: "RISO-PROD",
script: "/var/www/nodejs_riso_server/src/server/server.js", script: "/var/www/nodejs_riso_server/src/server/server.js",
ignore_watch: ["node_modules", "logs"], ignore_watch: ["node_modules", "logs"],
interpreter: "/root/.nvm/versions/node/v22.13.1/bin/node", // interpreter: "/root/.nvm/versions/node/v22.13.1/bin/node",
//autorestart: true, //autorestart: true,
instances: 1, instances: 1,
watch: false, watch: false,

View File

@@ -1,10 +1,10 @@
module.exports = { module.exports = {
apps: [ apps: [
{ {
name: "RISO (TEST)", name: "RISO-TEST",
script: "./src/server/server.js", script: "./src/server/server.js",
ignore_watch: ["node_modules", "logs"], ignore_watch: ["node_modules", "logs"],
interpreter: "/root/.nvm/versions/node/v22.13.1/bin/node", // interpreter: "/root/.nvm/versions/node/v22.13.1/bin/node",
watch: false, watch: false,
instances: 1, instances: 1,
env_test: { env_test: {

View File

@@ -34,3 +34,5 @@ Sab 11/10 ORE 19:05: USER [surya1977]: ciao
Sab 11/10 ORE 19:36: USER [surya1977]: ciao Sab 11/10 ORE 19:36: USER [surya1977]: ciao
Sab 11/10 ORE 19:38: USER [surya1977]: ciao Sab 11/10 ORE 19:38: USER [surya1977]: ciao
Lun 27/10 ORE 13:35: USER [surya1977]: ciao

View File

@@ -16,6 +16,7 @@
"author": "Surya", "author": "Surya",
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"axios": "^1.13.0",
"basic-ftp": "^5.0.5", "basic-ftp": "^5.0.5",
"bcryptjs": "^3.0.2", "bcryptjs": "^3.0.2",
"bluebird": "^3.7.2", "bluebird": "^3.7.2",
@@ -30,9 +31,11 @@
"dotenv": "^16.4.7", "dotenv": "^16.4.7",
"ejs": "^3.1.10", "ejs": "^3.1.10",
"email-templates": "^12.0.2", "email-templates": "^12.0.2",
"entities": "^7.0.0",
"express": "^4.21.2", "express": "^4.21.2",
"fast-csv": "^5.0.5", "fast-csv": "^5.0.5",
"formidable": "^3.5.2", "formidable": "^3.5.2",
"fs-extra": "^11.3.2",
"ghostscript4js": "^3.2.3", "ghostscript4js": "^3.2.3",
"helmet": "^8.1.0", "helmet": "^8.1.0",
"i18n": "^0.15.1", "i18n": "^0.15.1",
@@ -73,6 +76,7 @@
"validator": "^13.12.0", "validator": "^13.12.0",
"vhost": "^3.0.2", "vhost": "^3.0.2",
"web-push": "^3.6.7", "web-push": "^3.6.7",
"ws": "^8.18.3",
"xlsx": "^0.18.5", "xlsx": "^0.18.5",
"xml2js": "^0.6.2", "xml2js": "^0.6.2",
"xoauth2": "^1.2.0" "xoauth2": "^1.2.0"

View File

@@ -1409,7 +1409,7 @@ module.exports.removeProductInfoWithoutDateUpdatedFromGM = async function (idapp
return mylog; return mylog;
}; };
module.exports.HideProductInfoWithoutDateUpdatedFromGM = async function (idapp) { module.exports.unSetDate_Updated_fromGM_OnProduct = async function (idapp) {
const Product = this; const Product = this;
let mylog; let mylog;

View File

@@ -874,6 +874,8 @@ sendNotifSchema.statics.compileOtherFields = async function (arrnotif) {
).lean(); ).lean();
if (myimgprofile && myimgprofile.profile.img) if (myimgprofile && myimgprofile.profile.img)
notif.myimgsender = 'upload/profile/' + notif.sender + '/' + myimgprofile.profile.img; notif.myimgsender = 'upload/profile/' + notif.sender + '/' + myimgprofile.profile.img;
else
notif.myimgsender = '/images/noimg-user.svg'
} }
return arrnotif; return arrnotif;

View File

@@ -8,6 +8,8 @@ mongoose.set('debug', false);
const { ObjectId } = require('mongodb'); const { ObjectId } = require('mongodb');
const shared_consts = require('../tools/shared_nodejs');
const _ = require('lodash'); const _ = require('lodash');
// Resolving error Unknown modifier: $pushAll // Resolving error Unknown modifier: $pushAll
@@ -408,6 +410,7 @@ module.exports.createFirstUserAdmin = async function () {
const numusers = await User.countDocuments({ idapp: mysite.idapp }); const numusers = await User.countDocuments({ idapp: mysite.idapp });
if (numusers === 0) { if (numusers === 0) {
// Non esistono utenti, quindi creo quello di Admin // Non esistono utenti, quindi creo quello di Admin
console.error('❌❌❌❌ ***** Non esistono utenti, quindi creo quello di Admin ! app=', mysite.idapp);
const utenteadmin = { idapp: '13', username: shared_consts.ADMIN_USER_SERVER }; const utenteadmin = { idapp: '13', username: shared_consts.ADMIN_USER_SERVER };

View File

@@ -796,7 +796,7 @@ async function findUserByTokenAndAccess(User, decoded, token, typeaccess, withus
return await User.findOne(query, project).lean(); return await User.findOne(query, project).lean();
} catch (err) { } catch (err) {
console.warn('Errore con decoded._id, provo con decoded.smart:', err.message); // console.warn('Errore con decoded._id, provo con decoded.smart:', err.message);
// Fallback: usa decoded.smart // Fallback: usa decoded.smart
const query = { const query = {
@@ -917,6 +917,8 @@ UserSchema.statics.findByRefreshTokenAnyAccess = async function (refreshToken) {
} }
} }
return ris;
}; };

View File

@@ -472,6 +472,9 @@ class GenPdf {
filenamerelative = options.path + `${myfilenameout}${addstr}_generato.pdf`; filenamerelative = options.path + `${myfilenameout}${addstr}_generato.pdf`;
fullnamepath = tools.getdirByIdApp(this.idapp) + '/' + filenamerelative; fullnamepath = tools.getdirByIdApp(this.idapp) + '/' + filenamerelative;
await tools.ensureDir(fullnamepath);
await this.generatePdfFromUrl(url, fullnamepath, options); await this.generatePdfFromUrl(url, fullnamepath, options);
if (options.comprimi) { if (options.comprimi) {

View File

@@ -465,7 +465,7 @@ class Macro {
// disattiva dalla tabella product tutti i campi date_updated_fromGM // disattiva dalla tabella product tutti i campi date_updated_fromGM
const result = await Product.updateMany({ idapp: options.idapp }, { $unset: { date_updated_fromGM: null } }); const result = await Product.updateMany({ idapp: options.idapp }, { $unset: { date_updated_fromGM: null } });
let quanti_rimossi = result.modifiedCount; let quanti_rimossi = result. modifiedCount;
console.log(`Sbianca date_updated_fromGM da Product: (${quanti_rimossi} su ${result.matchedCount})`); console.log(`Sbianca date_updated_fromGM da Product: (${quanti_rimossi} su ${result.matchedCount})`);
rimuoviTabellePerIniziare = true; rimuoviTabellePerIniziare = true;
} }
@@ -513,7 +513,7 @@ class Macro {
} }
if (rimuoviTabellePerIniziare && options.rimuovieventualiCancellati) { if (rimuoviTabellePerIniziare && options.rimuovieventualiCancellati) {
await Product.HideProductInfoWithoutDateUpdatedFromGM(options.idapp); await Product.unSetDate_Updated_fromGM_OnProduct(options.idapp);
} }
if (myjob) await myjob.terminateJob(); if (myjob) await myjob.terminateJob();
} }

View File

@@ -746,7 +746,7 @@ router.post('/gettable', authenticate_noerror, (req, res) => {
params.table = sanitizeHtml(params.table); params.table = sanitizeHtml(params.table);
if (!shared_consts.TABLES_ENABLE_GETTABLE_FOR_NOT_LOGGED.includes(params.table) && !req.user) { if (!shared_consts.TABLES_ENABLE_GETTABLE_FOR_NOT_LOGGED.includes(params.table) && !req.user) {
return res.status(req.code).send({}); return res.status(server_constants.RIS_CODE_HTTP_FORBIDDEN_PERMESSI).send({msgerr: 'Non hai i permessi per vedere questa pagina.'});
} }
let idapp = req.user ? req.user.idapp : sanitizeHtml(params.idapp); let idapp = req.user ? req.user.idapp : sanitizeHtml(params.idapp);
@@ -2206,11 +2206,13 @@ async function load(req, res, version = '0') {
} }
router.get(process.env.LINK_CHECK_UPDATES, authenticate_noerror, async (req, res) => { router.get(process.env.LINK_CHECK_UPDATES, authenticate_noerror, async (req, res) => {
try {
const idapp = req.query.idapp; const idapp = req.query.idapp;
// console.log("POST " + process.env.LINK_CHECK_UPDATES + " userId=" + userId); // console.log("POST " + process.env.LINK_CHECK_UPDATES + " userId=" + userId);
if (!req.user) { if (!req.user) {
return res.status(req.code).send(); if (req.code === 1) return res.status(200).send();
else return res.status(req.code).send();
} }
await CfgServer.find({ idapp }) await CfgServer.find({ idapp })
@@ -2254,7 +2256,12 @@ router.get(process.env.LINK_CHECK_UPDATES, authenticate_noerror, async (req, res
if (User.isAdmin(req.user.perm)) { if (User.isAdmin(req.user.perm)) {
last_notifcoins_inattesa = SendNotif.findAllNotifCoinsAllIdAndIdApp(idapp); last_notifcoins_inattesa = SendNotif.findAllNotifCoinsAllIdAndIdApp(idapp);
} else { } else {
last_notifcoins_inattesa = SendNotif.findLastNotifCoinsByUserIdAndIdApp(req.user.username, idapp, 200, true); last_notifcoins_inattesa = SendNotif.findLastNotifCoinsByUserIdAndIdApp(
req.user.username,
idapp,
200,
true
);
} }
last_notifcoins = SendNotif.findLastNotifCoinsByUserIdAndIdApp(req.user.username, idapp, 1, false); last_notifcoins = SendNotif.findLastNotifCoinsByUserIdAndIdApp(req.user.username, idapp, 1, false);
@@ -2285,6 +2292,9 @@ router.get(process.env.LINK_CHECK_UPDATES, authenticate_noerror, async (req, res
console.log(e.message); console.log(e.message);
res.status(400).send({ code: server_constants.RIS_CODE_ERR, msg: e }); res.status(400).send({ code: server_constants.RIS_CODE_ERR, msg: e });
}); });
} catch (e) {
console.error('error:', e);
}
}); });
router.post('/upload_from_other_server/:dir', authenticate, (req, res) => { router.post('/upload_from_other_server/:dir', authenticate, (req, res) => {

View File

@@ -402,7 +402,7 @@ connectToDatabase(connectionUrl, options)
// console.log('nomeapp 1: ' , tools.getNomeAppByIdApp(1)); // console.log('nomeapp 1: ' , tools.getNomeAppByIdApp(1));
// console.log('nomeapp 2: ' , tools.getNomeAppByIdApp(2)); // console.log('nomeapp 2: ' , tools.getNomeAppByIdApp(2));
User.find({ username: 'paoloar77', idapp: '1' }).then(async (arrusers) => { User.find({ username: 'surya1977', idapp: '1' }).then(async (arrusers) => {
if (arrusers !== null) { if (arrusers !== null) {
for (const user of arrusers) { for (const user of arrusers) {
await tools await tools
@@ -466,7 +466,7 @@ connectToDatabase(connectionUrl, options)
async function inizia() { async function inizia() {
try { try {
if (true) { if (false) {
const url = 'https://raw.githubusercontent.com/matteocontrini/comuni-json/master/comuni.json'; const url = 'https://raw.githubusercontent.com/matteocontrini/comuni-json/master/comuni.json';
const outputPath = './comuni_italia_geojson.json'; const outputPath = './comuni_italia_geojson.json';
downloadGeoJSON(url, outputPath); downloadGeoJSON(url, outputPath);
@@ -672,7 +672,7 @@ connectToDatabase(connectionUrl, options)
username: 'paoloar773', username: 'paoloar773',
}); });
user.aportador_solidario = 'paoloar77'; user.aportador_solidario = 'surya1977';
let mylocalsconf = { let mylocalsconf = {
idapp, idapp,

View File

@@ -2494,16 +2494,17 @@ class Telegram {
} }
async menuRestartSrv(rec, msg, cmd2) { async menuRestartSrv(rec, msg, cmd2) {
console.log('menuRestartSrv')
if (cmd2 === '6711') { if (cmd2 === '6711') {
const freeSpace = await tools.getFreeDiskSpace(); const freeSpace = await tools.getFreeDiskSpace();
const strfree = `Spazio libero su disco: ${freeSpace}`; const strfree = `Spazio libero su disco: ${freeSpace}`;
await MyTelegramBot.sendMsgTelegramToTheAdminAllSites( await MyTelegramBot.sendMsgTelegramToTheAdminAllSites(
this.chisono(rec) + ' ha rilanciato il Server NODE.JS... \n' + strfree this.chisono(rec) + ' sta rilanciando il Server NODE.JS... \n' + strfree
); );
let file = '~/batch/production_restart_server.sh'; let file = '/opt/scripts/production_restart_server.sh';
if (process.env.NODE_ENV === 'test') { if (process.env.NODE_ENV === 'test') {
file = '~/batch/test_restart_server.sh'; file = '/opt/scripts/test_restart_server.sh';
} }
let messaggio = this.chisono(rec) + ' Restart il Server (Node.Js) : ' + file + ' ' + process.version; let messaggio = this.chisono(rec) + ' Restart il Server (Node.Js) : ' + file + ' ' + process.version;

View File

@@ -4760,29 +4760,47 @@ module.exports = {
}); });
}, },
execScriptByTelegram: function (idapp, msg, script, testo) { // general.js
execScriptByTelegram: function (idapp, msg, scriptPath, testo) {
const { exec } = require('child_process'); const { exec } = require('child_process');
const telegrambot = require('../telegram/telegrambot'); const telegrambot = require('../telegram/telegrambot');
const idchat = msg.chat.id; const idchat = msg.chat.id;
console.log(testo + ' (' + script + ')'); console.log(`👉 execScriptByTelegram: ${testo} (${scriptPath})`);
telegrambot.local_sendMsgTelegramByIdTelegram(idapp, idchat, testo); telegrambot.local_sendMsgTelegramByIdTelegram(idapp, idchat, testo);
exec(script, (error, stdout, stderr) => { // Opzioni per simulare una shell più completa
const options = {
shell: '/bin/bash',
env: {
...process.env, // eredita le variabili d'ambiente correnti
PATH: '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin',
},
timeout: 60000, // 60 secondi max
};
exec(scriptPath, options, (error, stdout, stderr) => {
let logMsg = '';
let telegramMsg = '';
if (error) { if (error) {
telegrambot.local_sendMsgTelegramByIdTelegram(idapp, idchat, 'ERROR: ' + error.message); logMsg = `❌ Script fallito: ${error.message}`;
console.log(`error: ${error.message}`); telegramMsg = `❌ ERRORE: ${error.message}`;
return; console.error(logMsg);
} } else if (stderr && !error) {
if (stderr) { // Nota: alcuni script scrivono info su stderr anche se OK → non sempre è errore!
telegrambot.local_sendMsgTelegramByIdTelegram(idapp, idchat, 'ERROR: ' + stderr); logMsg = `⚠️ Stderr (non fatale): ${stderr}`;
console.log(`stderr: ${stderr}`); telegramMsg = `⚠️ Avviso: ${stderr.substring(0, 300)}`; // tronca per Telegram
return; console.warn(logMsg);
} else {
logMsg = '✅ Script completato con successo';
telegramMsg = stdout ? stdout.substring(0, 300) : '✅ Completato';
console.log(logMsg);
} }
// console.log(` ... stdout: ${stdout}`); // Invia sempre un feedback a Telegram
telegrambot.local_sendMsgTelegramByIdTelegram(idapp, idchat, stdout); telegrambot.local_sendMsgTelegramByIdTelegram(idapp, idchat, telegramMsg);
}); });
}, },
@@ -6271,4 +6289,21 @@ module.exports = {
return null; return null;
}, },
async ensureDir(fullnamepath) {
const dir = path.dirname(fullnamepath);
try {
await fs.stat(dir);
// La directory esiste → tutto ok
} catch (err) {
if (err.code === 'ENOENT') {
console.log('Directory non esistente, creazione:', dir);
await fs.mkdir(dir, { recursive: true });
} else {
console.error('Errore imprevisto durante il controllo della directory:', err);
throw err; // Rilancia l'errore se non è ENOENT
}
}
},
}; };

View File

@@ -28,7 +28,8 @@ module.exports = Object.freeze({
RIS_CODE_LOGIN_OK: 1, RIS_CODE_LOGIN_OK: 1,
RIS_ISCRIZIONE_OK: 5, RIS_ISCRIZIONE_OK: 5,
RIS_CODE_HTTP_INVALID_TOKEN: 403, RIS_CODE_HTTP_INVALID_TOKEN: 401,
RIS_CODE_HTTP_FORBIDDEN_PERMESSI: 403,
RIS_CODE_HTTP_FORBIDDEN_TOKEN_EXPIRED: 408, RIS_CODE_HTTP_FORBIDDEN_TOKEN_EXPIRED: 408,
RIS_CODE_TOKEN_RESETPASSWORD_NOT_FOUND: -23, RIS_CODE_TOKEN_RESETPASSWORD_NOT_FOUND: -23,

View File

@@ -1 +1 @@
1.2.72 1.2.75

900
yarn.lock

File diff suppressed because it is too large Load Diff