fix: the video dialog marks the products that already have a published video (DTF-WEB-G, DTF-WEB-H)
All checks were successful
Build and deploy / Validate source (push) Successful in 11s
Build and deploy / Integration suite on a real stack (push) Successful in 7m20s
Build and deploy / Secret scan and release gate (push) Successful in 10s
Build and deploy / Publish images (push) Successful in 1m40s
All checks were successful
Build and deploy / Validate source (push) Successful in 11s
Build and deploy / Integration suite on a real stack (push) Successful in 7m20s
Build and deploy / Secret scan and release gate (push) Successful in 10s
Build and deploy / Publish images (push) Successful in 1m40s
"Onde aparece" names the products another published video holds and closes them while this one is published; turning Publicar on over a taken product stays off and says which video holds it. The server checks before copying any file and its refusal names that video too. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -97,6 +97,14 @@ def update_video(video_id: str, body: VideoUpdate, user=Depends(can('manage'))):
|
||||
with db.connect() as c:
|
||||
previous = c.execute('SELECT upload_id,captions_id,video_key,captions_key FROM dtf_local.site_videos WHERE id=%s FOR UPDATE',
|
||||
(video_id,)).fetchone() or {}
|
||||
# One floating video per product page; checked before any copy, and
|
||||
# the refusal names the video that holds the product (DTF-WEB-G).
|
||||
if body.enabled and body.product:
|
||||
other = c.execute('SELECT id FROM dtf_local.site_videos WHERE id<>%s AND product=%s AND enabled',
|
||||
(video_id, body.product)).fetchone()
|
||||
if other:
|
||||
raise HTTPException(409, f'Este produto já tem o vídeo "{CATALOG.get(other["id"], other["id"])}" '
|
||||
'publicado. Tire esse do Site antes, ou escolha outro lugar.')
|
||||
identity = operator_identity(user)
|
||||
keys = []
|
||||
for uid, expected, previous_id, previous_key in (
|
||||
@@ -113,11 +121,6 @@ def update_video(video_id: str, body: VideoUpdate, user=Depends(can('manage'))):
|
||||
CopySource={'Bucket': storage.bucket, 'Key': upload['object_key']},
|
||||
Key=key, ContentType=mime, MetadataDirective='REPLACE')
|
||||
keys.append(key)
|
||||
if body.enabled and body.product:
|
||||
other = c.execute('SELECT id FROM dtf_local.site_videos WHERE id<>%s AND product=%s AND enabled',
|
||||
(video_id, body.product)).fetchone()
|
||||
if other:
|
||||
raise HTTPException(409, 'Já existe um vídeo flutuante ativo para este produto.')
|
||||
c.execute('''INSERT INTO dtf_local.site_videos(id,upload_id,captions_id,video_key,captions_key,product,enabled,updated_by)
|
||||
VALUES(%s,%s,%s,%s,%s,%s,%s,%s)
|
||||
ON CONFLICT (id) DO UPDATE SET upload_id=EXCLUDED.upload_id,captions_id=EXCLUDED.captions_id,
|
||||
|
||||
@@ -48,6 +48,13 @@ def run():
|
||||
entry = next(row for row in published if row['id'] == 'sala')
|
||||
assert entry['product'] == 'file'
|
||||
assert entry['captions'] == '/api/site/videos/sala/captions'
|
||||
# One floating video per product: a second one is refused before any
|
||||
# copy, naming the video that holds the product (DTF-WEB-G).
|
||||
refused = operator.call('/operator/site-videos/png', {'upload_id': video,
|
||||
'product': 'file', 'enabled': True}, expected=409)
|
||||
assert 'A sala às 3 da manhã' in refused['detail'], refused
|
||||
with db.connect() as c:
|
||||
assert not c.execute("SELECT 1 FROM dtf_local.site_videos WHERE id='png'").fetchone()
|
||||
with urlopen(entry['src'], timeout=30) as response:
|
||||
assert response.read() == VIDEO
|
||||
with urlopen(Request(BASE + entry['captions'], headers=with_host()), timeout=30) as response:
|
||||
|
||||
@@ -582,18 +582,37 @@ 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.'));
|
||||
// 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)
|
||||
.map(other=>[other.product,other.title]));
|
||||
const product=node('select');
|
||||
for(const [value,label] of SITE_VIDEO_PRODUCTS){
|
||||
const option=node('option',label);option.value=value;product.append(option);
|
||||
const option=node('option',taken.has(value)?label+' · já tem vídeo':label);option.value=value;product.append(option);
|
||||
}
|
||||
product.value=video.product||'';
|
||||
const where=field('Onde aparece',product,'Ou flutuando na página de um produto.');
|
||||
const whereHint=where.querySelector('small');
|
||||
const paintWhere=()=>{
|
||||
for(const option of product.options)option.disabled=published&&taken.has(option.value);
|
||||
if(!taken.has(product.value))where.classList.remove('warn');
|
||||
whereHint.textContent=taken.has(product.value)
|
||||
?'Este produto já tem o vídeo "'+taken.get(product.value)+'" publicado. Tire esse do Site para publicar este aqui.'
|
||||
:'Ou flutuando na página de um produto.';
|
||||
};
|
||||
product.onchange=paintWhere;
|
||||
const sw=node('button',undefined,'sw'+(published?' on':''));
|
||||
sw.type='button';sw.setAttribute('role','switch');sw.setAttribute('aria-checked',String(published));
|
||||
sw.append(node('span',undefined,'t'),'Publicar no Site');
|
||||
sw.onclick=()=>{published=!published;sw.classList.toggle('on',published);sw.setAttribute('aria-checked',String(published));};
|
||||
sw.onclick=()=>{
|
||||
if(!published&&taken.has(product.value)){where.classList.add('warn');product.focus();return;}
|
||||
published=!published;sw.classList.toggle('on',published);sw.setAttribute('aria-checked',String(published));
|
||||
paintWhere();
|
||||
};
|
||||
const situation=node('div',undefined,'fld');situation.append(node('span','Situação'),sw);
|
||||
const row=node('div',undefined,'g2');
|
||||
row.append(field('Onde aparece',product,'Ou flutuando na página de um produto.'),situation);
|
||||
row.append(where,situation);
|
||||
paintWhere();
|
||||
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()=>{
|
||||
|
||||
Reference in New Issue
Block a user