fix: visualizzazione delle immagini nelle note e mail inviate. fix: corretto veramente problema del fusorario delle mail. feat: tooltip fullscreen per le immagini.

This commit is contained in:
2026-07-13 22:08:53 +02:00
parent a7fb2c22f0
commit 964241d8ec
3 changed files with 172 additions and 31 deletions
+25 -16
View File
@@ -3,6 +3,13 @@ const router = express.Router();
const pool = require('../db');
const { db, logAttivita } = require('../activityDb');
// Helper to get local timestamp in YYYY-MM-DD HH:mm:ss format
function getLocalTimestamp() {
const d = new Date();
const pad = (n) => String(n).padStart(2, '0');
return `${d.getFullYear()}-${pad(d.getMonth() + 1)}-${pad(d.getDate())} ${pad(d.getHours())}:${pad(d.getMinutes())}:${pad(d.getSeconds())}`;
}
// Helper: resolve agent name from DB (best-effort, non-blocking)
async function resolveAgentName(agentId) {
try {
@@ -427,7 +434,7 @@ router.get('/:id', async (req, res) => {
// Fetch attachments metadata for all articles in the ticket
const attachmentsResult = await pool.query(
`SELECT id, article_id, filename, content_size, content_type, disposition
`SELECT id, article_id, filename, content_size, content_type, disposition, content_id
FROM article_data_mime_attachment
WHERE article_id IN (
SELECT id FROM article WHERE ticket_id = $1
@@ -1238,6 +1245,8 @@ router.post('/:id/articles', async (req, res) => {
);
const channelId = channelResult.rows.length > 0 ? channelResult.rows[0].id : 1;
const localNow = getLocalTimestamp();
// Create article
const articleResult = await client.query(
`INSERT INTO article (
@@ -1245,9 +1254,9 @@ router.post('/:id/articles', async (req, res) => {
is_visible_for_customer, search_index_needs_rebuild,
create_time, create_by, change_time, change_by
) VALUES (
$1, $2, $3, $4, 1, NOW(), $5, NOW(), $5
$1, $2, $3, $4, 1, $5, $6, $5, $6
) RETURNING id`,
[id, senderTypeId, channelId, is_visible_for_customer ? 1 : 0, operatorId]
[id, senderTypeId, channelId, is_visible_for_customer ? 1 : 0, localNow, operatorId]
);
const articleId = articleResult.rows[0].id;
@@ -1269,9 +1278,9 @@ router.post('/:id/articles', async (req, res) => {
$1, $2, '', '', '', '', $3, $4,
'', '', '',
$5, EXTRACT(EPOCH FROM NOW())::INTEGER, $6,
NOW(), $7, NOW(), $7
$7, $8, $7, $8
)`,
[articleId, fromHeader, subject || 'Nota interna', body, contentType, contentPath, operatorId]
[articleId, fromHeader, subject || 'Nota interna', body, contentType, contentPath, localNow, operatorId]
);
// Create article_data_mime_attachment for OTRS CE HTML rendering (using file-1 and base64 encoded text)
@@ -1286,9 +1295,9 @@ router.post('/:id/articles', async (req, res) => {
create_time, create_by, change_time, change_by
) VALUES (
$1, 'file-1', $2, 'text/html; charset="utf-8"', '', $3,
NOW(), $4, NOW(), $4
$4, $5, $4, $5
)`,
[articleId, String(contentSize), base64Body, operatorId]
[articleId, String(contentSize), base64Body, localNow, operatorId]
);
// Insert additional attachments if any
@@ -1299,14 +1308,15 @@ router.post('/:id/articles', async (req, res) => {
`INSERT INTO article_data_mime_attachment (
article_id, filename, content_size, content_type, disposition, content,
create_time, create_by, change_time, change_by
) VALUES ($1, $2, $3, $4, 'attachment', $5, NOW(), $6, NOW(), $6)`,
) VALUES ($1, $2, $3, $4, 'attachment', $5, $7, $6, $7, $6)`,
[
articleId,
att.filename,
contentBuffer.length,
att.content_type || 'application/octet-stream',
att.content, // base64 string directly
operatorId
operatorId,
localNow
]
);
}
@@ -1320,16 +1330,15 @@ router.post('/:id/articles', async (req, res) => {
`INSERT INTO time_accounting (
ticket_id, article_id, time_unit,
create_time, create_by, change_time, change_by
) VALUES ($1, $2, $3, NOW(), $4, NOW(), $4)`,
[id, articleId, parsedTime, operatorId]
) VALUES ($1, $2, $3, $5, $4, $5, $4)`,
[id, articleId, parsedTime, operatorId, localNow]
);
}
}
// Update ticket change_time
await client.query(
`UPDATE ticket SET change_time = NOW(), change_by = $1 WHERE id = $2`,
[operatorId, id]
`UPDATE ticket SET change_time = $1, change_by = $2 WHERE id = $3`,
[localNow, operatorId, id]
);
// Add history entry
@@ -1351,13 +1360,13 @@ router.post('/:id/articles', async (req, res) => {
) VALUES (
$1, $2, $3, $4, $5, $6,
$7, $8, $9,
NOW(), $10, NOW(), $10
$11, $10, $11, $10
)`,
[
`%%`,
htResult.rows[0].id, id, articleId, t.type_id || 1, t.queue_id,
t.user_id, t.ticket_priority_id, t.ticket_state_id,
operatorId
operatorId, localNow
]
);
}