Files
ai-showcase-platform/app/set-ip/page.tsx

175 lines
5.4 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

'use client';
import React, { useState } from 'react';
import { Button } from '@/components/ui/button';
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card';
import { Input } from '@/components/ui/input';
import { Label } from '@/components/ui/label';
import { Alert, AlertDescription } from '@/components/ui/alert';
import { Loader2, Database, CheckCircle, AlertTriangle } from 'lucide-react';
export default function SetIPPage() {
const [clientIP, setClientIP] = useState('61-227-253-171');
const [loading, setLoading] = useState(false);
const [message, setMessage] = useState<string>('');
const [error, setError] = useState<string>('');
// 設置客戶端 IP
const setClientIP = async () => {
if (!clientIP.trim()) {
setError('請輸入客戶端 IP 地址');
return;
}
try {
setLoading(true);
const response = await fetch('/api/set-client-ip', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({ clientIP: clientIP.trim() }),
});
const data = await response.json();
if (data.success) {
setMessage(data.message || '客戶端 IP 設置成功');
setError('');
} else {
setError(data.error || '設置客戶端 IP 失敗');
}
} catch (err) {
setError('設置錯誤: ' + (err instanceof Error ? err.message : '未知錯誤'));
} finally {
setLoading(false);
}
};
// 快速設置你的 IP
const setYourIP = () => {
setClientIP('61-227-253-171');
};
// 測試清理功能
const testCleanup = async () => {
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}`);
setError('');
} else {
setError(data.error || '清理失敗');
}
} catch (err) {
setError('清理錯誤: ' + (err instanceof Error ? err.message : '未知錯誤'));
} finally {
setLoading(false);
}
};
return (
<div className="container mx-auto p-6 space-y-6">
<div>
<h1 className="text-3xl font-bold"> IP</h1>
<p className="text-muted-foreground">
IP
</p>
</div>
{/* IP 設置 */}
<Card>
<CardHeader>
<CardTitle className="flex items-center gap-2">
<Database className="h-5 w-5" />
IP
</CardTitle>
<CardDescription>
IP 使 IP
</CardDescription>
</CardHeader>
<CardContent className="space-y-4">
<div className="space-y-2">
<Label htmlFor="clientIP"> IP </Label>
<div className="flex gap-2">
<Input
id="clientIP"
value={clientIP}
onChange={(e) => setClientIP(e.target.value)}
placeholder="例如: 61-227-253-171"
className="flex-1"
/>
<Button
onClick={setYourIP}
disabled={loading}
variant="outline"
>
使 IP
</Button>
</div>
</div>
<div className="flex gap-2">
<Button
onClick={setClientIP}
disabled={loading || !clientIP.trim()}
className="flex-1"
>
{loading ? <Loader2 className="h-4 w-4 animate-spin" /> : <CheckCircle className="h-4 w-4" />}
IP
</Button>
<Button
onClick={testCleanup}
disabled={loading}
variant="destructive"
className="flex-1"
>
{loading ? <Loader2 className="h-4 w-4 animate-spin" /> : <AlertTriangle className="h-4 w-4" />}
</Button>
</div>
</CardContent>
</Card>
{/* 使用說明 */}
<Card>
<CardHeader>
<CardTitle>使</CardTitle>
</CardHeader>
<CardContent className="space-y-2 text-sm text-muted-foreground">
<p> <strong> IP:</strong> 61-227-253-171</p>
<p> <strong> IP:</strong> IP IP</p>
<p> <strong>:</strong> IP </p>
<p> <strong>:</strong> IP </p>
</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>
)}
</div>
);
}