import { useEffect } from "react"; import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card"; import { Checkbox } from "@/components/ui/checkbox"; import { Label } from "@/components/ui/label"; import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue, } from "@/components/ui/select"; import { Clock, Database, RefreshCw, Calendar, Activity, Zap, Info } from "lucide-react"; import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger, } from "@/components/ui/tooltip"; import type { ScheduleConfig, DatabaseCleanupConfig } from "@/types/config"; import { formatDate } from "@/lib/utils"; interface AutomationSettingsProps { scheduleConfig: ScheduleConfig; cleanupConfig: DatabaseCleanupConfig; onScheduleChange: (config: ScheduleConfig) => void; onCleanupChange: (config: DatabaseCleanupConfig) => void; isAutoSavingSchedule?: boolean; isAutoSavingCleanup?: boolean; } const scheduleIntervals = [ { label: "Every hour", value: 3600 }, { label: "Every 2 hours", value: 7200 }, { label: "Every 4 hours", value: 14400 }, { label: "Every 8 hours", value: 28800 }, { label: "Every 12 hours", value: 43200 }, { label: "Daily", value: 86400 }, { label: "Every 2 days", value: 172800 }, { label: "Weekly", value: 604800 }, ]; const retentionPeriods = [ { label: "1 day", value: 86400 }, { label: "3 days", value: 259200 }, { label: "1 week", value: 604800 }, { label: "2 weeks", value: 1209600 }, { label: "1 month", value: 2592000 }, { label: "2 months", value: 5184000 }, { label: "3 months", value: 7776000 }, ]; function getCleanupInterval(retentionSeconds: number): number { const days = retentionSeconds / 86400; if (days <= 1) return 21600; // 6 hours if (days <= 3) return 43200; // 12 hours if (days <= 7) return 86400; // 24 hours if (days <= 30) return 172800; // 48 hours return 604800; // 1 week } function getCleanupFrequencyText(retentionSeconds: number): string { const days = retentionSeconds / 86400; if (days <= 1) return "every 6 hours"; if (days <= 3) return "every 12 hours"; if (days <= 7) return "daily"; if (days <= 30) return "every 2 days"; return "weekly"; } export function AutomationSettings({ scheduleConfig, cleanupConfig, onScheduleChange, onCleanupChange, isAutoSavingSchedule, isAutoSavingCleanup, }: AutomationSettingsProps) { // Update nextRun for cleanup when settings change useEffect(() => { if (cleanupConfig.enabled && !cleanupConfig.nextRun) { const cleanupInterval = getCleanupInterval(cleanupConfig.retentionDays); const nextRun = new Date(Date.now() + cleanupInterval * 1000); onCleanupChange({ ...cleanupConfig, nextRun }); } }, [cleanupConfig.enabled, cleanupConfig.retentionDays]); return ( Automation & Maintenance

Background Operations

These automated tasks run in the background to keep your mirrors up-to-date and maintain optimal database performance. Choose intervals that match your workflow and repository update frequency.

{/* Automatic Syncing Section */}

Automatic Syncing

{isAutoSavingSchedule && ( )}
onScheduleChange({ ...scheduleConfig, enabled: !!checked }) } />

Periodically check GitHub for changes and mirror them to Gitea

{scheduleConfig.enabled && (
)}
Last sync {scheduleConfig.lastRun ? formatDate(scheduleConfig.lastRun) : "Never"}
{scheduleConfig.enabled ? ( scheduleConfig.nextRun && (
Next sync {formatDate(scheduleConfig.nextRun)}
) ) : (
Enable automatic syncing to schedule periodic repository updates
)}
{/* Database Cleanup Section */}

Database Maintenance

{isAutoSavingCleanup && ( )}
onCleanupChange({ ...cleanupConfig, enabled: !!checked }) } />

Remove old activity logs and events to optimize storage

{cleanupConfig.enabled && (
{cleanupConfig.enabled && (

Cleanup runs {getCleanupFrequencyText(cleanupConfig.retentionDays)}

)}
)}
Last cleanup {cleanupConfig.lastRun ? formatDate(cleanupConfig.lastRun) : "Never"}
{cleanupConfig.enabled ? ( cleanupConfig.nextRun && (
Next cleanup {formatDate(cleanupConfig.nextRun)}
) ) : (
Enable automatic cleanup to optimize database storage
)}
); }