import { useEffect, useRef, useState } from 'react' import api from '../lib/api' import { Upload, Trash2, ImageIcon, Info } from 'lucide-react' export default function Settings() { const [hasImage, setHasImage] = useState(false) const [imageUrl, setImageUrl] = useState('') const [uploading, setUploading] = useState(false) const [dragging, setDragging] = useState(false) const fileRef = useRef(null) const checkImage = async () => { try { const token = localStorage.getItem('token') const res = await fetch('/api/admin/settings/blocked-image', { headers: { Authorization: `Bearer ${token}` }, }) if (res.ok) { setHasImage(true) // Use the static file URL (no auth needed) for the tag setImageUrl('/panel/blocked_image.jpg?t=' + Date.now()) } else { setHasImage(false) setImageUrl('') } } catch { setHasImage(false) } } useEffect(() => { checkImage() }, []) const upload = async (file: File) => { if (!file.type.startsWith('image/')) { alert('Solo se permiten imágenes (JPEG, PNG, WebP, GIF)') return } setUploading(true) try { const form = new FormData() form.append('file', file) await api.post('/settings/blocked-image', form, { headers: { 'Content-Type': 'multipart/form-data' }, }) await checkImage() } catch (e: any) { alert('Error al subir la imagen: ' + (e.response?.data?.detail || e.message)) } finally { setUploading(false) } } const handleFileChange = (e: React.ChangeEvent) => { const file = e.target.files?.[0] if (file) upload(file) e.target.value = '' } const handleDrop = (e: React.DragEvent) => { e.preventDefault() setDragging(false) const file = e.dataTransfer.files[0] if (file) upload(file) } const deleteImage = async () => { if (!confirm('¿Eliminar la imagen de bloqueo?')) return await api.delete('/settings/blocked-image') setHasImage(false) setImageUrl('') } return (

Ajustes

{/* Blocked image section */}

Imagen de conexión bloqueada

Esta imagen se mostrará como canal de vídeo cuando un usuario intente reproducir en un segundo dispositivo habiendo alcanzado su límite de conexiones simultáneas.

El zapping normal (cambiar de canal en el mismo dispositivo) sigue funcionando sin interrupciones. La imagen solo aparece cuando se conecta un segundo dispositivo diferente con la misma cuenta.
{/* Upload area */}
{ e.preventDefault(); setDragging(true) }} onDragLeave={() => setDragging(false)} onDrop={handleDrop} onClick={() => !uploading && fileRef.current?.click()} className={` relative border-2 border-dashed rounded-xl cursor-pointer transition-colors ${dragging ? 'border-primary-400 bg-primary-500/10' : 'border-dark-600 hover:border-dark-500'} `} > {hasImage && imageUrl ? (
Blocked image
Haz clic para cambiar
) : (

Arrastra una imagen o haz clic para subir

JPEG, PNG, WebP o GIF · máx. 10 MB

)} {uploading && (
Subiendo...
)}
{hasImage && (
)}
) }