diff --git a/web/kanban-site.js b/web/kanban-site.js index 04d05a9..98e1fde 100644 --- a/web/kanban-site.js +++ b/web/kanban-site.js @@ -570,6 +570,23 @@ function siteVideoRow(video){ tr.append(title,file,captions,where,situation,action); return tr; } +// The server's own limits (app/api/site_videos.py _kind), checked in the dialog +// so a wrong file, also a dropped one, is named before any upload (DTF-WEB-J). +const SITE_VIDEO_FILES={ + video:{ext:['.mp4','.webm'],max:500*1024*1024,rule:'O vídeo precisa ser MP4 ou WebM de até 500 MB.'}, + captions:{ext:['.vtt'],max:1024*1024,rule:'A legenda precisa ser um arquivo VTT de até 1 MB.'}}; +function siteVideoFileOk(file,kind){ + const {ext,max}=SITE_VIDEO_FILES[kind]; + return ext.some(end=>file.name.toLowerCase().endsWith(end))&&file.size<=max; +} +// Shows under the field whether the chosen file can be sent; true when it can. +function siteVideoFileCheck(input,fieldBox,kind,current){ + const file=input.files[0],small=fieldBox.querySelector(':scope > small'); + const ok=!file||siteVideoFileOk(file,kind); + fieldBox.classList.toggle('warn',!ok); + small.textContent=ok?current:'"'+file.name+'" não pode ser enviado. '+SITE_VIDEO_FILES[kind].rule; + return ok; +} function videoDialog(video){ let published=!!video.enabled; const videoInput=node('input');videoInput.type='file';videoInput.accept='.mp4,.webm,video/mp4,video/webm'; @@ -582,6 +599,10 @@ function videoDialog(video){ captionsField.append(node('span',video.captions_name?'Legenda':'Legenda · opcional'), dropField(captionsInput,{title:'Escolher legenda',hint:'Arquivo VTT.'}), node('small',video.captions_name||'Nenhuma legenda enviada.')); + const checkVideo=()=>siteVideoFileCheck(videoInput,videoField,'video',video.video_name||'Nenhum arquivo enviado.'); + const checkCaptions=()=>siteVideoFileCheck(captionsInput,captionsField,'captions',video.captions_name||'Nenhuma legenda enviada.'); + videoInput.addEventListener('change',checkVideo); + captionsInput.addEventListener('change',checkCaptions); // A product page shows one floating video: the products another published // video holds are marked, and closed while this one is published (DTF-WEB-G). const taken=new Map(siteVideos.filter(other=>other.id!==video.id&&other.enabled&&other.product) @@ -616,6 +637,8 @@ function videoDialog(video){ formDialog(video.title,{width:640,className:'siteDialog', text:video.enabled?'Publicado no Site':'Rascunho · ainda não aparece no Site', fields:[videoField,captionsField,row],label:'Salvar vídeo',onsave:async()=>{ + const videoOk=checkVideo(),captionsOk=checkCaptions(); + if(!videoOk||!captionsOk){(videoOk?captionsField:videoField).scrollIntoView({block:'center'});return false;} let uploadId=video.upload_id,captionsId=video.captions_id; if(videoInput.files[0])uploadId=await dtfUpload(videoInput.files[0],{api,startPath:'/site-videos/uploads', scope:'site-video:'+video.id+':video',progress:text=>say(text)});