fix(thumbnail): corrige 500 em RX sem thumb — fallback Wasabi legado
continuous-integration/webhook Deploy concluído (VPS4)
continuous-integration/webhook Deploy concluído (VPS4)
Causa raiz: request-presigned-urls usava firstName/lastName para montar o patientName do caminho no Wasabi, mas o client envia apenas name. Resultado: toda imagem era salva em '.../Desconhecido/arquivo.png' no Wasabi, mas o banco guardava o nome real do paciente — na recuperação, a key ficava diferente e resultava em NoSuchKey → 500. Correções: 1. server.js: getImageBufferWithFallback() — tenta o path correto (nome real) e, se falhar, tenta o path legado 'Desconhecido'. Usado tanto para ler thumb existente quanto para gerar do original. 2. server.js: patientName corrigido em send-image e request-presigned-urls para usar data.patientData.name (o campo que o client realmente envia), garantindo consistência entre Wasabi e banco em novos uploads. 3. routes/images.js: runThumbBackfill agora usa storage.getImageBuffer com fallback 'Desconhecido' em vez de leitura apenas do disco local — o boot backfill passa a funcionar para imagens no Wasabi. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -540,23 +540,32 @@ router.post('/backfill-thumbs', async (req, res) => {
|
||||
});
|
||||
|
||||
async function runThumbBackfill(rows) {
|
||||
const UPLOAD_DIR = process.env.UPLOAD_DIR || path.join(__dirname, '..', '..', 'uploads');
|
||||
const PROCESSED_DIR = process.env.PROCESSED_DIR || path.join(__dirname, '..', '..', 'processed');
|
||||
let done = 0, failed = 0;
|
||||
for (const row of rows) {
|
||||
try {
|
||||
// Tenta carregar a imagem do disco local
|
||||
// Busca a original via storage (disco local → Wasabi com path correto → fallback 'Desconhecido')
|
||||
let imgBuffer = null;
|
||||
for (const dir of [UPLOAD_DIR, PROCESSED_DIR]) {
|
||||
try { imgBuffer = await fs.readFile(path.join(dir, row.filename)); break; } catch (_) {}
|
||||
try {
|
||||
imgBuffer = await storage.getImageBuffer(row.filename, row.clinic_name, row.client_name, row.patient_name);
|
||||
} catch (_) {}
|
||||
|
||||
// Fallback legado: uploads antigos foram gravados com patientName='Desconhecido' no Wasabi
|
||||
if (!imgBuffer && row.patient_name !== 'Desconhecido') {
|
||||
try {
|
||||
imgBuffer = await storage.getImageBuffer(row.filename, row.clinic_name, row.client_name, 'Desconhecido');
|
||||
} catch (_) {}
|
||||
}
|
||||
|
||||
if (!imgBuffer) { failed++; continue; }
|
||||
|
||||
const thumbBuffer = await imageProcessor.getThumbnail(imgBuffer);
|
||||
const thumbFilename = `thumb_${row.filename.replace(/\.[^.]+$/, '')}.jpg`;
|
||||
await storage.saveImage(thumbFilename, thumbBuffer, row.clinic_name, row.client_name, row.patient_name, false);
|
||||
await db.run('UPDATE images SET thumb_filename = $1 WHERE id = $2', [thumbFilename, row.id]);
|
||||
done++;
|
||||
console.log(`[backfill-thumbs] ✅ id ${row.id}: ${thumbFilename}`);
|
||||
} catch (e) {
|
||||
console.error(`[backfill-thumbs] ❌ id ${row.id}:`, e.message);
|
||||
failed++;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user