- Aggiunto bottone Aggiungi al Carrello sulla lista dei libri dei cataloghi
This commit is contained in:
@@ -5938,6 +5938,7 @@ module.exports = {
|
||||
|
||||
async downloadImgIfMissing(productInfo) {
|
||||
const ProductInfo = require('../models/productInfo');
|
||||
const Product = require('../models/product');
|
||||
|
||||
try {
|
||||
if (this.sulServer()) {
|
||||
@@ -6015,7 +6016,7 @@ module.exports = {
|
||||
}
|
||||
|
||||
let fileesistente = false;
|
||||
if (productInfo.imagefile) {
|
||||
if (productInfo.imagefile && productInfo.imagefile !== 'noimg.jpg') {
|
||||
// controlla se esiste il file
|
||||
const img =
|
||||
this.getdirByIdApp(productInfo.idapp) +
|
||||
@@ -6030,7 +6031,7 @@ module.exports = {
|
||||
}
|
||||
|
||||
if (!vecchiomodo && (!productInfo.image_link || !fileesistente)) {
|
||||
let scarica_da_sito = !productInfo.imagefile;
|
||||
let scarica_da_sito = !productInfo.imagefile || productInfo.imagefile === 'noimg.jpg';
|
||||
|
||||
if (!scarica_da_sito && productInfo.imagefile) {
|
||||
scarica_da_sito = !fileesistente; // Se non esiste lo scarico !
|
||||
@@ -6054,7 +6055,7 @@ module.exports = {
|
||||
let aggiornatoimg;
|
||||
try {
|
||||
aggiornatoimg = await downloader.downloadImage(link, savePath, {
|
||||
maxRetries: 1,
|
||||
maxRetries: 3,
|
||||
initialDelay: 300,
|
||||
timeout: 15000,
|
||||
nomefileoriginale: true,
|
||||
@@ -6062,11 +6063,24 @@ module.exports = {
|
||||
} catch (e) {
|
||||
aggiornatoimg = { ris: false };
|
||||
}
|
||||
if (aggiornatoimg?.code === 404) {
|
||||
if (
|
||||
aggiornatoimg?.code === 404 ||
|
||||
(aggiornatoimg?.filepath && aggiornatoimg.filepath.includes('noimg.jpg'))
|
||||
) {
|
||||
// non trovato quindi la prossima volta non richiederlo
|
||||
await ProductInfo.setImgNotFound(productInfo._id);
|
||||
}
|
||||
|
||||
if (aggiornatoimg?.filepath.includes('noimg.jpg')) {
|
||||
// nascondi il prodotto se non trovo l'immagine !
|
||||
await Product.updateOne(
|
||||
{ idProductInfo: productInfo._id },
|
||||
{ $set: { deleted: true } }
|
||||
);
|
||||
|
||||
aggiornatoimg = { ris: false, deleted: true };
|
||||
}
|
||||
|
||||
if (aggiornatoimg?.filepath) {
|
||||
const filenamebase = path.basename(aggiornatoimg.filepath);
|
||||
// const img = '/upload/products/' + filenamebase;
|
||||
|
||||
Reference in New Issue
Block a user