mirror of
https://github.com/fsolla/teqo.git
synced 2026-11-16 20:13:04 +00:00
Envio em lote (1 request raw-body por arquivo, fan-out ≤2, até 50 arquivos) e adicionar por link (Instagram/YouTube; extração só pela Graph API da conta própria, senão peça-link) em /campanha/comunicacao/conteudos. Cada peça tem estado próprio (Processando/Pronto/Falhou + Reprocessar), transcrição/texto e catalogação automática revisável; publicar/despublicar preserva arquivo, slug e publishedAt. - collections contentPiece + contentMedia (upload privado no S3) e migration 20260923_032714_add_content_piece (slug único gerado no 1º publish, sourceUrl única, searchText com índice trigram) - pipeline reusa C199 (job after() + reaper + retry condicional, transcrição DeepInfra, ffmpeg/chunk), o classificador de facetas do acervo e o institutionCatalog; curatedFields impede o job de sobrescrever curadoria - gate único canReadCommunicationCatalog (advisor/leader negados); delete só pelo admin; sem Consent novo - UI portada do design aprovado (lista desktop + cards mobile, diálogo de lote com progresso por arquivo, diálogo de link, ficha editável, kill switch); nav/chrome/column-picker/manifest atualizados - instagramFeed expõe mediaUrl; revalidateTag ganha wrapper seguro fora de request (fixtures/scripts) - testes: 2 unit specs, 1 int spec (16 casos) e 7 e2e na vertical - follow-up de engenharia: #1267 (docs/plans/escala-dry-pos-c211.md) Closes #1254
62 lines
2.1 KiB
TypeScript
62 lines
2.1 KiB
TypeScript
'use client'
|
|
|
|
import { useRouter } from 'next/navigation'
|
|
import { useEffect } from 'react'
|
|
|
|
import type { ContentPieceStatusResponse } from '@/app/(campaign)/campanha/(app)/comunicacao/conteudos/types'
|
|
import { postCampaignJson } from '@/lib/campaignJsonRequest'
|
|
import { CAMPAIGN_CONTENT_PIECE_STATUS_HREF } from '@/lib/campaignPaths'
|
|
|
|
/**
|
|
* C211 — keeps the honest processing states moving without a full reload: while
|
|
* a visible piece is `processando`, polls the status route and refreshes the
|
|
* server tree when any state changed. Silent on failure — the next tick
|
|
* retries; pauses on a hidden tab.
|
|
*/
|
|
export const ContentPieceStatusRefresher = ({
|
|
pieces,
|
|
intervalMs = 5_000,
|
|
}: {
|
|
pieces: readonly { id: number; processingStatus: string }[]
|
|
intervalMs?: number
|
|
}) => {
|
|
const router = useRouter()
|
|
const pending = pieces.some((piece) => piece.processingStatus === 'processando')
|
|
const signature = pieces
|
|
.map((piece) => `${piece.id}:${piece.processingStatus}`)
|
|
.sort()
|
|
.join(',')
|
|
|
|
useEffect(() => {
|
|
// Terminal states never poll: the timer only exists while something moves.
|
|
if (!signature || !pending) return
|
|
const ids = signature.split(',').map((entry) => Number(entry.split(':')[0]))
|
|
let stopped = false
|
|
|
|
const tick = async () => {
|
|
if (stopped || document.visibilityState === 'hidden') return
|
|
try {
|
|
const { ok, payload } = await postCampaignJson<ContentPieceStatusResponse>(
|
|
CAMPAIGN_CONTENT_PIECE_STATUS_HREF,
|
|
{ contentPieceIds: ids },
|
|
)
|
|
if (stopped || !ok || payload.status !== 'success') return
|
|
const nextSignature = payload.pieces
|
|
.map((piece) => `${piece.id}:${piece.processingStatus}`)
|
|
.sort()
|
|
.join(',')
|
|
if (nextSignature !== signature) router.refresh()
|
|
} catch {
|
|
// A failed poll is a lost tick, never a user-facing error.
|
|
}
|
|
}
|
|
|
|
const timer = window.setInterval(() => void tick(), intervalMs)
|
|
return () => {
|
|
stopped = true
|
|
window.clearInterval(timer)
|
|
}
|
|
}, [signature, pending, intervalMs, router])
|
|
|
|
return null
|
|
}
|