feat: a video on several products, sound and expand on the floating player, upright vertical video, looping cards at the foot of the home (Rodada 5, D7)

site_videos.products (the old product column is kept and copied); one
floating video per product checks the overlap and names it. The floating
player starts muted, with a sound button that says its state and an
expand button to the large player. A vertical video stands upright on
the floating and the large player. The home's videos move to its foot as
muted looping cards that play only on screen, not at all with reduced
motion, and open the large player.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Cauê Faleiros
2026-11-30 16:03:51 -03:00
parent 22239f21d8
commit 21858b5764
7 changed files with 218 additions and 69 deletions

View File

@@ -24,15 +24,32 @@ CATALOG = {
}
VIDEO_MAX = 500 * 1024 * 1024
CAPTIONS_MAX = 1024 * 1024
PRODUCTS = ('file', 'avulsa', 'uvfile', 'uv')
PRODUCT_NAMES = {
'file': 'Arquivo por metro',
'avulsa': 'Artes avulsas',
'uvfile': 'Arquivo por metro · UV',
'uv': 'Artes avulsas · UV',
}
class VideoUpdate(StrictModel):
upload_id: UUID | None = None
captions_id: UUID | None = None
product: Literal['file', 'avulsa', 'uvfile', 'uv'] | None = None
products: list[Literal['file', 'avulsa', 'uvfile', 'uv']] = Field(default_factory=list, max_length=4)
enabled: bool = False
def _products(body):
"""The chosen products, unique and in catalog order; the old single
`product` still works and means one product."""
chosen = set(body.products)
if not chosen and body.product:
chosen.add(body.product)
return [product for product in PRODUCTS if product in chosen]
class VideoUploadStart(StrictModel):
name: str = Field(min_length=1, max_length=200, pattern=r'^[^/\\\x00-\x1f]+$')
size: int = Field(gt=0, strict=True)
@@ -78,14 +95,19 @@ def manage_videos(user=Depends(operator)):
FROM dtf_local.site_videos v
LEFT JOIN dtf_local.uploads u ON u.id=v.upload_id
LEFT JOIN dtf_local.uploads t ON t.id=v.captions_id''').fetchall()}
return {'videos': [dict(id=id, title=title,
product=rows[id]['product'] if id in rows else None,
upload_id=rows[id]['upload_id'] if id in rows else None,
captions_id=rows[id]['captions_id'] if id in rows else None,
video_name=rows[id]['video_name'] if id in rows else None,
captions_name=rows[id]['captions_name'] if id in rows else None,
enabled=rows[id]['enabled'] if id in rows else False)
for id, title in CATALOG.items()]}
videos = []
for id, title in CATALOG.items():
row = rows.get(id)
products = list(row['products'] or []) if row else []
videos.append(dict(id=id, title=title,
product=products[0] if products else None,
products=products,
upload_id=row['upload_id'] if row else None,
captions_id=row['captions_id'] if row else None,
video_name=row['video_name'] if row else None,
captions_name=row['captions_name'] if row else None,
enabled=row['enabled'] if row else False))
return {'videos': videos}
@router.post('/api/operator/site-videos/{video_id}')
@@ -94,17 +116,20 @@ def update_video(video_id: str, body: VideoUpdate, user=Depends(can('manage'))):
raise HTTPException(404, 'Vídeo não encontrado.')
if body.enabled and not body.upload_id:
raise HTTPException(422, 'Envie o vídeo antes de publicar.')
products = _products(body)
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()
# the refusal names the video and the product it holds (DTF-WEB-G).
if body.enabled and products:
other = c.execute('''SELECT id,products FROM dtf_local.site_videos
WHERE id<>%s AND enabled AND products && %s''', (video_id, products)).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.')
common = next(product for product in products if product in other['products'])
raise HTTPException(409, f'O produto "{PRODUCT_NAMES[common]}" já tem o vídeo '
f'"{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 (
@@ -121,12 +146,14 @@ 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)
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)
c.execute('''INSERT INTO dtf_local.site_videos(id,upload_id,captions_id,video_key,captions_key,product,products,enabled,updated_by)
VALUES(%s,%s,%s,%s,%s,%s,%s,%s,%s)
ON CONFLICT (id) DO UPDATE SET upload_id=EXCLUDED.upload_id,captions_id=EXCLUDED.captions_id,
video_key=EXCLUDED.video_key,captions_key=EXCLUDED.captions_key,
product=EXCLUDED.product,enabled=EXCLUDED.enabled,updated_by=EXCLUDED.updated_by,updated_at=now()''',
(video_id, body.upload_id, body.captions_id, keys[0], keys[1], body.product, body.enabled, user))
product=EXCLUDED.product,products=EXCLUDED.products,enabled=EXCLUDED.enabled,
updated_by=EXCLUDED.updated_by,updated_at=now()''',
(video_id, body.upload_id, body.captions_id, keys[0], keys[1],
products[0] if products else None, products, body.enabled, user))
ids = [uid for uid in (body.upload_id, body.captions_id) if uid]
if ids:
c.execute("UPDATE dtf_local.uploads SET expires_at=GREATEST(expires_at,now()+interval '30 days') WHERE id=ANY(%s)", (ids,))
@@ -137,14 +164,18 @@ def update_video(video_id: str, body: VideoUpdate, user=Depends(can('manage'))):
@router.get('/api/site/videos')
def published_videos():
with db.connect() as c:
rows = c.execute('''SELECT v.id,v.product,v.video_key,v.captions_key,u.name AS video_name
rows = c.execute('''SELECT v.id,v.products,v.video_key,v.captions_key,u.name AS video_name
FROM dtf_local.site_videos v
JOIN dtf_local.uploads u ON u.id=v.upload_id
WHERE v.enabled AND v.video_key IS NOT NULL''').fetchall()
return {'videos': [dict(id=row['id'], product=row['product'],
src=storage.view(row['video_key'], _kind({'name':row['video_name'],'size':0})[0]),
captions=f"/api/site/videos/{row['id']}/captions" if row['captions_key'] else None)
for row in rows]}
videos = []
for row in rows:
products = list(row['products'] or [])
videos.append(dict(id=row['id'], product=products[0] if products else None,
products=products,
src=storage.view(row['video_key'], _kind({'name':row['video_name'],'size':0})[0]),
captions=f"/api/site/videos/{row['id']}/captions" if row['captions_key'] else None))
return {'videos': videos}
@router.get('/api/site/videos/{video_id}/captions')

View File

@@ -0,0 +1,8 @@
-- Round 5, D7: the same video can appear on more than one product page. The
-- old single `product` column stays for compatibility; the code reads
-- `products`. One floating video per product is still enforced in the API.
ALTER TABLE dtf_local.site_videos ADD COLUMN IF NOT EXISTS products text[] NOT NULL DEFAULT '{}';
UPDATE dtf_local.site_videos SET products=ARRAY[product] WHERE product IS NOT NULL AND products='{}';
ALTER TABLE dtf_local.site_videos DROP CONSTRAINT IF EXISTS site_videos_products_check;
ALTER TABLE dtf_local.site_videos ADD CONSTRAINT site_videos_products_check
CHECK (products <@ ARRAY['file','avulsa','uvfile','uv']::text[]);