mirror of
https://github.com/fsolla/teqo.git
synced 2026-11-19 08:03:06 +00:00
Board "Acompanhe de perto" (S1+S2) ganha o feed automático do perfil oficial: loader irmão src/utilities/socialFeed/instagramFeed.ts (Graph API /media com children p/ carrossel + username, unstable_cache tag social-feed + revalidate 300, snapshot cru pré-exclusão persistido via SQL direto, refresh de token automático com retry 1x — refresh endpoint só renova tokens de Instagram Login, page tokens caem no fail-closed), global SocialFeedSettings estendida (instagramEnabled/AccessToken/UserId/MaxItems + snapshot hidden; excludedItems já cobria a plataforma desde a S2). Requisito nº 1 — picker de exclusão no admin (primeiro componente custom do repo, campo ui + importmap): lista os posts do snapshot com thumbnail e toggle "Não exibir" que escreve em excludedItems. Card com coverAspect square (1:1 do rascunho), badge Instagram, título = legenda com fallback para post sem legenda, clique no permalink (noopener), link "Seguir no Instagram →" derivado do username. Os feeds externos mudam para o subfolder socialFeed/ (pin da S2 previa). Migration 20260818_192948_add_instagram_social_feed_fields (não destrutiva). Stub IG no webServer (porta dev+2000, helper socialStub.ts) + 3 e2e novos no describe serial + kill switch estendido + smoke do picker no admin. Closes #20
189 lines
5.2 KiB
TypeScript
189 lines
5.2 KiB
TypeScript
import { payloadAdminOnly } from '@/utilities/campaignAccess'
|
|
import { REVALIDATE_SOCIAL_FEED_TAG } from '@/utilities/revalidateRequest'
|
|
import { revalidateTag } from 'next/cache'
|
|
import type { GlobalConfig } from 'payload'
|
|
|
|
const slug = 'social-feed-settings'
|
|
|
|
const YOUTUBE_VIDEO_ID_PATTERN = /^[A-Za-z0-9_-]{11}$/
|
|
|
|
const revalidateFeed = async () => revalidateTag(REVALIDATE_SOCIAL_FEED_TAG)
|
|
|
|
/**
|
|
* Configuration of the campaign home content board's external feeds (plano-site
|
|
* §4.2): YouTube now, Instagram in S3. The board's read path is the public home
|
|
* render, so the global's `read` is admin-only — the YouTube API key and the
|
|
* excluded-item list never leak through the REST API (the public render reads
|
|
* via the Local API, which bypasses access control by design).
|
|
*/
|
|
export const SocialFeedSettings: GlobalConfig = {
|
|
slug,
|
|
label: 'Feed de redes sociais',
|
|
admin: {
|
|
group: 'Configurações',
|
|
description:
|
|
'Fonte automática do board "Acompanhe de perto" da home de campanha. Sem chave configurada, os cards da plataforma não aparecem.',
|
|
},
|
|
access: {
|
|
read: payloadAdminOnly,
|
|
update: payloadAdminOnly,
|
|
},
|
|
hooks: {
|
|
afterChange: [revalidateFeed],
|
|
},
|
|
fields: [
|
|
{
|
|
name: 'enabled',
|
|
type: 'checkbox',
|
|
label: 'Feed ativo',
|
|
defaultValue: true,
|
|
admin: {
|
|
description:
|
|
'Desligado, as fontes externas (YouTube, Instagram) somem do board sem mexer nos artigos do site.',
|
|
},
|
|
},
|
|
{
|
|
name: 'youtubeEnabled',
|
|
type: 'checkbox',
|
|
label: 'YouTube ativo',
|
|
defaultValue: true,
|
|
admin: {
|
|
description: 'Desliga só os cards de vídeo do YouTube.',
|
|
},
|
|
},
|
|
{
|
|
name: 'youtubeApiKey',
|
|
type: 'text',
|
|
label: 'Chave da API (YouTube Data API v3)',
|
|
admin: {
|
|
description:
|
|
'Chave de API do Google Cloud com a YouTube Data API v3 habilitada. Restrinja por IP se possível.',
|
|
},
|
|
},
|
|
{
|
|
name: 'youtubeChannelId',
|
|
type: 'text',
|
|
label: 'ID do canal',
|
|
admin: {
|
|
description: 'Ex.: UCyqT2nMLnwQn2Bh7mB7y3dA (o canal oficial é @JorgeSollaDep).',
|
|
},
|
|
},
|
|
{
|
|
name: 'youtubeMaxItems',
|
|
type: 'number',
|
|
label: 'Máximo de vídeos',
|
|
defaultValue: 3,
|
|
min: 1,
|
|
max: 5,
|
|
admin: {
|
|
description: 'Quantos vídeos entram no bento (1 grande + os próximos).',
|
|
},
|
|
},
|
|
{
|
|
name: 'instagramEnabled',
|
|
type: 'checkbox',
|
|
label: 'Instagram ativo',
|
|
defaultValue: true,
|
|
admin: {
|
|
description: 'Desliga só os cards de post do Instagram.',
|
|
},
|
|
},
|
|
{
|
|
name: 'instagramAccessToken',
|
|
type: 'text',
|
|
label: 'Token de acesso (Instagram Graph API)',
|
|
admin: {
|
|
description:
|
|
'Token long-lived da conta Business/Creator vinculada à página do Facebook. Tokens emitidos via Instagram Login são renovados automaticamente; para page tokens, o refresh falha e o token precisa ser trocado aqui manualmente.',
|
|
},
|
|
},
|
|
{
|
|
name: 'instagramUserId',
|
|
type: 'text',
|
|
label: 'ID do usuário (conta Business/Creator)',
|
|
admin: {
|
|
description: 'ID numérico da conta de negócios do Instagram.',
|
|
},
|
|
},
|
|
{
|
|
name: 'instagramMaxItems',
|
|
type: 'number',
|
|
label: 'Máximo de posts',
|
|
defaultValue: 3,
|
|
min: 1,
|
|
max: 5,
|
|
admin: {
|
|
description: 'Quantos posts entram no bento (1 grande + os próximos).',
|
|
},
|
|
},
|
|
{
|
|
name: 'instagramExclusionPicker',
|
|
type: 'ui',
|
|
label: 'Instagram — posts recentes',
|
|
admin: {
|
|
components: {
|
|
Field: './components/admin/InstagramPostExclusionPicker#InstagramPostExclusionPicker',
|
|
},
|
|
},
|
|
},
|
|
{
|
|
name: 'excludedItems',
|
|
type: 'array',
|
|
label: 'Itens excluídos',
|
|
labels: {
|
|
singular: 'Item excluído',
|
|
plural: 'Itens excluídos',
|
|
},
|
|
admin: {
|
|
description:
|
|
'Conteúdo marcado para NÃO aparecer no board (vídeo errado, transmissão incompleta, post de grade). O board pula para o próximo elegível.',
|
|
},
|
|
fields: [
|
|
{
|
|
name: 'platform',
|
|
type: 'select',
|
|
label: 'Plataforma',
|
|
required: true,
|
|
options: [
|
|
{ label: 'YouTube', value: 'youtube' },
|
|
{ label: 'Instagram', value: 'instagram' },
|
|
],
|
|
},
|
|
{
|
|
name: 'itemId',
|
|
type: 'text',
|
|
label: 'ID do item',
|
|
required: true,
|
|
validate: (
|
|
value: string | null | undefined,
|
|
{ data }: { data: { platform?: string } },
|
|
) => {
|
|
if (data.platform === 'youtube' && value && !YOUTUBE_VIDEO_ID_PATTERN.test(value)) {
|
|
return 'Informe o ID do vídeo (11 caracteres)'
|
|
}
|
|
return true
|
|
},
|
|
},
|
|
{
|
|
name: 'reason',
|
|
type: 'text',
|
|
label: 'Motivo (opcional)',
|
|
},
|
|
],
|
|
},
|
|
{
|
|
name: 'youtubeFeedSnapshot',
|
|
type: 'json',
|
|
admin: {
|
|
hidden: true,
|
|
},
|
|
},
|
|
{
|
|
name: 'instagramFeedSnapshot',
|
|
type: 'json',
|
|
admin: {
|
|
hidden: true,
|
|
},
|
|
},
|
|
],
|
|
}
|