- Aggiornato node.js alla versione 22.18.1

- Aggiornato tutti i pacchetti del server all'ultima versione.
- passato mongoose da versione 5 a versione 6
This commit is contained in:
Surya Paolo
2025-03-03 00:46:08 +01:00
parent 45d06b0923
commit 53a70a1c96
120 changed files with 3385 additions and 6065 deletions

View File

@@ -873,7 +873,7 @@ module.exports = {
catch((err) => {
if (err.statusCode === 410) {
// Gone: is not valid anymore (Expired probably!), so I have to delete from my db
return Subscription.findOneAndRemove({ _id: subscription._id });
return Subscription.findOneAndDelete({ _id: subscription._id });
} else {
console.log('Subscription is no longer valid: ', err);
}
@@ -910,95 +910,99 @@ module.exports = {
try {
return await Subscription.find({ userId }, (err, subscriptions) => {
if (err) {
console.error(`Error occurred while getting subscriptions`);
// res.status(500).json({
// error: 'Technical error occurred'
// });
let subscriptions = [];
try {
subscriptions = await Subscription.find({ userId });
} catch (err) {
console.error(`Error occurred while getting subscriptions`);
// res.status(500).json({
// error: 'Technical error occurred'
// });
//++ Rimuovi questo record !?
//++ Rimuovi questo record !?
return false;
} else {
let conta = 0;
let parallelSubscriptionCalls = subscriptions.map((subscription) => {
const trovati = subscriptions.length;
return new Promise((resolve, reject) => {
const pushSubscription = {
return false;
}
let conta = 0;
if (subscriptions && subscriptions.length > 0) {
let parallelSubscriptionCalls = subscriptions.map((subscription) => {
const trovati = subscriptions.length;
return new Promise((resolve, reject) => {
const pushSubscription = {
endpoint: subscription.endpoint,
keys: {
p256dh: subscription.keys.p256dh,
auth: subscription.keys.auth,
},
};
conta++;
const parse = require('url-parse');
const parsedUrl = parse(subscription.endpoint);
const audience = parsedUrl.protocol + '//' + parsedUrl.hostname;
const vapidHeaders = webpush.getVapidHeaders(
audience,
process.env.VAPI_KEY_SUBJECT,
process.env.PUBLIC_VAPI_KEY,
process.env.PRIVATE_VAPI_KEY,
'aes128gcm',
);
const pushOptions = {
vapidDetails: {
subject: process.env.VAPI_KEY_SUBJECT,
privateKey: process.env.PRIVATE_VAPI_KEY,
publicKey: process.env.PUBLIC_VAPI_KEY,
},
TTL: payload.ttl,
headers: vapidHeaders,
};
// console.log('************ INVIO WEBPUSH.SENDNOTIFICATION N° ', conta, '/', trovati, 'A', subscription.browser);
const pushPayload = JSON.stringify(payload);
webpush.sendNotification(
pushSubscription,
pushPayload,
pushOptions,
).then((value) => {
// console.log('Invio Push', value);
resolve({
status: true,
endpoint: subscription.endpoint,
keys: {
p256dh: subscription.keys.p256dh,
auth: subscription.keys.auth,
},
};
conta++;
const parse = require('url-parse');
const parsedUrl = parse(subscription.endpoint);
const audience = parsedUrl.protocol + '//' + parsedUrl.hostname;
const vapidHeaders = webpush.getVapidHeaders(
audience,
process.env.VAPI_KEY_SUBJECT,
process.env.PUBLIC_VAPI_KEY,
process.env.PRIVATE_VAPI_KEY,
'aes128gcm',
);
const pushOptions = {
vapidDetails: {
subject: process.env.VAPI_KEY_SUBJECT,
privateKey: process.env.PRIVATE_VAPI_KEY,
publicKey: process.env.PUBLIC_VAPI_KEY,
},
TTL: payload.ttl,
headers: vapidHeaders,
};
// console.log('************ INVIO WEBPUSH.SENDNOTIFICATION N° ', conta, '/', trovati, 'A', subscription.browser);
const pushPayload = JSON.stringify(payload);
webpush.sendNotification(
pushSubscription,
pushPayload,
pushOptions,
).then((value) => {
// console.log('Invio Push', value);
resolve({
status: true,
endpoint: subscription.endpoint,
data: value,
});
}).catch(async (err) => {
console.error('err Push', err.body);
if (err.body) {
// Cancella dal DB la notifica Push, visto che da errore! (sarà scaduto)
const ris = await Subscription.deleteOne({ _id: subscription._id });
}
reject({
status: false,
endpoint: subscription.endpoint,
data: err,
});
data: value,
});
}).catch(async (err) => {
console.error('err Push', err.body);
if (err.body) {
// Cancella dal DB la notifica Push, visto che da errore! (sarà scaduto)
const ris = await Subscription.deleteOne({ _id: subscription._id });
}
reject({
status: false,
endpoint: subscription.endpoint,
data: err,
});
}).catch(error => {
console.log('ERROR: sendNotificationToUser', error.data.body ? error.data.body : error);
});
}).catch(error => {
console.log('ERROR: sendNotificationToUser', error.data.body ? error.data.body : error);
});
// q.allSettled(parallelSubscriptionCalls).then((pushResults) => {
// console.info(pushResults);
// });
// res.json({
// data: 'Push triggered'
// });
return true;
}
});
});
return true;
}
// q.allSettled(parallelSubscriptionCalls).then((pushResults) => {
// console.info(pushResults);
// });
// res.json({
// data: 'Push triggered'
// });
} catch (e) {
console.error('sendNotificationToUser', e.message);
}
@@ -2755,10 +2759,10 @@ module.exports = {
let condition = {};
for (const myfilter of params.filtercustom) {
if (myfilter['userId']) {
myfilter['userId'] = ObjectId(myfilter['userId']);
myfilter['userId'] = new ObjectId(myfilter['userId']);
}
if (myfilter['_idOBJ']) {
filtriadded.push({ _id: ObjectId(myfilter['_idOBJ']) });
filtriadded.push({ _id: new ObjectId(myfilter['_idOBJ']) });
} else if (myfilter['dateTimeStart']) {
const gte = myfilter['dateTimeStart'].$gte;
const lte = myfilter['dateTimeStart'].$lte;
@@ -3373,7 +3377,11 @@ module.exports = {
startTimeLog(name) {
if (this.testing()) {
// console.log('inizio', name);
console.time(name);
try {
console.time(name);
} catch (e) {
}
}
},
@@ -3446,12 +3454,11 @@ module.exports = {
newrec.idapp = idappdest;
try {
await newrec.save((err, rec) => {
if (rec) {
num++;
}
const rec = await newrec.save();
if (rec) {
num++;
}
});
} catch (e) {
console.error('e', e);
}
@@ -4093,15 +4100,15 @@ module.exports = {
},
mkdirpath(dirPath) {
if (!fs.existsSync(dirPath)) {
try {
try {
if (!fs.existsSync(dirPath)) {
fs.mkdirSync(dirPath, { recursive: true });
} catch (e) {
if (dirPath !== path.dirname(dirPath)) {
const myname = path.dirname(dirPath);
this.mkdirpath(myname);
// this.mkdirpath(dirPath);
}
}
} catch (e) {
if (dirPath !== path.dirname(dirPath)) {
const myname = path.dirname(dirPath);
this.mkdirpath(myname);
// this.mkdirpath(dirPath);
}
}
},
@@ -5044,7 +5051,7 @@ module.exports = {
if (title) {
if (icon)
mystr += `${icon} `;
mystr += `<strong>${title}</strong>`;
if (acapo) {
@@ -5958,6 +5965,20 @@ module.exports = {
}
},
async findAllQueryIdApp(model, myfind, sort) {
try {
if (sort) {
return await model.find(myfind).sort(sort).lean();
} else {
return await model.find(myfind).lean();
}
} catch (err) {
console.error("Errore in findAllQueryIdApp:", err, model);
return null;
}
},
// Funzione per implementare il ritardo tra i tentativi
sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms));