fix: the review photo is measured before sending, and a drag to Finalizado without it opens Revisão

Sentry DTF-WEB-C and DTF-WEB-B (order #24, 16/11): a review photo under
1600 px on its longer side was refused only after the upload (a 1280x720
webcam always is), and dragging the card to Finalizado without the photo
got the server's 409. The dialog now says the minimum, the camera shot
and a chosen photo are measured in the browser with the same message,
and the drop opens Revisão instead of a refused move.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Cauê Faleiros
2026-11-16 10:37:44 -03:00
parent d6c80ff447
commit 92ffb679d6
2 changed files with 30 additions and 4 deletions

View File

@@ -266,6 +266,13 @@ function renderBoard(){
const order=board.orders.find(o=>o.id===e.dataTransfer.getData('text/plain'));
const machine=state==='imp'?laneAt(column,e.clientY):null;markLane(column,null);
if(!order)return;
// Above 1 m Finalizado needs the review photo: the drop opens Revisão
// instead of a refused move (Sentry DTF-WEB-B).
if(state==='fin'&&order.state==='rev'&&needsReviewPhoto(order)){
if(may('inspect')){say('Pedido acima de 1 m: tire a foto da revisão antes de finalizar.');reviewDialog(order);}
else say('Pedido acima de 1 m: falta a foto da revisão antes de finalizar.',true);
clearDrop();return;
}
try{
if(order.state!==state)await (state==='imp'?pullTo(order,machine):move(order,state,'',machine));
else if(state!=='fin')await reorder(order,column,e.clientY);

View File

@@ -374,8 +374,7 @@ function nextBox(order){
}else{
// Above 1 m the photo is required to finish (app/reviews.py): the main
// button takes it instead of releasing the order.
const hasPhoto=(order.reviews||[]).some(review=>review.kind==='photo');
if(!order.proof_parent&&orderMetres(order)>1&&!hasPhoto){
if(needsReviewPhoto(order)){
title='Tire a foto da revisão';
note('Pedido acima de 1 m: tire a foto da revisão antes de finalizar.');
if(may('inspect'))main.push(button('Revisar',()=>reviewDialog(order),'btn pri lg'));else cannot();
@@ -595,6 +594,18 @@ function cardOpenAction(order){
// recorded. The server names it DTF-<n>-revisao-<seq> and keeps it 180 days.
const REVIEW_VIDEO_MAX=30;
const reviewClock=s=>Math.floor(s/60)+':'+String(s%60).padStart(2,'0');
// Above 1 m the order finishes only with a review photo (app/reviews.py), of
// at least REVIEW_PHOTO_MIN px on its longer side so the footer can be read.
const REVIEW_PHOTO_MIN=1600;
const needsReviewPhoto=order=>!order.proof_parent&&orderMetres(order)>1&&
!(order.reviews||[]).some(review=>review.kind==='photo');
const smallPhoto=(width,height)=>'A foto tem '+width+'×'+height+' px; a revisão precisa de pelo menos '+
REVIEW_PHOTO_MIN+' px no lado maior para ler o rodapé.';
// The photo's size, read in the browser before the upload (Sentry DTF-WEB-C).
async function photoSize(file){
try{const bitmap=await createImageBitmap(file);const size=[bitmap.width,bitmap.height];bitmap.close?.();return size;}
catch(_){return null;}
}
function reviewDialog(order){
const host=dialogHost();
const video=node('video');video.className='reviewcam';video.muted=true;video.playsInline=true;video.autoplay=true;
@@ -659,6 +670,8 @@ function reviewDialog(order){
clear();
const width=video.videoWidth,height=video.videoHeight;
if(!width||!height){fail('A câmera ainda não está pronta. Espere um instante.');return;}
if(Math.max(width,height)<REVIEW_PHOTO_MIN){
fail(smallPhoto(width,height)+' Esta câmera não chega a isso: grave um vídeo, use o celular ou envie um arquivo.');return;}
const canvas=document.createElement('canvas');canvas.width=width;canvas.height=height;
canvas.getContext('2d').drawImage(video,0,0,width,height);
canvas.toBlob(blob=>{
@@ -704,7 +717,12 @@ function reviewDialog(order){
try{await checkDuration(file);}catch(error){input.value='';fail(error.message);return;}
if(closed)return;
showReady(file,'video');
}else showReady(file,'photo');
}else{
const size=await photoSize(file);
if(closed)return;
if(size&&Math.max(...size)<REVIEW_PHOTO_MIN){input.value='';fail(smallPhoto(size[0],size[1]));return;}
showReady(file,'photo');
}
};
fileLabel.onkeydown=event=>{if(event.key==='Enter'||event.key===' '){event.preventDefault();input.click();}};
cancel.onclick=()=>m.close();
@@ -725,7 +743,8 @@ function reviewDialog(order){
}
};
const m=modal('Revisão do #'+order.number,{host,width:640,
text:'Tire uma foto ou grave um vídeo de até 30 s da folha impressa, ou envie um arquivo.',
text:'Tire uma foto ou grave um vídeo de até 30 s da folha impressa, ou envie um arquivo. '+
'A foto precisa de pelo menos '+REVIEW_PHOTO_MIN+' px no lado maior.',
body:[video,controls,timer,preview],foot:[status,cancel,save],onclose:cleanup});
(async()=>{
try{