27 lines
1.1 KiB
JavaScript
27 lines
1.1 KiB
JavaScript
import { Router } from 'express'
|
|
import { openAttachment, sendAttachment } from '../../services/chatAttachments.js'
|
|
import { verifyFileLink } from '../../services/signedLinks.js'
|
|
|
|
/**
|
|
* Anhaenge mit signiertem Link (?exp=&sig=, 15 min) ohne JWT ausliefern: <img>, <audio> und Downloads im
|
|
* Ticketsystem koennen keinen Authorization-Header tragen. Ohne sig geht es weiter zur JWT-Pruefung.
|
|
* Eingehaengt in routes/team/index.js VOR requireStaffJwt.
|
|
*/
|
|
const router = Router()
|
|
|
|
router.get('/chats/:customerId/attachments/:id', async (req, res, next) => {
|
|
if (req.query.sig === undefined) return next()
|
|
const { customerId, id } = req.params
|
|
if (!verifyFileLink({ kind: 'chat', customerId, id, exp: req.query.exp, sig: String(req.query.sig) })) {
|
|
return res.status(403).json({ error: 'Link abgelaufen. Bitte die Unterhaltung neu laden.' })
|
|
}
|
|
try {
|
|
const found = await openAttachment({ customerId, id, viewer: 'admin' })
|
|
return sendAttachment(req, res, found)
|
|
} catch (err) {
|
|
return res.status(err.status || 500).json({ error: err.status ? err.message : 'Datei nicht verfügbar' })
|
|
}
|
|
})
|
|
|
|
export default router
|