- Finalmente risolto il calcolo e l'impaginazione del PDF, per WEb e per Stampa (300 dpi) !

- corretto altre cose sulla lista cataloghi.
This commit is contained in:
Surya Paolo
2025-05-23 17:02:41 +02:00
parent d6aaaabb00
commit 0e5d28d199
6 changed files with 814 additions and 880 deletions

View File

@@ -546,6 +546,15 @@ module.exports = {
FIRST_PROJ: '__PROJECTS',
EXECUTE_CALCPROJ: true,
isDirectoryAsync: async function (dir) {
try {
const stats = await fs.promises.stat(dir);
return stats.isDirectory();
} catch (e) {
return false;
}
},
isFileExistsAsync: async function (filename) {
try {
let fileExists = await fs.promises
@@ -3999,33 +4008,40 @@ module.exports = {
async deleteFile(filePath) {
try {
await fs.promises.unlink(filePath);
console.log(`File eliminato con successo: ${filePath}`);
// console.log(`File eliminato con successo: ${filePath}`);
} catch (err) {
console.error(`Errore durante l'eliminazione del file: ${filePath}`, err);
throw err;
}
},
delete(mypath, alsothumb, callback) {
fs.unlink(mypath, function (err) {
if (alsothumb) {
try {
let img_small = path.dirname(mypath) + '/' + server_constants.PREFIX_IMG_SMALL + path.basename(mypath);
fs.unlink(img_small, function (err) {
if (err) console.log('Errore durante la Cancellazione del file', mypath);
else console.log('deleted file', mypath);
});
} catch (e) {
console.error(err);
async delete(mypath, alsothumb, callback) {
try {
if (await this.isFileExistsAsync(mypath)) {
await fs.promises.unlink(mypath);
// console.log(`deleted file ${mypath}`);
if (alsothumb) {
let img_small = '';
try {
img_small = path.dirname(mypath) + '/' + server_constants.PREFIX_IMG_SMALL + path.basename(mypath);
if (await this.isFileExistsAsync(img_small)) {
await fs.promises.unlink(img_small);
console.log(`deleted file ${img_small}`);
} else {
// console.warn(`File not found: ${img_small}`);
}
console.log(`deleted file ${img_small}`);
} catch (e) {
console.error(`Error deleting file ${img_small}`, e?.message);
}
}
}
if (err) {
console.error(err);
callback(err);
return;
}
callback();
});
} catch (e) {
console.error(`Error deleting file ${mypath}`, e?.message);
callback(e);
return;
}
callback();
},
async mkdirpath(dirPath) {
@@ -5974,7 +5990,6 @@ module.exports = {
}
}
let fileesistente = false;
if (productInfo.imagefile) {
// controlla se esiste il file
@@ -6102,12 +6117,14 @@ module.exports = {
removePathDirByFileName(idapp, fullfilename) {
const mydir = this.getdirByIdApp(idapp);
// ++ remove mydir from fullfilename and add myhost to generate a URL
const filename = fullfilename.replace(mydir, '').replace(/\\/g, '/'); // Replace backslashes with slashes
let filename = fullfilename.replace(mydir, '').replace(/\\/g, '/'); // Sostituisce backslash con slash
// Rimuove la barra iniziale se presente
if (filename.startsWith('/')) {
filename = filename.substring(1);
}
return filename;
},
isDateValid(mydate) {
try {
return (
@@ -6117,4 +6134,13 @@ module.exports = {
return false;
}
},
aggiungiSuffissoAlNomeFile(filePath, suffisso) {
const dir = path.dirname(filePath);
const estensione = path.extname(filePath);
const nomeFile = path.basename(filePath, estensione);
const nuovoNomeFile = nomeFile + suffisso + estensione;
return path.join(dir, nuovoNomeFile);
},
};