- piuchebuono: possiblità di modificare l'immagine dalla scheda direttamente

- migliorata di poco la grafica dell'immagine.
This commit is contained in:
Surya Paolo
2024-10-02 23:22:44 +02:00
parent 03e5d2ed81
commit f9e0175f9b
20 changed files with 108 additions and 42 deletions

View File

@@ -73,9 +73,15 @@ const productInfoSchema = new Schema({
icon: {
type: String,
},
img: { // Se esiste img (sul server) visualizza questa, altrimenti vedi se esiste image_link
img: {
type: String,
},
imagefile: {
type: String,
},
vers_img: {
type: Number,
},
image_link: {
type: String,
},
@@ -221,7 +227,54 @@ module.exports.findAllIdApp = async function (idapp, code, id) {
module.exports.getProductByCode = function (idapp, code) {
return productInfo.findAllIdApp(idapp, code);
}
module.exports.correggiProductTypes = async function() {
module.exports.replaceProductImgToImageFile = async function () {
const ProductInfo = this;
let abilitaserver = false;
if (abilitaserver) {
// const result = await ProductInfo.updateMany({ "img": { $exists: true } }, { $rename: { 'img': 'imagefile' } });
// Trova tutti i documenti con il campo 'img' che esiste
const documents = await ProductInfo.find({ "img": { $exists: true } });
// Aggiorna ciascun documento
for (let doc of documents) {
if (doc.img && doc.img.startsWith('/upload/products/')) {
// Rimuovi il prefisso '/upload/products' dal campo `img`
doc.imagefile = doc.img.replace(/^\/upload\/products\//, '');
doc.img = undefined; // Può anche rimuovere il campo img corrente se desiderato
await doc.save(); // Salva il documento aggiornato
}
}
console.log(`Updated ${documents.length} document(s) with new imagefile paths.`);
} else {
const documents = await ProductInfo.find({ "imagefile": { $exists: true } });
// Aggiorna ciascun documento
for (let doc of documents) {
if (doc.imagefile && doc.imagefile.startsWith('upload/products/')) {
// Rimuovi il prefisso '/upload/products' dal campo `img`
doc.imagefile = doc.imagefile.replace(/^\upload\/products\//, '');
await doc.save(); // Salva il documento aggiornato
}
}
console.log(`Updated ${documents.length} document(s) with new imagefile paths.`);
}
await ProductInfo.updateMany({}, { 'vers_img': 0 });
console.log(`Updated ${result.modifiedCount} document(s).`);
};
module.exports.correggiProductTypes = async function () {
const ProductInfo = this;
const bulkOps = [];

View File

@@ -63,9 +63,9 @@ async function downloadImgIfMissing(productInfo) {
const img = 'upload/products/' + productInfo.image_link.split('/').pop();
const savePath = path.resolve(__dirname, img); // Sostituisci con il percorso dove salvare l'immagine
if (!productInfo.img || !fs.existsSync(savePath)) {
if (!productInfo.imagefile || !fs.existsSync(savePath)) {
// Download image from the URL productInfo.image_link
productInfo.img = img;
productInfo.imagefile = img;
const downloader = new ImageDownloader();
@@ -131,13 +131,13 @@ async function completaSettaggioProduct_AndProductInfo(arrcampi_productInfo, arr
}
if (!rec.hasOwnProperty('img') && product.code) {
productInfo.img = 'upload/products/' + product.code + '.jpg';
productInfo.imagefile = 'upload/products/' + product.code + '.jpg';
} else {
if (rec.hasOwnProperty('img')) {
if (rec['img']) {
productInfo.img = 'upload/products/' + rec['img'];
productInfo.imagefile = 'upload/products/' + rec['img'];
} else {
productInfo.img = '';
productInfo.imagefile = '';
}
}
}
@@ -1042,6 +1042,10 @@ router.post('/import', authenticate, async (req, res) => {
product.active = true;
}
if (productInfo.productTypes.length === 1 && productInfo.productTypes[0] === undefined) {
productInfo.productTypes = [shared_consts.PRODUCTTYPE.PRODUCT];
}
let esisteindb = await ProductInfo.findOne({ code: productInfo.code }).lean();
// Update ProductInfo

View File

@@ -957,7 +957,7 @@ router.patch('/chval', authenticate, async (req, res) => {
precRec = await mytable.findById(id);
}
return await mytable.findByIdAndUpdate(id, { $set: fieldsvalue }).
return await mytable.findByIdAndUpdate(id, { $set: fieldsvalue }, { new: true }).
then(async (rec) => {
// tools.mylogshow(' REC TO MODIFY: ', rec);
if (!rec) {

View File

@@ -1650,6 +1650,9 @@ async function eseguiDbOp(idapp, mydata, locale, req, res) {
} else if (mydata.dbop === 'correggiProductTypes') {
await ProductInfo.correggiProductTypes();
} else if (mydata.dbop === 'replaceProductImgToImageFile') {
await ProductInfo.replaceProductImgToImageFile();
} else if (mydata.dbop === 'correggiCircuitiANull') {

View File

@@ -3,13 +3,12 @@ const tools = require('../tools/general');
const appTelegram = [tools.FREEPLANET, tools.RISO];
const appTelegram_TEST = [tools.FREEPLANET, tools.RISO];
const appTelegram_DEVELOP = [tools.RISO];
//const appTelegram_DEVELOP = [tools.PIUCHEBUONO];
//const appTelegram_DEVELOP = [tools.RISO];
const appTelegram_DEVELOP = [tools.PIUCHEBUONO];
const appTelegramFinti = ['2', tools.CNM];
const appTelegramDest = [tools.FREEPLANET, tools.FREEPLANET];
const appTeleg_BotOnGroup = [tools.IDAPP_BOTONGROUP];
//PIPPO
@@ -742,8 +741,8 @@ const MyTelegramBot = {
},
getAppTelegramDevelop: function () {
if (process.env.appTelegram_TEST) {
return JSON.parse(process.env.appTelegram_TEST);
if (process.env.appTelegram_DEVELOP) {
return JSON.parse(process.env.appTelegram_DEVELOP);
} else {
return appTelegram_DEVELOP;
}

View File

@@ -1115,6 +1115,7 @@ module.exports = {
PDF: 107,
STREAMING: 108,
PRODUCT: 1000,
},
AccountType: {