mirror of
https://github.com/fsolla/teqo.git
synced 2026-11-13 23:53:05 +00:00
Collections speech/speechSegment no grupo Comunicação, papel communicator (leitura restrita) e índice trigram normalizado para a busca por segmento. Import idempotente da Câmara (discurso→evento→trecho→VOD→ASR) com facetas gazetteer+LLM, proveniência e preservação de curadoria manual; parser de quem presidia; reusa a lógica pura do piloto C152 via scripts/lib. Related #955
63 lines
1.9 KiB
TypeScript
63 lines
1.9 KiB
TypeScript
import type { CampaignUser, Media } from '@/payload-types'
|
|
|
|
const CAMPAIGN_AVATAR_MAX_BYTES = 2 * 1024 * 1024
|
|
|
|
const CAMPAIGN_AVATAR_UNSUPPORTED_MIME_MESSAGE = 'Envie uma imagem JPEG, PNG ou WebP.'
|
|
const CAMPAIGN_AVATAR_MAX_SIZE_MESSAGE = 'A imagem deve ter no máximo 2 MB.'
|
|
const CAMPAIGN_AVATAR_EMPTY_FILE_MESSAGE = 'O arquivo enviado está vazio.'
|
|
|
|
export const campaignRoleLabels: Record<CampaignUser['role'], string> = {
|
|
coordinator: 'Coordenador Geral',
|
|
advisor: 'Assessor',
|
|
candidate: 'Candidato',
|
|
communicator: 'Assessor de Comunicação',
|
|
leader: 'Liderança',
|
|
}
|
|
|
|
export type CampaignUserShellView = {
|
|
name: string
|
|
role: CampaignUser['role']
|
|
avatarUrl: string | null
|
|
}
|
|
|
|
export const campaignUserShellView = (
|
|
user: Pick<CampaignUser, 'name' | 'role' | 'avatar'>,
|
|
): CampaignUserShellView => ({
|
|
name: user.name,
|
|
role: user.role,
|
|
avatarUrl: mediaDocumentUrl(user.avatar),
|
|
})
|
|
|
|
const CAMPAIGN_AVATAR_MIME_TYPES = new Set(['image/jpeg', 'image/png', 'image/webp'])
|
|
|
|
export const campaignUserInitials = (name: string): string => {
|
|
const parts = name.trim().split(/\s+/).filter(Boolean).slice(0, 2)
|
|
|
|
if (parts.length === 0) return '?'
|
|
|
|
return parts.map((part) => part[0]?.toUpperCase() ?? '').join('')
|
|
}
|
|
|
|
export const mediaDocumentUrl = (media: number | Media | null | undefined): string | null => {
|
|
if (!media || typeof media === 'number') return null
|
|
|
|
return media.url ?? null
|
|
}
|
|
|
|
export const assertCampaignAvatarFile = (file: File): void => {
|
|
if (!CAMPAIGN_AVATAR_MIME_TYPES.has(file.type)) {
|
|
throw new Error(CAMPAIGN_AVATAR_UNSUPPORTED_MIME_MESSAGE)
|
|
}
|
|
if (file.size > CAMPAIGN_AVATAR_MAX_BYTES) {
|
|
throw new Error(CAMPAIGN_AVATAR_MAX_SIZE_MESSAGE)
|
|
}
|
|
if (file.size === 0) {
|
|
throw new Error(CAMPAIGN_AVATAR_EMPTY_FILE_MESSAGE)
|
|
}
|
|
}
|
|
|
|
export const CAMPAIGN_AVATAR_SAFE_ERROR_MESSAGES = [
|
|
CAMPAIGN_AVATAR_UNSUPPORTED_MIME_MESSAGE,
|
|
CAMPAIGN_AVATAR_MAX_SIZE_MESSAGE,
|
|
CAMPAIGN_AVATAR_EMPTY_FILE_MESSAGE,
|
|
] as const
|