- newsletter: prende la lista utenti (flag news_on)
- Abilita a Tutti la Newsletter news_on - isCommerciale - JobsInProgress - PCB: Corretto Totali che era a zero
This commit is contained in:
@@ -537,6 +537,11 @@ class ImageDownloader {
|
||||
fs.unlinkSync(filepath);
|
||||
}
|
||||
|
||||
// se in error.message c'è '404' allora esci e ritorna code: 404
|
||||
if (error.message.includes('404')) {
|
||||
return { ris: false, code: 404 };
|
||||
}
|
||||
|
||||
if (attempt === maxRetries) {
|
||||
console.error(`Download fallito dopo ${maxRetries} tentativi: ${error.message}`);
|
||||
return { ris: false };
|
||||
@@ -6109,28 +6114,30 @@ module.exports = {
|
||||
|
||||
async downloadImgIfMissing(productInfo) {
|
||||
|
||||
const ProductInfo = require('../models/productInfo');
|
||||
|
||||
try {
|
||||
if (this.sulServer()) {
|
||||
dirmain = '';
|
||||
} else {
|
||||
dirmain = server_constants.DIR_PUBLIC_LOCALE;
|
||||
}
|
||||
|
||||
|
||||
const vecchiomodo = false;
|
||||
|
||||
|
||||
if (productInfo.image_link && vecchiomodo) {
|
||||
|
||||
|
||||
const relativeimg = productInfo.image_link.split('/').pop();
|
||||
const img = this.getdirByIdApp(productInfo.idapp) + dirmain +
|
||||
server_constants.DIR_UPLOAD + '/products/' + productInfo.image_link.split('/').pop();
|
||||
const savePath = path.resolve(__dirname, img); // Sostituisci con il percorso dove salvare l'immagine
|
||||
|
||||
|
||||
let scaricaimg = !productInfo.imagefile || !fs.existsSync(savePath);
|
||||
|
||||
|
||||
if (!productInfo.imagefile && fs.existsSync(savePath)) {
|
||||
// esiste il file, ma sul DB non è corretto
|
||||
const stats = fs.statSync(savePath); // Ottieni informazioni sul file
|
||||
|
||||
|
||||
if (stats.size > 0) { // Controlla se la dimensione del file è maggiore di zero
|
||||
// Esiste il file ed è non vuoto, ma sul DB non è corretto
|
||||
productInfo.imagefile = relativeimg;
|
||||
@@ -6139,23 +6146,24 @@ module.exports = {
|
||||
scaricaimg = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
if (productInfo.imagefile && fs.existsSync(savePath)) {
|
||||
// esiste il file, ma sul DB non è corretto
|
||||
const stats = fs.statSync(savePath); // Ottieni informazioni sul file
|
||||
|
||||
|
||||
if (stats.size <= 0) { // Controlla se la dimensione del file è maggiore di zero
|
||||
scaricaimg = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
if (scaricaimg && vecchiomodo) {
|
||||
// Download image from the URL productInfo.image_link
|
||||
productInfo.imagefile = relativeimg;
|
||||
|
||||
|
||||
const downloader = new ImageDownloader();
|
||||
|
||||
|
||||
const aggiornatoimg = await downloader.downloadImage(productInfo.image_link, savePath,
|
||||
{
|
||||
maxRetries: 1,
|
||||
@@ -6167,80 +6175,82 @@ module.exports = {
|
||||
} else {
|
||||
console.log('Download non riuscito.');
|
||||
}
|
||||
|
||||
|
||||
return result;
|
||||
|
||||
|
||||
});
|
||||
return { prodInfo: productInfo, aggiornatoimg: aggiornatoimg.ris };
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
let fileesistente = false;
|
||||
if (productInfo.imagefile) {
|
||||
// controlla se esiste il file
|
||||
const img = this.getdirByIdApp(productInfo.idapp) + dirmain +
|
||||
server_constants.DIR_UPLOAD + '/products/' + productInfo.imagefile.split('/').pop();
|
||||
const filecompleto = path.resolve(__dirname, img); // Sostituisci con il percorso dove salvare l'immagine
|
||||
|
||||
|
||||
// Se non esiste lo scarico !
|
||||
fileesistente = fs.existsSync(filecompleto);
|
||||
}
|
||||
|
||||
|
||||
if (!vecchiomodo && (!productInfo.image_link || !fileesistente)) {
|
||||
|
||||
|
||||
let scarica_da_sito = !productInfo.imagefile;
|
||||
|
||||
|
||||
if (!scarica_da_sito && productInfo.imagefile) {
|
||||
scarica_da_sito = !fileesistente; // Se non esiste lo scarico !
|
||||
}
|
||||
|
||||
if (scarica_da_sito) {
|
||||
|
||||
if (scarica_da_sito && !productInfo.image_not_found) {
|
||||
// date and time
|
||||
productInfo.imagefile = 'img_' + new Date().toISOString().replace(/T/, ' ').replace(/\..+/, '');
|
||||
const img = this.getdirByIdApp(productInfo.idapp) + dirmain +
|
||||
server_constants.DIR_UPLOAD + '/products/' + productInfo.imagefile.split('/').pop();
|
||||
let savePath = path.resolve(__dirname, img); // Sostituisci con il percorso dove salvare l'immagine
|
||||
|
||||
|
||||
|
||||
|
||||
let link = 'https://www.gruppomacro.com/copertine.php?id_gm=' + productInfo.sku
|
||||
|
||||
|
||||
const downloader = new ImageDownloader();
|
||||
|
||||
|
||||
const aggiornatoimg = await downloader.downloadImage(link, savePath,
|
||||
{
|
||||
maxRetries: 1,
|
||||
initialDelay: 300,
|
||||
timeout: 15000,
|
||||
nomefileoriginale: true,
|
||||
}).then(result => {
|
||||
if (result) {
|
||||
// console.log('Download completato con successo!');
|
||||
} else {
|
||||
console.log('Download non riuscito.');
|
||||
}
|
||||
|
||||
return result;
|
||||
|
||||
});
|
||||
if (aggiornatoimg.filepath) {
|
||||
|
||||
|
||||
let aggiornatoimg;
|
||||
try {
|
||||
aggiornatoimg = await downloader.downloadImage(link, savePath,
|
||||
{
|
||||
maxRetries: 1,
|
||||
initialDelay: 300,
|
||||
timeout: 15000,
|
||||
nomefileoriginale: true,
|
||||
});
|
||||
} catch (e) {
|
||||
aggiornatoimg = { ris: false };
|
||||
}
|
||||
if (aggiornatoimg?.code === 404) {
|
||||
// non trovato quindi la prossima volta non richiederlo
|
||||
await ProductInfo.setImgNotFound(productInfo._id);
|
||||
}
|
||||
|
||||
|
||||
if (aggiornatoimg?.filepath) {
|
||||
const filenamebase = path.basename(aggiornatoimg.filepath);
|
||||
// const img = '/upload/products/' + filenamebase;
|
||||
productInfo.imagefile = filenamebase;
|
||||
}
|
||||
|
||||
|
||||
return { prodInfo: productInfo, aggiornatoimg: aggiornatoimg.ris };
|
||||
} else {
|
||||
return { prodInfo: null, aggiornatoimg: false };
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
} catch (e) {
|
||||
console.error('downloadImgIfMissing', e.message);
|
||||
}
|
||||
|
||||
|
||||
return { prodInfo: null, aggiornatoimg: false };
|
||||
|
||||
|
||||
},
|
||||
|
||||
removeAccents(mystr) {
|
||||
@@ -6257,7 +6267,7 @@ module.exports = {
|
||||
|
||||
return Array.from(mystr).map(char => accentsMap.get(char) || char).join('');
|
||||
},
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -53,6 +53,7 @@ const { CfgServer } = require('../models/cfgserver');
|
||||
const { CalZoom } = require('../models/calzoom');
|
||||
const { Gallery } = require('../models/gallery');
|
||||
const { TemplEmail } = require('../models/templemail');
|
||||
const { DestNewsletter } = require('../models/destnewsletter');
|
||||
const { OpzEmail } = require('../models/opzemail');
|
||||
const { MailingList } = require('../models/mailinglist');
|
||||
const { Settings } = require('../models/settings');
|
||||
@@ -207,6 +208,8 @@ module.exports = {
|
||||
mytable = CalZoom;
|
||||
else if (tablename === 'templemail')
|
||||
mytable = TemplEmail;
|
||||
else if (tablename === 'destnewsletter')
|
||||
mytable = DestNewsletter;
|
||||
else if (tablename === 'opzemail')
|
||||
mytable = OpzEmail;
|
||||
else if (tablename === 'settings')
|
||||
|
||||
@@ -359,6 +359,7 @@ module.exports = {
|
||||
Zoomeri: 32,
|
||||
Department: 64,
|
||||
Grafico: 128,
|
||||
Commerciale: 256,
|
||||
},
|
||||
|
||||
MessageOptions: {
|
||||
@@ -730,6 +731,8 @@ module.exports = {
|
||||
'profile',
|
||||
'calcstat',
|
||||
'news_on',
|
||||
'diario_on',
|
||||
'test',
|
||||
'aportador_solidario',
|
||||
'made_gift',
|
||||
'ind_order',
|
||||
@@ -1195,6 +1198,26 @@ module.exports = {
|
||||
EXCEED_QTAMAX: 20,
|
||||
},
|
||||
|
||||
DESTNEWSLETTER: {
|
||||
LISTA_NEWSLETTER: 0,
|
||||
UTENTI: 1,
|
||||
DIARIO: 2,
|
||||
TEST: 10,
|
||||
},
|
||||
|
||||
STATUS_JOB: {
|
||||
NONE: 0,
|
||||
START: 1,
|
||||
FINISH: 10,
|
||||
PAUSE: 2,
|
||||
},
|
||||
|
||||
TERMINATED_WHY: {
|
||||
END_NORMALLY: 1,
|
||||
END_WITHERROR: -50,
|
||||
TOOLONGTIME: -10,
|
||||
}
|
||||
|
||||
// Download, DVD, Epub, Mobi, Nuovo, PDF, Streaming, Usato
|
||||
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user