vari piccoli fix. Importati js e css per eliminare i warning e correzioni W3c.
This commit is contained in:
1 parent
ae458256d5
commit
a1b6d9333c
13 files changed
+954
-130
No files matched your search
@@ -1958,6 +1958,118 @@ router.get('/attachments/:id', async (req, res) => {
|
||||
}
|
||||
});
|
||||
|
||||
// PUT /api/tickets/attachments/:id — Update text attachment content
|
||||
router.put('/attachments/:id', async (req, res) => {
|
||||
try {
|
||||
const { id } = req.params;
|
||||
const { content } = req.body;
|
||||
if (typeof content !== 'string') {
|
||||
return res.status(400).json({ error: 'Contenuto non valido' });
|
||||
}
|
||||
|
||||
const checkRes = await pool.query(
|
||||
`SELECT filename, content_type FROM article_data_mime_attachment WHERE id = $1`,
|
||||
[id]
|
||||
);
|
||||
if (checkRes.rows.length === 0) {
|
||||
return res.status(404).json({ error: 'Allegato non trovato' });
|
||||
}
|
||||
|
||||
const contentBuffer = Buffer.from(content, 'utf-8');
|
||||
await pool.query(
|
||||
`UPDATE article_data_mime_attachment SET content = $1, content_size = $2 WHERE id = $3`,
|
||||
[contentBuffer, contentBuffer.length, id]
|
||||
);
|
||||
res.json({ message: 'Allegato di testo aggiornato con successo' });
|
||||
} catch (err) {
|
||||
console.error('Errore aggiornamento allegato:', err);
|
||||
res.status(500).json({ error: err.message });
|
||||
}
|
||||
});
|
||||
|
||||
// POST /api/tickets/attachments/:id/open — Open attachment using OS default app (Word, Excel, etc.)
|
||||
router.post('/attachments/:id/open', async (req, res) => {
|
||||
try {
|
||||
const { id } = req.params;
|
||||
const result = await pool.query(
|
||||
`SELECT filename, content_type, content FROM article_data_mime_attachment WHERE id = $1`,
|
||||
[id]
|
||||
);
|
||||
if (result.rows.length === 0) {
|
||||
return res.status(404).json({ error: 'Allegato non trovato' });
|
||||
}
|
||||
const attachment = result.rows[0];
|
||||
|
||||
let contentBuffer;
|
||||
if (attachment.content) {
|
||||
if (Buffer.isBuffer(attachment.content)) {
|
||||
const isRawBinary = attachment.content.length > 4 && (
|
||||
(attachment.content[0] === 0x25 && attachment.content[1] === 0x50 && attachment.content[2] === 0x44 && attachment.content[3] === 0x46) ||
|
||||
(attachment.content[0] === 0xFF && attachment.content[1] === 0xD8) ||
|
||||
(attachment.content[0] === 0x89 && attachment.content[1] === 0x50) ||
|
||||
(attachment.content[0] === 0x50 && attachment.content[1] === 0x4B)
|
||||
);
|
||||
if (isRawBinary) {
|
||||
contentBuffer = attachment.content;
|
||||
} else {
|
||||
const str = attachment.content.toString('utf-8');
|
||||
const cleaned = str.replace(/\s+/g, '');
|
||||
if (cleaned.length > 0 && cleaned.length % 4 === 0 && /^[A-Za-z0-9+/]*={0,2}$/.test(cleaned)) {
|
||||
try { contentBuffer = Buffer.from(cleaned, 'base64'); } catch (_) { contentBuffer = attachment.content; }
|
||||
} else {
|
||||
contentBuffer = attachment.content;
|
||||
}
|
||||
}
|
||||
} else if (typeof attachment.content === 'string') {
|
||||
const cleaned = attachment.content.replace(/\s+/g, '');
|
||||
if (cleaned.length > 0 && cleaned.length % 4 === 0 && /^[A-Za-z0-9+/]*={0,2}$/.test(cleaned)) {
|
||||
try { contentBuffer = Buffer.from(cleaned, 'base64'); } catch (_) { contentBuffer = Buffer.from(attachment.content, 'utf-8'); }
|
||||
} else {
|
||||
contentBuffer = Buffer.from(attachment.content, 'utf-8');
|
||||
}
|
||||
} else {
|
||||
contentBuffer = Buffer.from(attachment.content);
|
||||
}
|
||||
} else {
|
||||
contentBuffer = Buffer.alloc(0);
|
||||
}
|
||||
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
const os = require('os');
|
||||
const { exec } = require('child_process');
|
||||
|
||||
const tempDir = path.join(os.tmpdir(), 'otrs_turbo_attachments');
|
||||
if (!fs.existsSync(tempDir)) {
|
||||
fs.mkdirSync(tempDir, { recursive: true });
|
||||
}
|
||||
|
||||
const safeName = (attachment.filename || `allegato_${id}`).replace(/[^a-zA-Z0-9._-]/g, '_');
|
||||
const filePath = path.join(tempDir, `${id}_${safeName}`);
|
||||
fs.writeFileSync(filePath, contentBuffer);
|
||||
|
||||
let command = `"" "${filePath}"`;
|
||||
if (process.platform === 'win32') {
|
||||
command = `start "" "${filePath}"`;
|
||||
} else if (process.platform === 'darwin') {
|
||||
command = `open "${filePath}"`;
|
||||
} else {
|
||||
command = `xdg-open "${filePath}"`;
|
||||
}
|
||||
|
||||
exec(command, (err) => {
|
||||
if (err) {
|
||||
console.error('Error opening file via OS default app:', err);
|
||||
return res.status(500).json({ error: 'Impossibile aprire il file con l\'applicazione di sistema: ' + err.message });
|
||||
}
|
||||
res.json({ message: 'File aperto con l\'applicazione predefinita di sistema', filePath });
|
||||
});
|
||||
} catch (err) {
|
||||
console.error('Errore apertura allegato:', err);
|
||||
res.status(500).json({ error: err.message });
|
||||
}
|
||||
});
|
||||
|
||||
// POST /api/tickets/merge — Merge tickets (Issue #7)
|
||||
router.post('/merge', async (req, res) => {
|
||||
const { targetId, sourceIds } = req.body;
|
||||
|
||||
Reference in new issue
Block a user