fix: add public thumbnail endpoint without auth — allow images to load without login
continuous-integration/webhook Deploy concluído (VPS4)
continuous-integration/webhook Deploy concluído (VPS4)
This commit is contained in:
@@ -467,41 +467,6 @@ router.delete('/:id', async (req, res) => {
|
||||
}
|
||||
});
|
||||
|
||||
// ================================================================
|
||||
// GET /api/images/:id/thumbnail — Retorna URL da thumbnail
|
||||
// (lazy-loaded para não bloquear listagens)
|
||||
// ================================================================
|
||||
router.get('/:id/thumbnail', async (req, res) => {
|
||||
try {
|
||||
const image = await db.get('SELECT thumb_filename, 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 fileToCheck = image.thumb_filename || image.filename;
|
||||
let url;
|
||||
|
||||
// Tenta URL local primeiro (mais rápido)
|
||||
const fsSync = require('fs');
|
||||
const path = require('path');
|
||||
const localPath = path.join(process.env.UPLOAD_DIR || '/app/uploads', fileToCheck);
|
||||
|
||||
if (fsSync.existsSync(localPath)) {
|
||||
url = `/uploads/${fileToCheck}`;
|
||||
} else {
|
||||
// Se não existe localmente, tenta Wasabi
|
||||
try {
|
||||
const wasabiUrl = await storage.getImageUrl(fileToCheck, image.client_name, image.patient_name, false);
|
||||
url = wasabiUrl || `/uploads/${fileToCheck}`;
|
||||
} catch (e) {
|
||||
console.error('Erro ao gerar URL Wasabi para thumbnail:', e);
|
||||
url = `/uploads/${fileToCheck}`;
|
||||
}
|
||||
}
|
||||
res.json({ url });
|
||||
} catch (e) {
|
||||
res.status(500).json({ error: e.message });
|
||||
}
|
||||
});
|
||||
|
||||
// ================================================================
|
||||
// GET /api/images/:id/file-url — Retorna a URL de visualização
|
||||
// full-res de uma imagem (para o painel Original do modal)
|
||||
|
||||
Reference in New Issue
Block a user