'use client'; import React, { useState, useEffect } from 'react'; import { Radio, Plus, RefreshCw, ExternalLink, ShieldCheck, Tag } from 'lucide-react'; import { InfoTooltip } from '@/components/InfoTooltip'; const API_BASE = process.env.NEXT_PUBLIC_API_URL || ''; interface Channel { id: string; telegram_handle: string; title: string | null; niche: string; subscriber_count: number; is_active: boolean; last_scraped_at: string | null; created_at: string; } export default function ChannelsPage() { const [channels, setChannels] = useState([]); const [loading, setLoading] = useState(true); const [newHandle, setNewHandle] = useState(''); const [newTitle, setNewTitle] = useState(''); const [newNiche, setNewNiche] = useState('VPN & Proxy'); const [adding, setAdding] = useState(false); const fetchChannels = async () => { setLoading(true); try { const res = await fetch(`${API_BASE}/api/v1/channels`); if (res.ok) { const data = await res.json(); setChannels(data); } } catch (err) { console.error('Failed to load channels', err); } finally { setLoading(false); } }; useEffect(() => { fetchChannels(); }, []); const handleAddChannel = async (e: React.FormEvent) => { e.preventDefault(); if (!newHandle) return; setAdding(true); try { const res = await fetch(`${API_BASE}/api/v1/channels`, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ telegram_handle: newHandle, title: newTitle || newHandle, niche: newNiche, subscriber_count: 5000, is_active: true, }), }); if (res.ok) { setNewHandle(''); setNewTitle(''); fetchChannels(); } else { alert('این کانال قبلاً اضافه شده است.'); } } catch (err) { alert('خطا در افزودن کانال'); } finally { setAdding(false); } }; return (
{/* Header */}

کانال‌های تلگرامی تحت پایش

دسترسی از طریق Telegram Web Preview (بدون مسدودی اکانت کاربری)

{/* Add New Channel Card */}
افزودن کانال تلگرامی جدید به پایپ‌لاین
setNewHandle(e.target.value)} className="w-full bg-slate-950 border border-slate-800 rounded-xl px-3.5 py-2 text-xs text-slate-100 focus:outline-none focus:border-indigo-500 font-mono" required />
setNewTitle(e.target.value)} className="w-full bg-slate-950 border border-slate-800 rounded-xl px-3.5 py-2 text-xs text-slate-100 focus:outline-none focus:border-indigo-500" />
{/* Channels Table */}

کانال‌های ثبت‌شده در دیتابیس

{channels.length} کانال فعال
{loading ? (
در حال بارگذاری لیست...
) : (
{channels.map((ch) => ( ))}
آیدی تلگرام عنوان دسته‌بندی وضعیت رصد آخرین پایش لینک منبع
@{ch.telegram_handle} {ch.title || '-'} {ch.niche} فعال {ch.last_scraped_at ? ( new Date(ch.last_scraped_at).toLocaleString('fa-IR') ) : ( هنوز پایش نشده )} کانال
)}
); }