清理不必要的測試檔案

This commit is contained in:
2025-09-21 03:23:26 +08:00
parent 8b3af6608e
commit f6abef38e9
58 changed files with 1 additions and 8621 deletions

View File

@@ -1,371 +0,0 @@
'use client';
import React, { useState, useEffect } from 'react';
import { Button } from '@/components/ui/button';
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card';
import { Badge } from '@/components/ui/badge';
import { Alert, AlertDescription } from '@/components/ui/alert';
import { Input } from '@/components/ui/input';
import { Label } from '@/components/ui/label';
import { Loader2, Database, Trash2, Settings, Activity, Clock, Users } from 'lucide-react';
interface ConnectionStats {
totalConnections: number;
idleConnections: number;
oldConnections: number;
maxIdleTime: number;
maxConnectionAge: number;
connections: Array<{
createdAt: string;
lastUsed: string;
idleTime: number;
age: number;
userId?: string;
sessionId?: string;
}>;
}
export default function ConnectionMonitorPage() {
const [stats, setStats] = useState<ConnectionStats | null>(null);
const [loading, setLoading] = useState(false);
const [message, setMessage] = useState<string>('');
const [error, setError] = useState<string>('');
const [maxIdleTime, setMaxIdleTime] = useState<number>(300000); // 5分鐘
const [maxConnectionAge, setMaxConnectionAge] = useState<number>(1800000); // 30分鐘
// 獲取連線統計
const fetchStats = async () => {
try {
setLoading(true);
const response = await fetch('/api/connection-monitor?action=stats');
const data = await response.json();
if (data.success) {
setStats(data.data);
setMessage('統計更新成功');
setError('');
} else {
setError(data.error || '獲取統計失敗');
}
} catch (err) {
setError('網路錯誤: ' + (err instanceof Error ? err.message : '未知錯誤'));
} finally {
setLoading(false);
}
};
// 強制清理連線
const forceCleanup = async () => {
if (!confirm('確定要強制清理所有連線嗎?這可能會影響正在進行的操作!')) {
return;
}
try {
setLoading(true);
const response = await fetch('/api/connection-monitor?action=cleanup');
const data = await response.json();
if (data.success) {
setMessage('連線清理完成');
setError('');
await fetchStats(); // 重新獲取統計
} else {
setError(data.error || '清理失敗');
}
} catch (err) {
setError('清理錯誤: ' + (err instanceof Error ? err.message : '未知錯誤'));
} finally {
setLoading(false);
}
};
// 測試智能連線
const testConnection = async () => {
try {
setLoading(true);
const response = await fetch('/api/connection-monitor?action=test');
const data = await response.json();
if (data.success) {
setMessage('智能連線測試成功');
setError('');
await fetchStats(); // 重新獲取統計
} else {
setError(data.error || '測試失敗');
}
} catch (err) {
setError('測試錯誤: ' + (err instanceof Error ? err.message : '未知錯誤'));
} finally {
setLoading(false);
}
};
// 更新清理配置
const updateConfig = async () => {
try {
setLoading(true);
const response = await fetch('/api/connection-monitor', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
action: 'config',
maxIdleTime,
maxConnectionAge
}),
});
const data = await response.json();
if (data.success) {
setMessage('清理配置更新成功');
setError('');
await fetchStats(); // 重新獲取統計
} else {
setError(data.error || '配置更新失敗');
}
} catch (err) {
setError('配置更新錯誤: ' + (err instanceof Error ? err.message : '未知錯誤'));
} finally {
setLoading(false);
}
};
// 格式化時間
const formatTime = (ms: number) => {
const seconds = Math.floor(ms / 1000);
const minutes = Math.floor(seconds / 60);
const hours = Math.floor(minutes / 60);
if (hours > 0) return `${hours}h ${minutes % 60}m`;
if (minutes > 0) return `${minutes}m ${seconds % 60}s`;
return `${seconds}s`;
};
// 組件載入時獲取統計
useEffect(() => {
fetchStats();
// 每30秒自動更新統計
const interval = setInterval(fetchStats, 30000);
return () => clearInterval(interval);
}, []);
return (
<div className="container mx-auto p-6 space-y-6">
<div className="flex items-center justify-between">
<div>
<h1 className="text-3xl font-bold"></h1>
<p className="text-muted-foreground">
</p>
</div>
<Button
onClick={fetchStats}
disabled={loading}
variant="outline"
>
{loading ? <Loader2 className="h-4 w-4 animate-spin" /> : <Activity className="h-4 w-4" />}
</Button>
</div>
{/* 統計概覽 */}
{stats && (
<div className="grid grid-cols-1 md:grid-cols-4 gap-4">
<Card>
<CardContent className="p-6">
<div className="flex items-center gap-2">
<Database className="h-5 w-5 text-blue-500" />
<div>
<p className="text-sm font-medium text-muted-foreground"></p>
<p className="text-2xl font-bold">{stats.totalConnections}</p>
</div>
</div>
</CardContent>
</Card>
<Card>
<CardContent className="p-6">
<div className="flex items-center gap-2">
<Clock className="h-5 w-5 text-yellow-500" />
<div>
<p className="text-sm font-medium text-muted-foreground"></p>
<p className="text-2xl font-bold">{stats.idleConnections}</p>
</div>
</div>
</CardContent>
</Card>
<Card>
<CardContent className="p-6">
<div className="flex items-center gap-2">
<Users className="h-5 w-5 text-red-500" />
<div>
<p className="text-sm font-medium text-muted-foreground"></p>
<p className="text-2xl font-bold">{stats.oldConnections}</p>
</div>
</div>
</CardContent>
</Card>
<Card>
<CardContent className="p-6">
<div className="flex items-center gap-2">
<Activity className="h-5 w-5 text-green-500" />
<div>
<p className="text-sm font-medium text-muted-foreground"></p>
<p className="text-2xl font-bold">
{stats.idleConnections + stats.oldConnections === 0 ? '良好' : '需清理'}
</p>
</div>
</div>
</CardContent>
</Card>
</div>
)}
{/* 操作按鈕 */}
<Card>
<CardHeader>
<CardTitle className="flex items-center gap-2">
<Settings className="h-5 w-5" />
</CardTitle>
<CardDescription>
</CardDescription>
</CardHeader>
<CardContent className="space-y-4">
<div className="grid grid-cols-1 md:grid-cols-3 gap-4">
<Button
onClick={testConnection}
disabled={loading}
variant="outline"
className="w-full"
>
{loading ? <Loader2 className="h-4 w-4 animate-spin" /> : <Database className="h-4 w-4" />}
</Button>
<Button
onClick={forceCleanup}
disabled={loading}
variant="destructive"
className="w-full"
>
{loading ? <Loader2 className="h-4 w-4 animate-spin" /> : <Trash2 className="h-4 w-4" />}
</Button>
<Button
onClick={updateConfig}
disabled={loading}
variant="secondary"
className="w-full"
>
{loading ? <Loader2 className="h-4 w-4 animate-spin" /> : <Settings className="h-4 w-4" />}
</Button>
</div>
{/* 配置設定 */}
<div className="grid grid-cols-1 md:grid-cols-2 gap-4 pt-4 border-t">
<div className="space-y-2">
<Label htmlFor="maxIdleTime"> ()</Label>
<Input
id="maxIdleTime"
type="number"
value={maxIdleTime}
onChange={(e) => setMaxIdleTime(Number(e.target.value))}
placeholder="300000 (5分鐘)"
/>
</div>
<div className="space-y-2">
<Label htmlFor="maxConnectionAge"> ()</Label>
<Input
id="maxConnectionAge"
type="number"
value={maxConnectionAge}
onChange={(e) => setMaxConnectionAge(Number(e.target.value))}
placeholder="1800000 (30分鐘)"
/>
</div>
</div>
</CardContent>
</Card>
{/* 連線詳情 */}
{stats && stats.connections.length > 0 && (
<Card>
<CardHeader>
<CardTitle></CardTitle>
<CardDescription>
</CardDescription>
</CardHeader>
<CardContent>
<div className="space-y-2">
{stats.connections.map((conn, index) => (
<div key={index} className="flex items-center justify-between p-3 border rounded-lg">
<div className="flex items-center gap-4">
<Badge variant="outline">#{index + 1}</Badge>
<div>
<p className="text-sm font-medium">
: {new Date(conn.createdAt).toLocaleString()}
</p>
<p className="text-sm text-muted-foreground">
使: {new Date(conn.lastUsed).toLocaleString()}
</p>
</div>
</div>
<div className="flex items-center gap-2">
<Badge variant={conn.idleTime > stats.maxIdleTime ? "destructive" : "default"}>
: {formatTime(conn.idleTime)}
</Badge>
<Badge variant={conn.age > stats.maxConnectionAge ? "destructive" : "default"}>
: {formatTime(conn.age)}
</Badge>
{conn.userId && (
<Badge variant="secondary">: {conn.userId}</Badge>
)}
</div>
</div>
))}
</div>
</CardContent>
</Card>
)}
{/* 訊息顯示 */}
{message && (
<Alert>
<Activity className="h-4 w-4" />
<AlertDescription>{message}</AlertDescription>
</Alert>
)}
{error && (
<Alert variant="destructive">
<Database className="h-4 w-4" />
<AlertDescription>{error}</AlertDescription>
</Alert>
)}
{/* 說明資訊 */}
<Card>
<CardHeader>
<CardTitle></CardTitle>
</CardHeader>
<CardContent className="space-y-2 text-sm text-muted-foreground">
<p> <strong>:</strong> 30</p>
<p> <strong>:</strong> 使</p>
<p> <strong>:</strong> </p>
<p> <strong>:</strong> </p>
<p> <strong>:</strong> </p>
</CardContent>
</Card>
</div>
);
}

View File

@@ -1,267 +0,0 @@
'use client';
import React, { useState, useEffect } from 'react';
import { Button } from '@/components/ui/button';
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card';
import { Badge } from '@/components/ui/badge';
import { Alert, AlertDescription } from '@/components/ui/alert';
import { Loader2, Database, Power, AlertTriangle, CheckCircle } from 'lucide-react';
interface ShutdownStatus {
isShuttingDown: boolean;
handlerCount: number;
registeredHandlers: string[];
}
export default function DatabaseShutdownPage() {
const [status, setStatus] = useState<ShutdownStatus | null>(null);
const [loading, setLoading] = useState(false);
const [message, setMessage] = useState<string>('');
const [error, setError] = useState<string>('');
// 獲取關閉狀態
const fetchStatus = async () => {
try {
setLoading(true);
const response = await fetch('/api/test-shutdown?action=status');
const data = await response.json();
if (data.success) {
setStatus(data.data);
setMessage('狀態更新成功');
setError('');
} else {
setError(data.error || '獲取狀態失敗');
}
} catch (err) {
setError('網路錯誤: ' + (err instanceof Error ? err.message : '未知錯誤'));
} finally {
setLoading(false);
}
};
// 測試關閉機制
const testShutdown = async () => {
try {
setLoading(true);
const response = await fetch('/api/test-shutdown?action=test');
const data = await response.json();
if (data.success) {
setMessage('關閉機制測試成功');
setError('');
await fetchStatus(); // 重新獲取狀態
} else {
setError(data.error || '測試失敗');
}
} catch (err) {
setError('測試錯誤: ' + (err instanceof Error ? err.message : '未知錯誤'));
} finally {
setLoading(false);
}
};
// 強制關閉測試
const forceShutdown = async () => {
if (!confirm('確定要執行強制關閉測試嗎?這可能會影響應用程式運行!')) {
return;
}
try {
setLoading(true);
const response = await fetch('/api/test-shutdown?action=force');
const data = await response.json();
if (data.success) {
setMessage('強制關閉測試完成');
setError('');
await fetchStatus(); // 重新獲取狀態
} else {
setError(data.error || '強制關閉測試失敗');
}
} catch (err) {
setError('強制關閉錯誤: ' + (err instanceof Error ? err.message : '未知錯誤'));
} finally {
setLoading(false);
}
};
// 優雅關閉測試
const gracefulShutdown = async () => {
if (!confirm('確定要執行優雅關閉測試嗎?這會關閉所有資料庫連線!')) {
return;
}
try {
setLoading(true);
const response = await fetch('/api/test-shutdown', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({ action: 'graceful' }),
});
const data = await response.json();
if (data.success) {
setMessage('優雅關閉測試完成');
setError('');
await fetchStatus(); // 重新獲取狀態
} else {
setError(data.error || '優雅關閉測試失敗');
}
} catch (err) {
setError('優雅關閉錯誤: ' + (err instanceof Error ? err.message : '未知錯誤'));
} finally {
setLoading(false);
}
};
// 組件載入時獲取狀態
useEffect(() => {
fetchStatus();
}, []);
return (
<div className="container mx-auto p-6 space-y-6">
<div className="flex items-center justify-between">
<div>
<h1 className="text-3xl font-bold"></h1>
<p className="text-muted-foreground">
</p>
</div>
<Button
onClick={fetchStatus}
disabled={loading}
variant="outline"
>
{loading ? <Loader2 className="h-4 w-4 animate-spin" /> : <Database className="h-4 w-4" />}
</Button>
</div>
{/* 狀態顯示 */}
{status && (
<Card>
<CardHeader>
<CardTitle className="flex items-center gap-2">
<Database className="h-5 w-5" />
</CardTitle>
<CardDescription>
</CardDescription>
</CardHeader>
<CardContent className="space-y-4">
<div className="grid grid-cols-1 md:grid-cols-3 gap-4">
<div className="flex items-center gap-2">
<span className="text-sm font-medium">:</span>
<Badge variant={status.isShuttingDown ? "destructive" : "default"}>
{status.isShuttingDown ? "關閉中" : "正常"}
</Badge>
</div>
<div className="flex items-center gap-2">
<span className="text-sm font-medium">:</span>
<Badge variant="outline">{status.handlerCount}</Badge>
</div>
<div className="flex items-center gap-2">
<span className="text-sm font-medium">:</span>
<Badge variant={status.isShuttingDown ? "destructive" : "default"}>
{status.isShuttingDown ? "異常" : "正常"}
</Badge>
</div>
</div>
<div>
<span className="text-sm font-medium">:</span>
<div className="mt-2 flex flex-wrap gap-2">
{status.registeredHandlers.map((handler, index) => (
<Badge key={index} variant="secondary">
{handler}
</Badge>
))}
</div>
</div>
</CardContent>
</Card>
)}
{/* 操作按鈕 */}
<Card>
<CardHeader>
<CardTitle className="flex items-center gap-2">
<Power className="h-5 w-5" />
</CardTitle>
<CardDescription>
</CardDescription>
</CardHeader>
<CardContent className="space-y-4">
<div className="grid grid-cols-1 md:grid-cols-3 gap-4">
<Button
onClick={testShutdown}
disabled={loading}
variant="outline"
className="w-full"
>
{loading ? <Loader2 className="h-4 w-4 animate-spin" /> : <CheckCircle className="h-4 w-4" />}
</Button>
<Button
onClick={forceShutdown}
disabled={loading}
variant="destructive"
className="w-full"
>
{loading ? <Loader2 className="h-4 w-4 animate-spin" /> : <AlertTriangle className="h-4 w-4" />}
</Button>
<Button
onClick={gracefulShutdown}
disabled={loading}
variant="destructive"
className="w-full"
>
{loading ? <Loader2 className="h-4 w-4 animate-spin" /> : <Power className="h-4 w-4" />}
</Button>
</div>
</CardContent>
</Card>
{/* 訊息顯示 */}
{message && (
<Alert>
<CheckCircle className="h-4 w-4" />
<AlertDescription>{message}</AlertDescription>
</Alert>
)}
{error && (
<Alert variant="destructive">
<AlertTriangle className="h-4 w-4" />
<AlertDescription>{error}</AlertDescription>
</Alert>
)}
{/* 說明資訊 */}
<Card>
<CardHeader>
<CardTitle>使</CardTitle>
</CardHeader>
<CardContent className="space-y-2 text-sm text-muted-foreground">
<p> <strong>:</strong> </p>
<p> <strong>:</strong> </p>
<p> <strong>:</strong> </p>
<p> SIGINT SIGTERM </p>
<p> </p>
</CardContent>
</Card>
</div>
);
}

View File

@@ -1,281 +0,0 @@
'use client';
import React, { useState, useEffect } from 'react';
import { Button } from '@/components/ui/button';
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card';
import { Badge } from '@/components/ui/badge';
import { Alert, AlertDescription } from '@/components/ui/alert';
import { Loader2, Database, AlertTriangle, Trash2, Eye, Zap } from 'lucide-react';
interface ConnectionDetail {
ID: number;
USER: string;
HOST: string;
DB: string;
COMMAND: string;
TIME: number;
STATE: string;
INFO?: string;
}
interface ConnectionData {
connectionCount: number;
connections: ConnectionDetail[];
}
export default function EmergencyCleanupPage() {
const [connectionData, setConnectionData] = useState<ConnectionData | null>(null);
const [loading, setLoading] = useState(false);
const [message, setMessage] = useState<string>('');
const [error, setError] = useState<string>('');
// 獲取連線詳情
const fetchConnectionDetails = async () => {
try {
setLoading(true);
const response = await fetch('/api/emergency-cleanup?action=details');
const data = await response.json();
if (data.success) {
setConnectionData(data.data);
setMessage('連線詳情更新成功');
setError('');
} else {
setError(data.error || '獲取連線詳情失敗');
}
} catch (err) {
setError('網路錯誤: ' + (err instanceof Error ? err.message : '未知錯誤'));
} finally {
setLoading(false);
}
};
// 執行緊急清理
const executeEmergencyCleanup = async () => {
if (!confirm('確定要執行緊急清理嗎?這會關閉所有資料庫連線!')) {
return;
}
try {
setLoading(true);
const response = await fetch('/api/emergency-cleanup', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({ action: 'cleanup' }),
});
const data = await response.json();
if (data.success) {
setMessage('緊急清理完成');
setError('');
await fetchConnectionDetails(); // 重新獲取詳情
} else {
setError(data.error || '緊急清理失敗');
}
} catch (err) {
setError('緊急清理錯誤: ' + (err instanceof Error ? err.message : '未知錯誤'));
} finally {
setLoading(false);
}
};
// 強制殺死所有連線
const forceKillAllConnections = async () => {
if (!confirm('確定要強制殺死所有連線嗎?這會立即終止所有資料庫連線!')) {
return;
}
try {
setLoading(true);
const response = await fetch('/api/emergency-cleanup', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({ action: 'kill-all' }),
});
const data = await response.json();
if (data.success) {
setMessage('強制殺死連線完成');
setError('');
await fetchConnectionDetails(); // 重新獲取詳情
} else {
setError(data.error || '強制殺死連線失敗');
}
} catch (err) {
setError('強制殺死連線錯誤: ' + (err instanceof Error ? err.message : '未知錯誤'));
} finally {
setLoading(false);
}
};
// 組件載入時獲取連線詳情
useEffect(() => {
fetchConnectionDetails();
}, []);
return (
<div className="container mx-auto p-6 space-y-6">
<div className="flex items-center justify-between">
<div>
<h1 className="text-3xl font-bold text-red-600"></h1>
<p className="text-muted-foreground">
</p>
</div>
<Button
onClick={fetchConnectionDetails}
disabled={loading}
variant="outline"
>
{loading ? <Loader2 className="h-4 w-4 animate-spin" /> : <Eye className="h-4 w-4" />}
</Button>
</div>
{/* 警告提示 */}
<Alert variant="destructive">
<AlertTriangle className="h-4 w-4" />
<AlertDescription>
<strong></strong> 使
</AlertDescription>
</Alert>
{/* 連線統計 */}
{connectionData && (
<Card>
<CardHeader>
<CardTitle className="flex items-center gap-2">
<Database className="h-5 w-5" />
</CardTitle>
<CardDescription>
</CardDescription>
</CardHeader>
<CardContent className="space-y-4">
<div className="flex items-center gap-4">
<Badge variant="outline" className="text-lg px-3 py-1">
: {connectionData.connectionCount}
</Badge>
<Badge
variant={connectionData.connectionCount > 10 ? "destructive" : "default"}
className="text-lg px-3 py-1"
>
: {connectionData.connectionCount > 10 ? "異常" : "正常"}
</Badge>
</div>
</CardContent>
</Card>
)}
{/* 緊急操作 */}
<Card>
<CardHeader>
<CardTitle className="flex items-center gap-2 text-red-600">
<Zap className="h-5 w-5" />
</CardTitle>
<CardDescription>
</CardDescription>
</CardHeader>
<CardContent className="space-y-4">
<div className="grid grid-cols-1 md:grid-cols-2 gap-4">
<Button
onClick={executeEmergencyCleanup}
disabled={loading}
variant="destructive"
className="w-full"
>
{loading ? <Loader2 className="h-4 w-4 animate-spin" /> : <Trash2 className="h-4 w-4" />}
</Button>
<Button
onClick={forceKillAllConnections}
disabled={loading}
variant="destructive"
className="w-full"
>
{loading ? <Loader2 className="h-4 w-4 animate-spin" /> : <AlertTriangle className="h-4 w-4" />}
</Button>
</div>
</CardContent>
</Card>
{/* 連線詳情列表 */}
{connectionData && connectionData.connections.length > 0 && (
<Card>
<CardHeader>
<CardTitle></CardTitle>
<CardDescription>
</CardDescription>
</CardHeader>
<CardContent>
<div className="space-y-2 max-h-96 overflow-y-auto">
{connectionData.connections.map((conn, index) => (
<div key={conn.ID} className="flex items-center justify-between p-3 border rounded-lg">
<div className="flex items-center gap-4">
<Badge variant="outline">#{conn.ID}</Badge>
<div>
<p className="text-sm font-medium">
: {conn.USER} | : {conn.HOST}
</p>
<p className="text-sm text-muted-foreground">
: {conn.DB} | : {conn.COMMAND}
</p>
<p className="text-sm text-muted-foreground">
: {conn.TIME}s | : {conn.STATE}
</p>
{conn.INFO && (
<p className="text-xs text-muted-foreground mt-1">
: {conn.INFO.length > 100 ? conn.INFO.substring(0, 100) + '...' : conn.INFO}
</p>
)}
</div>
</div>
</div>
))}
</div>
</CardContent>
</Card>
)}
{/* 訊息顯示 */}
{message && (
<Alert>
<Database className="h-4 w-4" />
<AlertDescription>{message}</AlertDescription>
</Alert>
)}
{error && (
<Alert variant="destructive">
<AlertTriangle className="h-4 w-4" />
<AlertDescription>{error}</AlertDescription>
</Alert>
)}
{/* 使用說明 */}
<Card>
<CardHeader>
<CardTitle>使</CardTitle>
</CardHeader>
<CardContent className="space-y-2 text-sm text-muted-foreground">
<p> <strong>:</strong> </p>
<p> <strong>:</strong> </p>
<p> <strong>:</strong> </p>
<p> 使</p>
</CardContent>
</Card>
</div>
);
}

View File

@@ -1,442 +0,0 @@
'use client';
import React, { useState, useEffect } from 'react';
import { Button } from '@/components/ui/button';
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card';
import { Badge } from '@/components/ui/badge';
import { Alert, AlertDescription } from '@/components/ui/alert';
import { Input } from '@/components/ui/input';
import { Label } from '@/components/ui/label';
import { Loader2, Database, AlertTriangle, Trash2, Eye, Zap, Globe } from 'lucide-react';
interface ConnectionDetail {
ID: number;
USER: string;
HOST: string;
DB: string;
COMMAND: string;
TIME: number;
STATE: string;
INFO?: string;
}
interface ConnectionStatus {
ip: string;
connectionCount: number;
connections: ConnectionDetail[];
}
interface LocalStats {
clientIP: string;
trackedConnections: number;
connections: Array<{
connectionId: string;
createdAt: string;
lastUsed: string;
userAgent?: string;
}>;
}
export default function IPCleanupPage() {
const [connectionStatus, setConnectionStatus] = useState<ConnectionStatus | null>(null);
const [localStats, setLocalStats] = useState<LocalStats | null>(null);
const [loading, setLoading] = useState(false);
const [message, setMessage] = useState<string>('');
const [error, setError] = useState<string>('');
const [targetIP, setTargetIP] = useState<string>('');
// 獲取當前 IP 的連線狀態
const fetchCurrentIPStatus = async () => {
try {
setLoading(true);
const response = await fetch('/api/ip-cleanup?action=status');
const data = await response.json();
if (data.success) {
setConnectionStatus(data.data);
setMessage('當前 IP 連線狀態更新成功');
setError('');
} else {
setError(data.error || '獲取當前 IP 連線狀態失敗');
}
} catch (err) {
setError('網路錯誤: ' + (err instanceof Error ? err.message : '未知錯誤'));
} finally {
setLoading(false);
}
};
// 獲取指定 IP 的連線狀態
const fetchSpecificIPStatus = async () => {
if (!targetIP.trim()) {
setError('請輸入目標 IP 地址');
return;
}
try {
setLoading(true);
const response = await fetch(`/api/ip-cleanup?action=status-specific&ip=${encodeURIComponent(targetIP)}`);
const data = await response.json();
if (data.success) {
setConnectionStatus(data.data);
setMessage(`指定 IP ${targetIP} 的連線狀態更新成功`);
setError('');
} else {
setError(data.error || '獲取指定 IP 連線狀態失敗');
}
} catch (err) {
setError('網路錯誤: ' + (err instanceof Error ? err.message : '未知錯誤'));
} finally {
setLoading(false);
}
};
// 獲取本地連線統計
const fetchLocalStats = async () => {
try {
setLoading(true);
const response = await fetch('/api/ip-cleanup?action=local-stats');
const data = await response.json();
if (data.success) {
setLocalStats(data.data);
setMessage('本地連線統計更新成功');
setError('');
} else {
setError(data.error || '獲取本地連線統計失敗');
}
} catch (err) {
setError('網路錯誤: ' + (err instanceof Error ? err.message : '未知錯誤'));
} finally {
setLoading(false);
}
};
// 清理當前 IP 的連線
const cleanupCurrentIP = async () => {
if (!confirm('確定要清理當前 IP 的所有連線嗎?')) {
return;
}
try {
setLoading(true);
const response = await fetch('/api/ip-cleanup', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({ action: 'cleanup-current' }),
});
const data = await response.json();
if (data.success) {
setMessage(data.message || '當前 IP 連線清理完成');
setError('');
await fetchCurrentIPStatus(); // 重新獲取狀態
} else {
setError(data.error || '當前 IP 連線清理失敗');
}
} catch (err) {
setError('當前 IP 連線清理錯誤: ' + (err instanceof Error ? err.message : '未知錯誤'));
} finally {
setLoading(false);
}
};
// 清理指定 IP 的連線
const cleanupSpecificIP = async () => {
if (!targetIP.trim()) {
setError('請輸入目標 IP 地址');
return;
}
if (!confirm(`確定要清理 IP ${targetIP} 的所有連線嗎?`)) {
return;
}
try {
setLoading(true);
const response = await fetch('/api/ip-cleanup', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
action: 'cleanup-specific',
targetIP: targetIP.trim()
}),
});
const data = await response.json();
if (data.success) {
setMessage(data.message || `IP ${targetIP} 連線清理完成`);
setError('');
await fetchSpecificIPStatus(); // 重新獲取狀態
} else {
setError(data.error || `IP ${targetIP} 連線清理失敗`);
}
} catch (err) {
setError(`IP ${targetIP} 連線清理錯誤: ` + (err instanceof Error ? err.message : '未知錯誤'));
} finally {
setLoading(false);
}
};
// 清理本地追蹤的連線
const cleanupLocalConnections = async () => {
try {
setLoading(true);
const response = await fetch('/api/ip-cleanup', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({ action: 'cleanup-local' }),
});
const data = await response.json();
if (data.success) {
setMessage(data.message || '本地連線清理完成');
setError('');
await fetchLocalStats(); // 重新獲取統計
} else {
setError(data.error || '本地連線清理失敗');
}
} catch (err) {
setError('本地連線清理錯誤: ' + (err instanceof Error ? err.message : '未知錯誤'));
} finally {
setLoading(false);
}
};
// 組件載入時獲取狀態
useEffect(() => {
fetchCurrentIPStatus();
fetchLocalStats();
}, []);
return (
<div className="container mx-auto p-6 space-y-6">
<div className="flex items-center justify-between">
<div>
<h1 className="text-3xl font-bold">IP </h1>
<p className="text-muted-foreground">
IP
</p>
</div>
<div className="flex gap-2">
<Button
onClick={fetchCurrentIPStatus}
disabled={loading}
variant="outline"
>
{loading ? <Loader2 className="h-4 w-4 animate-spin" /> : <Eye className="h-4 w-4" />}
IP
</Button>
<Button
onClick={fetchLocalStats}
disabled={loading}
variant="outline"
>
{loading ? <Loader2 className="h-4 w-4 animate-spin" /> : <Database className="h-4 w-4" />}
</Button>
</div>
</div>
{/* 當前 IP 連線狀態 */}
{connectionStatus && (
<Card>
<CardHeader>
<CardTitle className="flex items-center gap-2">
<Globe className="h-5 w-5" />
IP
</CardTitle>
<CardDescription>
IP: {connectionStatus.ip} | : {connectionStatus.connectionCount}
</CardDescription>
</CardHeader>
<CardContent className="space-y-4">
<div className="flex items-center gap-4">
<Badge variant="outline" className="text-lg px-3 py-1">
: {connectionStatus.connectionCount}
</Badge>
<Badge
variant={connectionStatus.connectionCount > 5 ? "destructive" : "default"}
className="text-lg px-3 py-1"
>
: {connectionStatus.connectionCount > 5 ? "異常" : "正常"}
</Badge>
</div>
</CardContent>
</Card>
)}
{/* 本地連線統計 */}
{localStats && (
<Card>
<CardHeader>
<CardTitle className="flex items-center gap-2">
<Database className="h-5 w-5" />
</CardTitle>
<CardDescription>
IP: {localStats.clientIP} | : {localStats.trackedConnections}
</CardDescription>
</CardHeader>
<CardContent>
<div className="space-y-2">
{localStats.connections.map((conn, index) => (
<div key={index} className="flex items-center justify-between p-2 border rounded">
<div>
<p className="text-sm font-medium"> ID: {conn.connectionId}</p>
<p className="text-xs text-muted-foreground">
: {new Date(conn.createdAt).toLocaleString()} |
使: {new Date(conn.lastUsed).toLocaleString()}
</p>
</div>
</div>
))}
</div>
</CardContent>
</Card>
)}
{/* 操作按鈕 */}
<Card>
<CardHeader>
<CardTitle className="flex items-center gap-2">
<Trash2 className="h-5 w-5" />
IP
</CardTitle>
<CardDescription>
IP
</CardDescription>
</CardHeader>
<CardContent className="space-y-4">
<div className="grid grid-cols-1 md:grid-cols-2 gap-4">
<Button
onClick={cleanupCurrentIP}
disabled={loading}
variant="destructive"
className="w-full"
>
{loading ? <Loader2 className="h-4 w-4 animate-spin" /> : <Trash2 className="h-4 w-4" />}
IP
</Button>
<Button
onClick={cleanupLocalConnections}
disabled={loading}
variant="outline"
className="w-full"
>
{loading ? <Loader2 className="h-4 w-4 animate-spin" /> : <Database className="h-4 w-4" />}
</Button>
</div>
{/* 指定 IP 清理 */}
<div className="space-y-2">
<Label htmlFor="targetIP"> IP </Label>
<div className="flex gap-2">
<Input
id="targetIP"
value={targetIP}
onChange={(e) => setTargetIP(e.target.value)}
placeholder="例如: 192.168.1.100"
className="flex-1"
/>
<Button
onClick={fetchSpecificIPStatus}
disabled={loading || !targetIP.trim()}
variant="outline"
>
<Eye className="h-4 w-4" />
</Button>
<Button
onClick={cleanupSpecificIP}
disabled={loading || !targetIP.trim()}
variant="destructive"
>
<Trash2 className="h-4 w-4" />
</Button>
</div>
</div>
</CardContent>
</Card>
{/* 連線詳情列表 */}
{connectionStatus && connectionStatus.connections.length > 0 && (
<Card>
<CardHeader>
<CardTitle></CardTitle>
<CardDescription>
IP {connectionStatus.ip}
</CardDescription>
</CardHeader>
<CardContent>
<div className="space-y-2 max-h-96 overflow-y-auto">
{connectionStatus.connections.map((conn, index) => (
<div key={conn.ID} className="flex items-center justify-between p-3 border rounded-lg">
<div className="flex items-center gap-4">
<Badge variant="outline">#{conn.ID}</Badge>
<div>
<p className="text-sm font-medium">
: {conn.USER} | : {conn.HOST}
</p>
<p className="text-sm text-muted-foreground">
: {conn.DB} | : {conn.COMMAND}
</p>
<p className="text-sm text-muted-foreground">
: {conn.TIME}s | : {conn.STATE}
</p>
{conn.INFO && (
<p className="text-xs text-muted-foreground mt-1">
: {conn.INFO.length > 100 ? conn.INFO.substring(0, 100) + '...' : conn.INFO}
</p>
)}
</div>
</div>
</div>
))}
</div>
</CardContent>
</Card>
)}
{/* 訊息顯示 */}
{message && (
<Alert>
<Database className="h-4 w-4" />
<AlertDescription>{message}</AlertDescription>
</Alert>
)}
{error && (
<Alert variant="destructive">
<AlertTriangle className="h-4 w-4" />
<AlertDescription>{error}</AlertDescription>
</Alert>
)}
{/* 使用說明 */}
<Card>
<CardHeader>
<CardTitle>IP </CardTitle>
</CardHeader>
<CardContent className="space-y-2 text-sm text-muted-foreground">
<p> <strong> IP :</strong> </p>
<p> <strong> IP :</strong> IP IP </p>
<p> <strong>:</strong> </p>
<p> <strong>:</strong> IP </p>
<p> <strong>:</strong> IP </p>
</CardContent>
</Card>
</div>
);
}

View File

@@ -1,195 +0,0 @@
"use client"
import { useState } from "react"
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card"
import { Button } from "@/components/ui/button"
import { Label } from "@/components/ui/label"
import { Textarea } from "@/components/ui/textarea"
import { Dialog, DialogContent, DialogDescription, DialogHeader, DialogTitle } from "@/components/ui/dialog"
import { CheckCircle, Edit, Loader2 } from "lucide-react"
export default function ScoringFormTestPage() {
const [showScoringForm, setShowScoringForm] = useState(false)
const [manualScoring, setManualScoring] = useState({
judgeId: "judge1",
participantId: "app1",
scores: {
"創新性": 0,
"技術性": 0,
"實用性": 0,
"展示效果": 0,
"影響力": 0
},
comments: ""
})
const [isLoading, setIsLoading] = useState(false)
const scoringRules = [
{ name: "創新性", description: "技術創新程度和獨特性", weight: 25 },
{ name: "技術性", description: "技術實現的複雜度和穩定性", weight: 20 },
{ name: "實用性", description: "實際應用價值和用戶體驗", weight: 25 },
{ name: "展示效果", description: "演示效果和表達能力", weight: 15 },
{ name: "影響力", description: "對行業和社會的潛在影響", weight: 15 }
]
const calculateTotalScore = (scores: Record<string, number>): number => {
let totalScore = 0
let totalWeight = 0
scoringRules.forEach(rule => {
const score = scores[rule.name] || 0
const weight = rule.weight || 1
totalScore += score * weight
totalWeight += weight
})
return totalWeight > 0 ? Math.round(totalScore / totalWeight) : 0
}
const handleSubmitScore = async () => {
setIsLoading(true)
// 模擬提交
setTimeout(() => {
setIsLoading(false)
setShowScoringForm(false)
}, 2000)
}
return (
<div className="container mx-auto py-6">
<div className="mb-6">
<h1 className="text-3xl font-bold"></h1>
<p className="text-gray-600"></p>
</div>
<Card>
<CardHeader>
<CardTitle></CardTitle>
<CardDescription></CardDescription>
</CardHeader>
<CardContent>
<Button onClick={() => setShowScoringForm(true)} size="lg">
<Edit className="w-5 h-5 mr-2" />
</Button>
</CardContent>
</Card>
<Dialog open={showScoringForm} onOpenChange={setShowScoringForm}>
<DialogContent className="max-w-4xl max-h-[90vh] overflow-y-auto">
<DialogHeader>
<DialogTitle className="flex items-center space-x-2">
<Edit className="w-5 h-5" />
<span></span>
</DialogTitle>
<DialogDescription>
</DialogDescription>
</DialogHeader>
<div className="space-y-6">
{/* 評分項目 */}
<div className="space-y-4">
<h3 className="text-lg font-semibold"></h3>
{scoringRules.map((rule, index) => (
<div key={index} className="space-y-4 p-6 border rounded-lg bg-white shadow-sm">
<div className="flex justify-between items-start">
<div className="flex-1">
<Label className="text-lg font-semibold text-gray-900">{rule.name}</Label>
<p className="text-sm text-gray-600 mt-2 leading-relaxed">{rule.description}</p>
<p className="text-xs text-purple-600 mt-2 font-medium">{rule.weight}%</p>
</div>
<div className="text-right ml-4">
<span className="text-2xl font-bold text-blue-600">
{manualScoring.scores[rule.name] || 0} / 10
</span>
</div>
</div>
{/* 評分按鈕 */}
<div className="flex flex-wrap gap-3">
{Array.from({ length: 10 }, (_, i) => i + 1).map((score) => (
<button
key={score}
type="button"
onClick={() => setManualScoring({
...manualScoring,
scores: { ...manualScoring.scores, [rule.name]: score }
})}
className={`w-12 h-12 rounded-lg border-2 font-semibold text-lg transition-all duration-200 ${
(manualScoring.scores[rule.name] || 0) === score
? 'bg-blue-600 text-white border-blue-600 shadow-lg scale-105'
: 'bg-white text-gray-700 border-gray-300 hover:border-blue-400 hover:bg-blue-50 hover:scale-105'
}`}
>
{score}
</button>
))}
</div>
</div>
))}
</div>
{/* 總分顯示 */}
<div className="p-6 bg-gradient-to-r from-blue-50 to-purple-50 rounded-lg border-2 border-blue-200">
<div className="flex justify-between items-center">
<div>
<span className="text-xl font-bold text-gray-900"></span>
<p className="text-sm text-gray-600 mt-1"></p>
</div>
<div className="flex items-center space-x-3">
<span className="text-4xl font-bold text-blue-600">
{calculateTotalScore(manualScoring.scores)}
</span>
<span className="text-xl text-gray-500 font-medium">/ 10</span>
</div>
</div>
</div>
{/* 評審意見 */}
<div className="space-y-3">
<Label className="text-lg font-semibold"> *</Label>
<Textarea
placeholder="請詳細填寫評審意見、優點分析、改進建議等..."
value={manualScoring.comments}
onChange={(e) => setManualScoring({ ...manualScoring, comments: e.target.value })}
rows={6}
className="min-h-[120px] resize-none"
/>
<p className="text-xs text-gray-500"></p>
</div>
</div>
<div className="flex justify-end space-x-4 pt-6 border-t border-gray-200">
<Button
variant="outline"
size="lg"
onClick={() => setShowScoringForm(false)}
className="px-8"
>
</Button>
<Button
onClick={handleSubmitScore}
disabled={isLoading}
size="lg"
className="px-8 bg-blue-600 hover:bg-blue-700"
>
{isLoading ? (
<>
<Loader2 className="w-5 h-5 mr-2 animate-spin" />
...
</>
) : (
<>
<CheckCircle className="w-5 h-5 mr-2" />
</>
)}
</Button>
</div>
</DialogContent>
</Dialog>
</div>
)
}

View File

@@ -1,13 +0,0 @@
import { ScoringManagement } from "@/components/admin/scoring-management"
export default function ScoringTestPage() {
return (
<div className="container mx-auto py-6">
<div className="mb-6">
<h1 className="text-3xl font-bold"></h1>
<p className="text-gray-600"></p>
</div>
<ScoringManagement />
</div>
)
}

View File

@@ -1,13 +0,0 @@
import { ScoringManagement } from "@/components/admin/scoring-management"
export default function ScoringPage() {
return (
<div className="container mx-auto py-6">
<div className="mb-6">
<h1 className="text-3xl font-bold"></h1>
<p className="text-gray-600"></p>
</div>
<ScoringManagement />
</div>
)
}

View File

@@ -1,314 +0,0 @@
'use client';
import React, { useState, useEffect } from 'react';
import { Button } from '@/components/ui/button';
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card';
import { Badge } from '@/components/ui/badge';
import { Alert, AlertDescription } from '@/components/ui/alert';
import { Loader2, Database, AlertTriangle, Trash2, Eye, Zap, Skull } from 'lucide-react';
interface ConnectionStatus {
currentConnections: number;
maxConnections: number;
usagePercentage: number;
connectionDetails: Array<{
ID: number;
USER: string;
HOST: string;
DB: string;
COMMAND: string;
TIME: number;
STATE: string;
INFO?: string;
}>;
connectionCount: number;
}
export default function UltimateKillPage() {
const [status, setStatus] = useState<ConnectionStatus | null>(null);
const [loading, setLoading] = useState(false);
const [message, setMessage] = useState<string>('');
const [error, setError] = useState<string>('');
// 獲取連線狀態
const fetchStatus = async () => {
try {
setLoading(true);
const response = await fetch('/api/ultimate-kill?action=status');
const data = await response.json();
if (data.success) {
setStatus(data.data);
setMessage('狀態更新成功');
setError('');
} else {
setError(data.error || '獲取狀態失敗');
}
} catch (err) {
setError('網路錯誤: ' + (err instanceof Error ? err.message : '未知錯誤'));
} finally {
setLoading(false);
}
};
// 終極清理 - 殺死所有連線
const ultimateKill = async () => {
if (!confirm('確定要執行終極清理嗎?這會強制殺死所有資料庫連線!')) {
return;
}
try {
setLoading(true);
const response = await fetch('/api/ultimate-kill', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({ action: 'kill-all' }),
});
const data = await response.json();
if (data.success) {
setMessage(data.message || '終極清理完成');
setError('');
await fetchStatus(); // 重新獲取狀態
} else {
setError(data.error || '終極清理失敗');
}
} catch (err) {
setError('終極清理錯誤: ' + (err instanceof Error ? err.message : '未知錯誤'));
} finally {
setLoading(false);
}
};
// 強制重啟資料庫連線
const forceRestart = async () => {
if (!confirm('確定要強制重啟資料庫連線嗎?這會先殺死所有連線然後重新建立!')) {
return;
}
try {
setLoading(true);
const response = await fetch('/api/ultimate-kill', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({ action: 'restart' }),
});
const data = await response.json();
if (data.success) {
setMessage(data.message || '強制重啟完成');
setError('');
await fetchStatus(); // 重新獲取狀態
} else {
setError(data.error || '強制重啟失敗');
}
} catch (err) {
setError('強制重啟錯誤: ' + (err instanceof Error ? err.message : '未知錯誤'));
} finally {
setLoading(false);
}
};
// 組件載入時獲取狀態
useEffect(() => {
fetchStatus();
// 每10秒自動更新狀態
const interval = setInterval(fetchStatus, 10000);
return () => clearInterval(interval);
}, []);
return (
<div className="container mx-auto p-6 space-y-6">
<div className="flex items-center justify-between">
<div>
<h1 className="text-3xl font-bold text-red-600"></h1>
<p className="text-muted-foreground">
-
</p>
</div>
<Button
onClick={fetchStatus}
disabled={loading}
variant="outline"
>
{loading ? <Loader2 className="h-4 w-4 animate-spin" /> : <Eye className="h-4 w-4" />}
</Button>
</div>
{/* 嚴重警告 */}
<Alert variant="destructive">
<Skull className="h-4 w-4" />
<AlertDescription>
<strong></strong>
</AlertDescription>
</Alert>
{/* 連線狀態概覽 */}
{status && (
<div className="grid grid-cols-1 md:grid-cols-4 gap-4">
<Card>
<CardContent className="p-6">
<div className="flex items-center gap-2">
<Database className="h-5 w-5 text-blue-500" />
<div>
<p className="text-sm font-medium text-muted-foreground"></p>
<p className="text-2xl font-bold">{status.currentConnections}</p>
</div>
</div>
</CardContent>
</Card>
<Card>
<CardContent className="p-6">
<div className="flex items-center gap-2">
<AlertTriangle className="h-5 w-5 text-yellow-500" />
<div>
<p className="text-sm font-medium text-muted-foreground"></p>
<p className="text-2xl font-bold">{status.maxConnections}</p>
</div>
</div>
</CardContent>
</Card>
<Card>
<CardContent className="p-6">
<div className="flex items-center gap-2">
<Zap className="h-5 w-5 text-red-500" />
<div>
<p className="text-sm font-medium text-muted-foreground">使</p>
<p className="text-2xl font-bold">{status.usagePercentage.toFixed(1)}%</p>
</div>
</div>
</CardContent>
</Card>
<Card>
<CardContent className="p-6">
<div className="flex items-center gap-2">
<Trash2 className="h-5 w-5 text-green-500" />
<div>
<p className="text-sm font-medium text-muted-foreground"></p>
<p className="text-2xl font-bold">
{status.connectionCount <= 1 ? '正常' : '異常'}
</p>
</div>
</div>
</CardContent>
</Card>
</div>
)}
{/* 終極操作 */}
<Card>
<CardHeader>
<CardTitle className="flex items-center gap-2 text-red-600">
<Skull className="h-5 w-5" />
</CardTitle>
<CardDescription>
-
</CardDescription>
</CardHeader>
<CardContent className="space-y-4">
<div className="grid grid-cols-1 md:grid-cols-2 gap-4">
<Button
onClick={ultimateKill}
disabled={loading}
variant="destructive"
className="w-full"
>
{loading ? <Loader2 className="h-4 w-4 animate-spin" /> : <Skull className="h-4 w-4" />}
-
</Button>
<Button
onClick={forceRestart}
disabled={loading}
variant="destructive"
className="w-full"
>
{loading ? <Loader2 className="h-4 w-4 animate-spin" /> : <Zap className="h-4 w-4" />}
</Button>
</div>
</CardContent>
</Card>
{/* 連線詳情列表 */}
{status && status.connectionDetails.length > 0 && (
<Card>
<CardHeader>
<CardTitle></CardTitle>
<CardDescription>
</CardDescription>
</CardHeader>
<CardContent>
<div className="space-y-2 max-h-96 overflow-y-auto">
{status.connectionDetails.map((conn, index) => (
<div key={conn.ID} className="flex items-center justify-between p-3 border rounded-lg">
<div className="flex items-center gap-4">
<Badge variant="outline">#{conn.ID}</Badge>
<div>
<p className="text-sm font-medium">
: {conn.USER} | : {conn.HOST}
</p>
<p className="text-sm text-muted-foreground">
: {conn.DB} | : {conn.COMMAND}
</p>
<p className="text-sm text-muted-foreground">
: {conn.TIME}s | : {conn.STATE}
</p>
{conn.INFO && (
<p className="text-xs text-muted-foreground mt-1">
: {conn.INFO.length > 100 ? conn.INFO.substring(0, 100) + '...' : conn.INFO}
</p>
)}
</div>
</div>
</div>
))}
</div>
</CardContent>
</Card>
)}
{/* 訊息顯示 */}
{message && (
<Alert>
<Database className="h-4 w-4" />
<AlertDescription>{message}</AlertDescription>
</Alert>
)}
{error && (
<Alert variant="destructive">
<AlertTriangle className="h-4 w-4" />
<AlertDescription>{error}</AlertDescription>
</Alert>
)}
{/* 使用說明 */}
<Card>
<CardHeader>
<CardTitle></CardTitle>
</CardHeader>
<CardContent className="space-y-2 text-sm text-muted-foreground">
<p> <strong>:</strong> </p>
<p> <strong>:</strong> </p>
<p> <strong>:</strong> 10</p>
<p> <strong>:</strong> </p>
<p> 使</p>
</CardContent>
</Card>
</div>
);
}