. esportazione lista catalogo direttamente in EXCEL, e scelta dei campi.
This commit is contained in:
@@ -17,6 +17,7 @@ const PageViewSchema = new mongoose.Schema({
|
||||
userAgent: {
|
||||
type: String
|
||||
},
|
||||
referrer: String,
|
||||
timestamp: {
|
||||
type: Date,
|
||||
default: Date.now
|
||||
|
||||
@@ -4,6 +4,12 @@ const { authenticate, authenticate_noerror } = require('../middleware/authentica
|
||||
const router = express.Router();
|
||||
const PageView = require('../models/PageView');
|
||||
|
||||
const multer = require('multer');
|
||||
const XLSX = require('xlsx');
|
||||
|
||||
const upload = multer({ dest: 'uploads/' });
|
||||
|
||||
|
||||
router.post('/test-lungo', authenticate, (req, res) => {
|
||||
const timeout = req.body.timeout;
|
||||
|
||||
@@ -25,7 +31,7 @@ router.post('/test-lungo', authenticate, (req, res) => {
|
||||
});
|
||||
|
||||
router.post('/track-pageview', authenticate_noerror, async (req, res) => {
|
||||
const { url, userAgent, idapp } = req.body;
|
||||
const { url, userAgent, idapp, referrer } = req.body;
|
||||
const ip = req.ip || req.headers['x-forwarded-for'] || 'unknown';
|
||||
|
||||
try {
|
||||
@@ -33,6 +39,7 @@ router.post('/track-pageview', authenticate_noerror, async (req, res) => {
|
||||
url,
|
||||
ip,
|
||||
idapp,
|
||||
referrer,
|
||||
userId: req.user ? req.user._id : '',
|
||||
username: req.user ? req.user.username : '',
|
||||
userAgent,
|
||||
@@ -294,4 +301,37 @@ router.get('/pageviews/weekly-top-pages', authenticate_noerror, async (req, res)
|
||||
}
|
||||
});
|
||||
|
||||
router.post('/api/convert-csv-to-xls', upload.single('csv'), (req, res) => {
|
||||
try {
|
||||
const csvFilePath = req.file.path;
|
||||
|
||||
// Leggi il CSV con SheetJS
|
||||
const csvData = fs.readFileSync(csvFilePath, 'utf-8');
|
||||
const worksheet = XLSX.utils.csv_to_sheet(csvData);
|
||||
|
||||
// Crea un file Excel
|
||||
const workbook = XLSX.utils.book_new();
|
||||
XLSX.utils.book_append_sheet(workbook, worksheet, 'Sheet1');
|
||||
|
||||
// Imposta la risposta come file XLS
|
||||
const xlsFilePath = path.join(__dirname, 'converted', 'output.xls');
|
||||
XLSX.writeFile(workbook, xlsFilePath);
|
||||
|
||||
// Restituisci il file XLS al frontend come risposta
|
||||
res.download(xlsFilePath, 'converted-file.xls', (err) => {
|
||||
if (err) {
|
||||
console.error('Errore nel download del file:', err);
|
||||
res.status(500).send('Errore nel download del file');
|
||||
}
|
||||
|
||||
// Pulisci il file temporaneo
|
||||
fs.unlinkSync(csvFilePath);
|
||||
fs.unlinkSync(xlsFilePath);
|
||||
});
|
||||
} catch (error) {
|
||||
console.error("Errore nella conversione del file:", error);
|
||||
res.status(500).send('Errore nella conversione del file');
|
||||
}
|
||||
});
|
||||
|
||||
module.exports = router;
|
||||
|
||||
@@ -2950,7 +2950,8 @@ module.exports = {
|
||||
if (qa1) query = [...query, ...qa1];
|
||||
query.push({ $unwind: '$group' });
|
||||
|
||||
if (true) {
|
||||
if (false) {
|
||||
//##++Todo: Query per i limiti GPS!
|
||||
query.push({
|
||||
$match: {
|
||||
$and: [{ 'group.idapp': params.idapp }],
|
||||
|
||||
Reference in New Issue
Block a user