'use client' import { JSX } from 'react' import { useWebRTCPeer } from './WebRTCProvider' import { useCallback, useState } from 'react' import { useMutation } from '@tanstack/react-query' import CancelButton from './CancelButton' export default function ReportTermsViolationButton({ uploaderPeerID, slug, }: { uploaderPeerID: string slug: string }): JSX.Element { const { peer } = useWebRTCPeer() const [showModal, setShowModal] = useState(false) const [isReporting, setIsReporting] = useState(false) const reportMutation = useMutation({ mutationFn: async () => { const response = await fetch(`/api/destroy`, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ slug }), }) if (!response.ok) { throw new Error('Failed to report violation') } return response.json() }, }) const handleReport = useCallback(() => { try { // Destroy the channel so no further downloads can be made. setIsReporting(true) reportMutation.mutate() // Send a report message to the uploader to hard-redirect them to the reported page. // The uploader will broadcast a report message to all connections, which will hard-redirect all downloaders to the reported page. const conn = peer.connect(uploaderPeerID, { metadata: { type: 'report' }, }) // Set a timeout to redirect after 2 seconds even if connection doesn't open const timeout = setTimeout(() => { conn.close() window.location.href = '/reported' }, 2000) conn.on('open', () => { clearTimeout(timeout) conn.close() window.location.href = '/reported' }) } catch (error) { console.error('Failed to report violation', error) setIsReporting(false) } }, [peer, uploaderPeerID]) return ( <>
{showModal && (
setShowModal(false)} >
e.stopPropagation()} >

Before reporting this delivery, please note our FilePizza terms:

  • Only upload files you have the right to share
  • 🔒 Share download links only with known recipients
  • ⚠️ No illegal or harmful content allowed

If you've spotted a violation of these terms, click Report to halt its delivery.

setShowModal(false)} />
)} ) }