fix: serve Wasabi image URLs instead of local /uploads/ paths — prevent broken image links
continuous-integration/webhook Deploy concluído (VPS4)

This commit is contained in:
VPS 4 Deploy Agent
2026-05-30 17:22:11 +02:00
parent cf653558c4
commit b76bb14b0a
10 changed files with 162 additions and 6 deletions
+27
View File
@@ -105,6 +105,32 @@ function sanitizePathSegment(segment) {
return segment.trim().replace(/[\/\\?#%*:"<>|]/g, '_');
}
/**
* Retorna a URL assinada de uma imagem no Wasabi (ou null se não estiver lá ou Wasabi desativado)
*/
async function getImageUrl(filename, clientName, patientName, isProcessed = false, expirySeconds = 3600) {
if (!s3 || !currentBucket || !clientName || !patientName) {
return null;
}
try {
const cleanClient = sanitizePathSegment(clientName);
const cleanPatient = sanitizePathSegment(patientName);
const key = `${cleanClient}/${cleanPatient}/${filename}`;
// Gerar URL assinada com expiração (padrão: 1 hora)
const url = await getSignedUrl(
s3,
new GetObjectCommand({ Bucket: currentBucket, Key: key }),
{ expiresIn: expirySeconds }
);
return url;
} catch (error) {
console.error(`⚠️ [Wasabi] Erro ao gerar URL assinada para ${filename}:`, error.message);
return null;
}
}
/**
* Salva a imagem. Primeiro no disco local e depois, se o Wasabi estiver ativo, faz o upload.
* Remove a versão local temporária se o upload pro Wasabi der certo.
@@ -335,6 +361,7 @@ module.exports = {
loadConfigFromDb,
saveImage,
getImageBuffer,
getImageUrl,
deleteImage,
getDownloadPresignedUrl,
getUploadPresignedUrl,