import React, { useState, useEffect } from 'react'; import { useTranslation } from 'react-i18next'; import { Shield, Eye, Lock, AlertTriangle, Info } from 'lucide-react'; import { Button, Card, Toggle, Select, Input, Textarea } from '../common'; import { settingsService } from '../../services/settings.service'; import { toast } from 'react-toastify'; interface ProtectionSettings { default_protection_level: 'basic' | 'standard' | 'enhanced' | 'maximum'; default_image_quality: number; enable_devtools_protection: boolean; max_image_requests_per_minute: number; suspicious_activity_threshold: number; enable_canvas_rendering: boolean; default_fragmentation_level: number; enable_overlay_protection: boolean; protection_warning_message: string; } export const ImageProtectionSettings: React.FC = () => { const { t } = useTranslation(); const [settings, setSettings] = useState({ default_protection_level: 'standard', default_image_quality: 85, enable_devtools_protection: true, max_image_requests_per_minute: 30, suspicious_activity_threshold: 10, enable_canvas_rendering: false, default_fragmentation_level: 3, enable_overlay_protection: true, protection_warning_message: 'Images in this gallery are protected from unauthorized download.' }); const [isLoading, setIsLoading] = useState(true); const [isSaving, setIsSaving] = useState(false); useEffect(() => { loadSettings(); }, []); const loadSettings = async () => { try { setIsLoading(true); const response = await settingsService.getSettings(); // Map settings from API response const protectionSettings: ProtectionSettings = { default_protection_level: response.default_protection_level || 'standard', default_image_quality: parseInt(response.default_image_quality) || 85, enable_devtools_protection: response.enable_devtools_protection !== false, max_image_requests_per_minute: parseInt(response.max_image_requests_per_minute) || 30, suspicious_activity_threshold: parseInt(response.suspicious_activity_threshold) || 10, enable_canvas_rendering: response.enable_canvas_rendering === true, default_fragmentation_level: parseInt(response.default_fragmentation_level) || 3, enable_overlay_protection: response.enable_overlay_protection !== false, protection_warning_message: response.protection_warning_message || settings.protection_warning_message }; setSettings(protectionSettings); } catch (error) { console.error('Failed to load protection settings:', error); toast.error('Failed to load protection settings'); } finally { setIsLoading(false); } }; const saveSettings = async () => { try { setIsSaving(true); // Convert settings to API format const apiSettings = Object.entries(settings).reduce((acc, [key, value]) => { acc[key] = typeof value === 'boolean' ? value : value.toString(); return acc; }, {} as Record); await settingsService.updateSettings(apiSettings); toast.success('Protection settings saved successfully'); } catch (error) { console.error('Failed to save protection settings:', error); toast.error('Failed to save protection settings'); } finally { setIsSaving(false); } }; const updateSetting = (key: keyof ProtectionSettings, value: any) => { setSettings(prev => ({ ...prev, [key]: value })); }; const protectionLevels = [ { value: 'basic', label: 'Basic - Minimal protection, best performance' }, { value: 'standard', label: 'Standard - Balanced protection and performance' }, { value: 'enhanced', label: 'Enhanced - Strong protection with good performance' }, { value: 'maximum', label: 'Maximum - Strongest protection, may impact performance' } ]; const getProtectionLevelIcon = (level: string) => { switch (level) { case 'basic': return ; case 'standard': return ; case 'enhanced': return ; case 'maximum': return ; default: return ; } }; const getProtectionLevelDescription = (level: string) => { switch (level) { case 'basic': return 'Prevents drag/drop and basic right-click. Good for public galleries.'; case 'standard': return 'Adds keyboard shortcut blocking and user selection prevention.'; case 'enhanced': return 'Includes DevTools detection, rate limiting, and overlay protection.'; case 'maximum': return 'Canvas rendering, image fragmentation, and comprehensive monitoring.'; default: return ''; } }; if (isLoading) { return (
); } return (

Image Protection Settings

Configure security measures for photo galleries

{/* Protection Level */}
updateSetting('default_image_quality', parseInt(e.target.value))} className="w-full" />
Lower quality = Better protection Higher quality = Better image
{/* DevTools Protection */}

Detect and respond to browser developer tools

updateSetting('enable_devtools_protection', checked)} />
{/* Canvas Rendering */}

Render images on canvas instead of img tags (stronger protection)

updateSetting('enable_canvas_rendering', checked)} />
{/* Fragmentation Level */} {settings.enable_canvas_rendering && (
updateSetting('default_fragmentation_level', parseInt(e.target.value))} className="w-full" />
Low fragmentation High fragmentation
)} {/* Rate Limiting */}
updateSetting('max_image_requests_per_minute', parseInt(e.target.value))} />
updateSetting('suspicious_activity_threshold', parseInt(e.target.value))} />
{/* Overlay Protection */}

Add transparent overlays to prevent easy screenshot extraction

updateSetting('enable_overlay_protection', checked)} />
{/* Warning Message */}