fix: serve Wasabi image URLs instead of local /uploads/ paths — prevent broken image links
continuous-integration/webhook Deploy concluído (VPS4)
continuous-integration/webhook Deploy concluído (VPS4)
This commit is contained in:
@@ -159,6 +159,21 @@ router.get('/patients', async (req, res) => {
|
||||
params
|
||||
);
|
||||
|
||||
// Converter thumb_filename para URL completa (Wasabi ou local)
|
||||
for (const row of rows) {
|
||||
if (row.thumb_filename) {
|
||||
try {
|
||||
const thumbUrl = await storage.getImageUrl(row.thumb_filename, row.client_name, row.patient_name);
|
||||
row.thumb_url = thumbUrl || `/uploads/${row.thumb_filename}`;
|
||||
} catch (e) {
|
||||
console.error('Erro ao gerar URL de thumbnail:', e);
|
||||
row.thumb_url = `/uploads/${row.thumb_filename}`;
|
||||
}
|
||||
} else {
|
||||
row.thumb_url = '';
|
||||
}
|
||||
}
|
||||
|
||||
res.json(rows);
|
||||
} catch (error) {
|
||||
console.error('Erro ao listar pacientes:', error);
|
||||
@@ -186,6 +201,24 @@ router.get('/by-patient', async (req, res) => {
|
||||
[patientName, showDisabled ? 0 : 1]
|
||||
);
|
||||
|
||||
// Converter filenames para URLs completas (Wasabi ou local)
|
||||
for (const image of images) {
|
||||
try {
|
||||
if (image.filename) {
|
||||
const fileUrl = await storage.getImageUrl(image.filename, image.client_name, image.patient_name);
|
||||
image.file_url = fileUrl || `/uploads/${image.filename}`;
|
||||
}
|
||||
if (image.thumb_filename) {
|
||||
const thumbUrl = await storage.getImageUrl(image.thumb_filename, image.client_name, image.patient_name);
|
||||
image.thumb_url = thumbUrl || `/uploads/${image.thumb_filename}`;
|
||||
}
|
||||
} catch (e) {
|
||||
console.error('Erro ao gerar URL para imagem:', e);
|
||||
image.file_url = image.file_url || `/uploads/${image.filename}`;
|
||||
image.thumb_url = image.thumb_url || `/uploads/${image.thumb_filename}`;
|
||||
}
|
||||
}
|
||||
|
||||
res.json(images);
|
||||
} catch (error) {
|
||||
console.error('Erro ao buscar imagens do paciente:', error);
|
||||
@@ -462,11 +495,22 @@ router.delete('/:id', async (req, res) => {
|
||||
// ================================================================
|
||||
router.get('/:id/file-url', async (req, res) => {
|
||||
try {
|
||||
const image = await db.get('SELECT filename FROM images WHERE id = $1', [req.params.id]);
|
||||
const image = await db.get('SELECT filename, client_name, patient_name FROM images WHERE id = $1', [req.params.id]);
|
||||
if (!image) return res.status(404).json({ error: 'Imagem não encontrada' });
|
||||
const url = image.filename.startsWith('http')
|
||||
? image.filename
|
||||
: `/uploads/${image.filename}`;
|
||||
|
||||
let url;
|
||||
if (image.filename.startsWith('http')) {
|
||||
url = image.filename;
|
||||
} else {
|
||||
// Se o arquivo está no Wasabi, reconstroem a URL
|
||||
try {
|
||||
const wasabiUrl = await storage.getImageUrl(image.filename, image.client_name, image.patient_name);
|
||||
url = wasabiUrl || `/uploads/${image.filename}`;
|
||||
} catch (e) {
|
||||
console.error('Erro ao gerar URL Wasabi:', e);
|
||||
url = `/uploads/${image.filename}`;
|
||||
}
|
||||
}
|
||||
res.json({ url });
|
||||
} catch (e) {
|
||||
res.status(500).json({ error: e.message });
|
||||
|
||||
Reference in New Issue
Block a user