add: added image attachments to messages

This commit is contained in:
Lukian 2025-05-12 11:26:15 +02:00
parent 8f77a271e1
commit fb90f1ef4f
10 changed files with 169 additions and 10 deletions

22
back/api/attachments.js Normal file
View file

@ -0,0 +1,22 @@
const express = require('express');
const { getConnection, getAttachment } = require('../libs/mysql');
const fs = require('node:fs');
const path = require('node:path');
const router = express.Router();
router.get('/:file_name', async (req, res) => {
const { file_name } = req.params;
const connection = await getConnection();
const attachment = await getAttachment(connection, file_name);
connection.end();
if (!attachment[0]) {
return res.status(404).send({ error: 'File not found' });
}
res.sendFile(path.join(__dirname, `../data/attachments/${attachment[0].file_name}`), { headers: { 'Content-Type': 'image' } });
})
module.exports = router;