- ver 1.2.47 :
- corretto errore di modifica scheda - aggiunto scraping (fase 1)
This commit is contained in:
@@ -445,7 +445,7 @@ class ImageDownloader {
|
||||
for (let attempt = 1; attempt <= maxRetries; attempt++) {
|
||||
try {
|
||||
// Verifica se il filepath esiste già
|
||||
if (await this.existsSync(filepath)) {
|
||||
if (await this.isFileExists(filepath)) {
|
||||
fs.unlinkSync(filepath);
|
||||
}
|
||||
|
||||
@@ -533,7 +533,7 @@ class ImageDownloader {
|
||||
console.error(`❌ Errore nel tentativo ${attempt}/${maxRetries}:`, error.message);
|
||||
|
||||
// Pulizia del file in caso di errore
|
||||
if (await this.existsSync(filepath)) {
|
||||
if (await this.isFileExists(filepath)) {
|
||||
fs.unlinkSync(filepath);
|
||||
}
|
||||
|
||||
@@ -554,15 +554,6 @@ class ImageDownloader {
|
||||
}
|
||||
}
|
||||
|
||||
async existsSync(tempFolder) {
|
||||
try {
|
||||
await fs.access(tempFolder);
|
||||
// La directory esiste
|
||||
} catch {
|
||||
// La directory NON esiste
|
||||
}
|
||||
}
|
||||
|
||||
// Funzione per estrarre il nome del file dall'URL
|
||||
extractFileNameFromUrl(url) {
|
||||
const match = url.match(/\/([^/?#]+)(?:[?#]|$)/);
|
||||
@@ -736,15 +727,6 @@ module.exports = {
|
||||
console.log(args);
|
||||
},
|
||||
|
||||
existsSync: async function (tempFolder) {
|
||||
try {
|
||||
await fs.access(tempFolder);
|
||||
// La directory esiste
|
||||
} catch {
|
||||
// La directory NON esiste
|
||||
}
|
||||
},
|
||||
|
||||
mylogserr: function (...args) {
|
||||
console.error(args);
|
||||
},
|
||||
@@ -4204,7 +4186,7 @@ module.exports = {
|
||||
|
||||
async mkdirpath(dirPath) {
|
||||
try {
|
||||
if (!await this.existsSync(dirPath)) {
|
||||
if (!await this.isFileExists(dirPath)) {
|
||||
fs.mkdirSync(dirPath, { recursive: true });
|
||||
}
|
||||
} catch (e) {
|
||||
@@ -4262,8 +4244,11 @@ module.exports = {
|
||||
|
||||
async isFileExists(filename) {
|
||||
try {
|
||||
return await this.existsSync(filename);
|
||||
let fileExists = await fs.promises.stat(filename).then(() => true).catch(() => false);
|
||||
// console.log(filename, 'esiste', fileExists)
|
||||
return fileExists;
|
||||
} catch (e) {
|
||||
// console.log(filename, 'esiste', 'FALSE')
|
||||
return false
|
||||
}
|
||||
},
|
||||
@@ -5976,7 +5961,7 @@ module.exports = {
|
||||
img = dir + img;
|
||||
|
||||
/*if (checkifExist) {
|
||||
if (!this.existsSync(img)) {
|
||||
if (!this.isFileExists(img)) {
|
||||
return '';
|
||||
}
|
||||
}*/
|
||||
@@ -6150,9 +6135,9 @@ module.exports = {
|
||||
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 || !await this.existsSync(savePath);
|
||||
let scaricaimg = !productInfo.imagefile || !await this.isFileExists(savePath);
|
||||
|
||||
if (!productInfo.imagefile && await this.existsSync(savePath)) {
|
||||
if (!productInfo.imagefile && await this.isFileExists(savePath)) {
|
||||
// esiste il file, ma sul DB non è corretto
|
||||
const stats = fs.statSync(savePath); // Ottieni informazioni sul file
|
||||
|
||||
@@ -6166,7 +6151,7 @@ module.exports = {
|
||||
}
|
||||
|
||||
|
||||
if (productInfo.imagefile && await this.existsSync(savePath)) {
|
||||
if (productInfo.imagefile && await this.isFileExists(savePath)) {
|
||||
// esiste il file, ma sul DB non è corretto
|
||||
const stats = fs.statSync(savePath); // Ottieni informazioni sul file
|
||||
|
||||
@@ -6209,7 +6194,7 @@ module.exports = {
|
||||
const filecompleto = path.resolve(__dirname, img); // Sostituisci con il percorso dove salvare l'immagine
|
||||
|
||||
// Se non esiste lo scarico !
|
||||
fileesistente = await this.existsSync(filecompleto);
|
||||
fileesistente = await this.isFileExists(filecompleto);
|
||||
}
|
||||
|
||||
if (!vecchiomodo && (!productInfo.image_link || !fileesistente)) {
|
||||
|
||||
Reference in New Issue
Block a user