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:
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user