Spaces:
Paused
Paused
CBV01 commited on
Commit ·
9b3b998
1
Parent(s): 5d5cb17
feat: layout improvements, IPTV leakage fix, AI scraper mode, and suffix viewer
Browse files- backend/main.py +401 -160
- frontend/src/app/admin/page.tsx +285 -266
- frontend/src/app/scraper/page.tsx +207 -14
backend/main.py
CHANGED
|
@@ -1595,32 +1595,24 @@ async def _scrape_telegram_search(base_query: str, rows: list, queue: Optional[a
|
|
| 1595 |
search_queries = [base_query]
|
| 1596 |
print(f"SCRAPER[telegram] Free Mode active: Pure natural search with '{base_query}' across {len(rows)} accounts")
|
| 1597 |
else:
|
| 1598 |
-
# Fixed Mode: Build
|
| 1599 |
search_queries = [base_query]
|
| 1600 |
suffixes = [
|
| 1601 |
-
#
|
| 1602 |
"official", "group", "channel", "community", "chat", "hub",
|
| 1603 |
-
"network", "team", "zone", "world", "global", "
|
| 1604 |
-
|
| 1605 |
-
"real", "original", "
|
| 1606 |
-
"
|
| 1607 |
-
|
| 1608 |
-
"
|
| 1609 |
-
"
|
| 1610 |
-
|
| 1611 |
-
"
|
| 1612 |
-
"
|
| 1613 |
-
|
| 1614 |
-
|
| 1615 |
-
|
| 1616 |
-
"streams", "vvod", "players", "subscriptions", "servers",
|
| 1617 |
-
"resellers", "panels", "smart tv", "firestick", "movies",
|
| 1618 |
-
"series", "sports", "signals", "trading", "crypto", "bitcoin",
|
| 1619 |
-
"forex", "investments", "airdrops", "nft", "web3", "calls",
|
| 1620 |
-
"pumps", "marketing", "seo", "b2b", "leads gen", "traffic",
|
| 1621 |
-
"affiliate", "ecommerce", "dropshipping", "sales", "ads",
|
| 1622 |
-
"tools", "software", "development", "coders", "bots", "api",
|
| 1623 |
-
"tech", "designs", "promotions", "freelancers", "gigs", "jobs"
|
| 1624 |
]
|
| 1625 |
for suffix in suffixes:
|
| 1626 |
search_queries.append(f"{base_query} {suffix}")
|
|
@@ -1769,8 +1761,41 @@ async def _scrape_telegram_search(base_query: str, rows: list, queue: Optional[a
|
|
| 1769 |
|
| 1770 |
|
| 1771 |
|
| 1772 |
-
|
| 1773 |
-
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1774 |
results = []
|
| 1775 |
seen = set()
|
| 1776 |
|
|
@@ -1811,11 +1836,15 @@ async def _scrape_spider(seed_groups: List[Dict[str, Any]], rows: list, max_seed
|
|
| 1811 |
f_username = getattr(f_chat, 'username', None)
|
| 1812 |
if f_username:
|
| 1813 |
l_lower = f_username.lower()
|
|
|
|
| 1814 |
if l_lower not in seen:
|
| 1815 |
seen.add(l_lower)
|
|
|
|
|
|
|
|
|
|
| 1816 |
item = {
|
| 1817 |
"id": f"@{f_username}",
|
| 1818 |
-
"title":
|
| 1819 |
"username": f_username,
|
| 1820 |
"participants_count": getattr(f_chat, 'participants_count', 0) or getattr(f_chat, 'megagroup_participants', 0) or 0,
|
| 1821 |
"type": 'channel' if getattr(f_chat, 'broadcast', False) else 'group',
|
|
@@ -1846,10 +1875,14 @@ async def _scrape_spider(seed_groups: List[Dict[str, Any]], rows: list, max_seed
|
|
| 1846 |
v_info = await verify_telegram_info(l_lower)
|
| 1847 |
if not v_info["exists"]:
|
| 1848 |
continue
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1849 |
|
| 1850 |
item2 = {
|
| 1851 |
"id": f"@{l_lower}",
|
| 1852 |
-
"title":
|
| 1853 |
"username": l_lower,
|
| 1854 |
"participants_count": v_info["participants_count"],
|
| 1855 |
"type": "channel", # guess
|
|
@@ -1860,14 +1893,12 @@ async def _scrape_spider(seed_groups: List[Dict[str, Any]], rows: list, max_seed
|
|
| 1860 |
"source": "spider"
|
| 1861 |
}
|
| 1862 |
results.append(item2)
|
| 1863 |
-
# Auto-saving disabled as per user request (manual save only)
|
| 1864 |
-
# if user_id: asyncio.create_task(asyncio.to_thread(lambda: save_scraped_group(user_id, item2))) # type: ignore
|
| 1865 |
if queue:
|
| 1866 |
await queue.put({"type": "result", "layer": 3, "data": item2}) # pyre-ignore
|
| 1867 |
found_in_seed = int(found_in_seed) + 1 # type: ignore
|
| 1868 |
|
| 1869 |
if int(found_in_seed) > 0: # type: ignore
|
| 1870 |
-
print(f"SCRAPER[spider] Crawled @{username} -> found {found_in_seed} new links")
|
| 1871 |
await asyncio.sleep(0.5)
|
| 1872 |
|
| 1873 |
except Exception as e:
|
|
@@ -1882,6 +1913,204 @@ async def _scrape_spider(seed_groups: List[Dict[str, Any]], rows: list, max_seed
|
|
| 1882 |
return results
|
| 1883 |
|
| 1884 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1885 |
@app.get("/api/telegram/scrape_stream")
|
| 1886 |
async def scrape_keyword_stream(
|
| 1887 |
query: str,
|
|
@@ -1889,6 +2118,9 @@ async def scrape_keyword_stream(
|
|
| 1889 |
limit: int = 100,
|
| 1890 |
phone_number: Optional[str] = None,
|
| 1891 |
mode: Optional[str] = "fixed",
|
|
|
|
|
|
|
|
|
|
| 1892 |
user_id: str = Depends(get_current_user_id)
|
| 1893 |
):
|
| 1894 |
conn = get_db_connection()
|
|
@@ -1960,7 +2192,8 @@ async def scrape_keyword_stream(
|
|
| 1960 |
# Use ALL active accounts to maximize yield for the sweep
|
| 1961 |
rows = conn.execute("SELECT session_string, api_id, api_hash, phone_number FROM accounts WHERE user_id = ? AND status = 'active' ORDER BY is_active DESC", (user_id,)).fetchall()
|
| 1962 |
if hasattr(conn, "close"): conn.close()
|
| 1963 |
-
if not rows
|
|
|
|
| 1964 |
|
| 1965 |
base_query = query.strip()
|
| 1966 |
if country:
|
|
@@ -1971,10 +2204,35 @@ async def scrape_keyword_stream(
|
|
| 1971 |
async def scraper_task():
|
| 1972 |
try:
|
| 1973 |
search_mode = (mode or "fixed").lower().strip()
|
| 1974 |
-
mode_label = "Natural Free Search" if search_mode == "free" else "Fixed Suffix Variations"
|
| 1975 |
-
await queue.put({"type": "progress", "msg": f"Layer 1 & 2: Scanning Telegram API ({mode_label}) & Lyzem Engine for '{base_query}'..."}) # pyre-ignore
|
| 1976 |
|
| 1977 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1978 |
l_task = asyncio.create_task(_scrape_lyzem(base_query, 10, queue, user_id))
|
| 1979 |
t_res, l_res = await asyncio.gather(t_task, l_task, return_exceptions=True)
|
| 1980 |
|
|
@@ -1984,17 +2242,15 @@ async def scrape_keyword_stream(
|
|
| 1984 |
k = f"@{item.get('username', '')}"
|
| 1985 |
if k not in ug and item.get('username'): ug[k] = item
|
| 1986 |
|
| 1987 |
-
await queue.put({"type": "progress", "msg": f"Layer 3: Spidering {len(ug)} prominent groups..."})
|
| 1988 |
-
|
| 1989 |
-
|
| 1990 |
-
# Background auto-saving already handled by helper inside scrapers
|
| 1991 |
|
| 1992 |
-
await queue.put({"type": "done", "msg": "
|
| 1993 |
except asyncio.CancelledError:
|
| 1994 |
print("SCRAPER_STREAM canceled by client disconnect")
|
| 1995 |
raise
|
| 1996 |
except Exception as e:
|
| 1997 |
-
await queue.put({"type": "error", "msg": str(e)})
|
| 1998 |
|
| 1999 |
# Start explicitly outside event_generator
|
| 2000 |
bg_task = asyncio.create_task(scraper_task())
|
|
@@ -3519,137 +3775,122 @@ async def suggest_ai_keywords(req: AISuggestRequest, user_id: str = Depends(get_
|
|
| 3519 |
key = (req.api_key or "").strip()
|
| 3520 |
target_count = max(10, min(50, req.count or 30))
|
| 3521 |
|
| 3522 |
-
|
| 3523 |
-
|
| 3524 |
-
|
| 3525 |
-
|
| 3526 |
-
|
| 3527 |
-
"ideas", "inspiration", "tips", "trends", "deals", "market", "store",
|
| 3528 |
-
"wholesale", "vip", "pro", "solutions", "studio", "designs", "leads",
|
| 3529 |
-
"discuss", "lounge", "directory", "alerts", "showcase", "daily", "guide",
|
| 3530 |
-
"academy", "services", "exchange", "portal", "updates", "top", "best"
|
| 3531 |
-
]
|
| 3532 |
-
results = [kw_clean]
|
| 3533 |
-
for m in modifiers:
|
| 3534 |
-
if len(results) >= count: break
|
| 3535 |
-
cand1 = f"{kw_clean} {m}"
|
| 3536 |
-
if cand1 not in results: results.append(cand1)
|
| 3537 |
-
if len(results) >= count: break
|
| 3538 |
-
cand2 = f"{m} {kw_clean}"
|
| 3539 |
-
if cand2 not in results: results.append(cand2)
|
| 3540 |
-
return results[:count]
|
| 3541 |
|
| 3542 |
ai_keywords: List[str] = []
|
| 3543 |
error_note = None
|
| 3544 |
|
| 3545 |
-
|
| 3546 |
-
|
| 3547 |
-
|
| 3548 |
-
|
| 3549 |
-
|
| 3550 |
-
|
| 3551 |
-
|
| 3552 |
-
|
| 3553 |
-
|
| 3554 |
-
|
| 3555 |
-
|
| 3556 |
-
|
| 3557 |
-
|
| 3558 |
-
|
| 3559 |
-
|
| 3560 |
-
|
| 3561 |
-
|
| 3562 |
-
|
| 3563 |
-
"
|
| 3564 |
-
|
| 3565 |
-
|
| 3566 |
-
|
| 3567 |
-
|
| 3568 |
-
|
| 3569 |
-
|
| 3570 |
-
|
| 3571 |
-
|
| 3572 |
-
|
| 3573 |
-
|
| 3574 |
-
|
| 3575 |
-
|
| 3576 |
-
|
| 3577 |
-
error_note = f"OpenAI error ({res.status_code}): {res.text[:120]}"
|
| 3578 |
-
|
| 3579 |
-
elif provider in ("anthropic", "claude"):
|
| 3580 |
-
res = await client.post(
|
| 3581 |
-
"https://api.anthropic.com/v1/messages",
|
| 3582 |
-
headers={
|
| 3583 |
-
"x-api-key": key,
|
| 3584 |
-
"anthropic-version": "2023-06-01",
|
| 3585 |
-
"content-type": "application/json"
|
| 3586 |
-
},
|
| 3587 |
-
json={
|
| 3588 |
-
"model": req.model or "claude-3-5-haiku-20241022",
|
| 3589 |
-
"max_tokens": 1200,
|
| 3590 |
-
"messages": [{"role": "user", "content": prompt}]
|
| 3591 |
-
}
|
| 3592 |
-
)
|
| 3593 |
-
if res.status_code == 200:
|
| 3594 |
-
data = res.json()
|
| 3595 |
-
raw_content = data["content"][0]["text"]
|
| 3596 |
-
match = re.search(r'\[.*\]', raw_content, re.DOTALL)
|
| 3597 |
-
if match:
|
| 3598 |
-
ai_keywords = json.loads(match.group(0))
|
| 3599 |
-
else:
|
| 3600 |
-
error_note = f"Claude error ({res.status_code}): {res.text[:120]}"
|
| 3601 |
-
|
| 3602 |
-
elif provider == "openrouter":
|
| 3603 |
-
res = await client.post(
|
| 3604 |
-
"https://openrouter.ai/api/v1/chat/completions",
|
| 3605 |
-
headers={
|
| 3606 |
-
"Authorization": f"Bearer {key}",
|
| 3607 |
-
"Content-Type": "application/json",
|
| 3608 |
-
"HTTP-Referer": "https://arkitel.com",
|
| 3609 |
-
"X-Title": "ArkiTel"
|
| 3610 |
-
},
|
| 3611 |
-
json={
|
| 3612 |
-
"model": req.model or "openai/gpt-4o-mini",
|
| 3613 |
-
"messages": [
|
| 3614 |
-
{"role": "system", "content": "You are a Telegram keyword intelligence engine. Output only JSON arrays."},
|
| 3615 |
-
{"role": "user", "content": prompt}
|
| 3616 |
-
],
|
| 3617 |
-
"temperature": 0.7
|
| 3618 |
-
}
|
| 3619 |
-
)
|
| 3620 |
-
if res.status_code == 200:
|
| 3621 |
-
data = res.json()
|
| 3622 |
-
raw_content = data["choices"][0]["message"]["content"]
|
| 3623 |
-
match = re.search(r'\[.*\]', raw_content, re.DOTALL)
|
| 3624 |
-
if match:
|
| 3625 |
-
ai_keywords = json.loads(match.group(0))
|
| 3626 |
-
else:
|
| 3627 |
-
error_note = f"OpenRouter error ({res.status_code}): {res.text[:120]}"
|
| 3628 |
-
except Exception as e:
|
| 3629 |
-
error_note = f"AI request exception: {str(e)}"
|
| 3630 |
|
| 3631 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3632 |
clean_keywords: List[str] = []
|
| 3633 |
-
|
| 3634 |
-
|
| 3635 |
-
|
| 3636 |
-
|
| 3637 |
-
|
| 3638 |
-
|
| 3639 |
-
|
| 3640 |
-
|
| 3641 |
-
|
| 3642 |
-
|
| 3643 |
-
clean_keywords = generate_heuristic_keywords(seed, target_count)
|
| 3644 |
-
source = "heuristic_engine" if not key else f"heuristic_fallback ({error_note or 'model response error'})"
|
| 3645 |
|
| 3646 |
return {
|
| 3647 |
"seed": seed,
|
| 3648 |
"keywords": clean_keywords,
|
| 3649 |
"total": len(clean_keywords),
|
| 3650 |
-
"source":
|
| 3651 |
-
"provider": provider
|
| 3652 |
-
"note": error_note
|
| 3653 |
}
|
| 3654 |
|
| 3655 |
@app.delete("/api/admin/users/{user_id}")
|
|
|
|
| 1595 |
search_queries = [base_query]
|
| 1596 |
print(f"SCRAPER[telegram] Free Mode active: Pure natural search with '{base_query}' across {len(rows)} accounts")
|
| 1597 |
else:
|
| 1598 |
+
# Fixed Mode: Build 60+ universal generic and community variations (category-neutral)
|
| 1599 |
search_queries = [base_query]
|
| 1600 |
suffixes = [
|
| 1601 |
+
# Community & Networking (14)
|
| 1602 |
"official", "group", "channel", "community", "chat", "hub",
|
| 1603 |
+
"network", "team", "zone", "world", "global", "club", "lounge", "forum",
|
| 1604 |
+
# Authority & Quality (12)
|
| 1605 |
+
"main", "real", "original", "vip", "pro", "hq", "direct", "portal",
|
| 1606 |
+
"top", "best", "new", "prime",
|
| 1607 |
+
# Information & Updates (12)
|
| 1608 |
+
"updates", "news", "info", "alerts", "broadcast", "notices", "daily",
|
| 1609 |
+
"feed", "insights", "trends", "guide", "academy",
|
| 1610 |
+
# Business & Market (12)
|
| 1611 |
+
"market", "store", "shop", "deals", "leads", "clients", "services",
|
| 1612 |
+
"support", "help", "prices", "exchange", "b2b",
|
| 1613 |
+
# Scope & Connectivity (12)
|
| 1614 |
+
"online", "free", "live", "premium", "international", "access",
|
| 1615 |
+
"connect", "links", "directory", "showcase", "solutions", "discussion"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1616 |
]
|
| 1617 |
for suffix in suffixes:
|
| 1618 |
search_queries.append(f"{base_query} {suffix}")
|
|
|
|
| 1761 |
|
| 1762 |
|
| 1763 |
|
| 1764 |
+
def is_relevant_channel(title: str, username: str, query: str) -> bool:
|
| 1765 |
+
"""Checks whether a discovered channel/group matches the query context and rejects spam/unrelated niches (e.g. IPTV ads)."""
|
| 1766 |
+
if not query:
|
| 1767 |
+
return True
|
| 1768 |
+
|
| 1769 |
+
t_lower = (title or "").lower()
|
| 1770 |
+
u_lower = (username or "").lower()
|
| 1771 |
+
q_lower = query.lower()
|
| 1772 |
+
|
| 1773 |
+
# 1. Unrelated niche / spam blacklist: reject unless explicitly in the user's query
|
| 1774 |
+
unrelated_spam = [
|
| 1775 |
+
"iptv", "firestick", "m3u", "vvod", "reseller panel", "porn", "xxx", "casino", "gambling", "adult 18+", "betting"
|
| 1776 |
+
]
|
| 1777 |
+
for term in unrelated_spam:
|
| 1778 |
+
if term in t_lower or term in u_lower:
|
| 1779 |
+
if term not in q_lower:
|
| 1780 |
+
return False
|
| 1781 |
+
|
| 1782 |
+
# 2. Extract core words from query (skip common generic words)
|
| 1783 |
+
stopwords = {"the", "and", "for", "with", "from", "group", "channel", "official", "chat", "link", "best", "top", "world", "free"}
|
| 1784 |
+
query_tokens = [w for w in re.findall(r'[a-zA-Z0-9]+', q_lower) if len(w) >= 3 and w not in stopwords]
|
| 1785 |
+
if not query_tokens:
|
| 1786 |
+
return True
|
| 1787 |
+
|
| 1788 |
+
# Check if any query token or stem matches title or username
|
| 1789 |
+
for tok in query_tokens:
|
| 1790 |
+
stem = tok[:4] if len(tok) >= 5 else tok
|
| 1791 |
+
if stem in t_lower or stem in u_lower:
|
| 1792 |
+
return True
|
| 1793 |
+
|
| 1794 |
+
return False
|
| 1795 |
+
|
| 1796 |
+
|
| 1797 |
+
async def _scrape_spider(seed_groups: List[Dict[str, Any]], rows: list, max_seeds: int = 15, queue: Optional[asyncio.Queue] = None, user_id: str = "", base_query: str = "") -> List[Dict[str, Any]]:
|
| 1798 |
+
"""Layer 3: Spider Crawler. Reads recent messages of deep channels to find forwarded links and mentions with relevance verification."""
|
| 1799 |
results = []
|
| 1800 |
seen = set()
|
| 1801 |
|
|
|
|
| 1836 |
f_username = getattr(f_chat, 'username', None)
|
| 1837 |
if f_username:
|
| 1838 |
l_lower = f_username.lower()
|
| 1839 |
+
cand_title = getattr(f_chat, 'title', f_username)
|
| 1840 |
if l_lower not in seen:
|
| 1841 |
seen.add(l_lower)
|
| 1842 |
+
# Strict relevance filter against forwarded spam/unrelated niches
|
| 1843 |
+
if base_query and not is_relevant_channel(cand_title, f_username, base_query):
|
| 1844 |
+
continue
|
| 1845 |
item = {
|
| 1846 |
"id": f"@{f_username}",
|
| 1847 |
+
"title": cand_title,
|
| 1848 |
"username": f_username,
|
| 1849 |
"participants_count": getattr(f_chat, 'participants_count', 0) or getattr(f_chat, 'megagroup_participants', 0) or 0,
|
| 1850 |
"type": 'channel' if getattr(f_chat, 'broadcast', False) else 'group',
|
|
|
|
| 1875 |
v_info = await verify_telegram_info(l_lower)
|
| 1876 |
if not v_info["exists"]:
|
| 1877 |
continue
|
| 1878 |
+
cand_title = v_info["title"] or l
|
| 1879 |
+
# Strict relevance check
|
| 1880 |
+
if base_query and not is_relevant_channel(cand_title, l_lower, base_query):
|
| 1881 |
+
continue
|
| 1882 |
|
| 1883 |
item2 = {
|
| 1884 |
"id": f"@{l_lower}",
|
| 1885 |
+
"title": cand_title,
|
| 1886 |
"username": l_lower,
|
| 1887 |
"participants_count": v_info["participants_count"],
|
| 1888 |
"type": "channel", # guess
|
|
|
|
| 1893 |
"source": "spider"
|
| 1894 |
}
|
| 1895 |
results.append(item2)
|
|
|
|
|
|
|
| 1896 |
if queue:
|
| 1897 |
await queue.put({"type": "result", "layer": 3, "data": item2}) # pyre-ignore
|
| 1898 |
found_in_seed = int(found_in_seed) + 1 # type: ignore
|
| 1899 |
|
| 1900 |
if int(found_in_seed) > 0: # type: ignore
|
| 1901 |
+
print(f"SCRAPER[spider] Crawled @{username} -> found {found_in_seed} new verified links")
|
| 1902 |
await asyncio.sleep(0.5)
|
| 1903 |
|
| 1904 |
except Exception as e:
|
|
|
|
| 1913 |
return results
|
| 1914 |
|
| 1915 |
|
| 1916 |
+
async def _scrape_ai_web_discovery(
|
| 1917 |
+
base_query: str,
|
| 1918 |
+
country: Optional[str] = None,
|
| 1919 |
+
queue: Optional[asyncio.Queue] = None,
|
| 1920 |
+
user_id: str = "",
|
| 1921 |
+
provider: str = "openai",
|
| 1922 |
+
api_key: str = "",
|
| 1923 |
+
model: Optional[str] = None,
|
| 1924 |
+
rows: list = []
|
| 1925 |
+
) -> List[Dict[str, Any]]:
|
| 1926 |
+
"""
|
| 1927 |
+
AI Scraper: Scours the web and Telegram directories for active, public Telegram groups and channels
|
| 1928 |
+
matching base_query and country using the user's configured AI model (OpenAI, Claude, or OpenRouter).
|
| 1929 |
+
Discovered channels are verified in real-time via Telegram t.me metadata and streamed.
|
| 1930 |
+
"""
|
| 1931 |
+
results = []
|
| 1932 |
+
seen = set()
|
| 1933 |
+
prov = (provider or "openai").lower().strip()
|
| 1934 |
+
key = (api_key or "").strip()
|
| 1935 |
+
|
| 1936 |
+
if not key:
|
| 1937 |
+
if queue:
|
| 1938 |
+
await queue.put({
|
| 1939 |
+
"type": "error",
|
| 1940 |
+
"msg": "AI Scraper requires an API key. Please configure OpenAI, Claude, or OpenRouter in settings."
|
| 1941 |
+
})
|
| 1942 |
+
return []
|
| 1943 |
+
|
| 1944 |
+
c_info = f" specifically focused on {country.strip()}" if country and country.strip() else ""
|
| 1945 |
+
if queue:
|
| 1946 |
+
await queue.put({
|
| 1947 |
+
"type": "progress",
|
| 1948 |
+
"msg": f"AI Web Discovery: Asking {prov.capitalize()} to uncover active public Telegram communities for '{base_query}'{c_info}..."
|
| 1949 |
+
})
|
| 1950 |
+
|
| 1951 |
+
prompt = (
|
| 1952 |
+
f"You are an advanced web intelligence and OSINT Telegram discovery engine. "
|
| 1953 |
+
f"Identify and list 40 to 60 real, active, public Telegram channels, groups, and discussion communities "
|
| 1954 |
+
f"across the web and Telegram directories for the niche/topic: '{base_query}'{c_info}. "
|
| 1955 |
+
f"Return ONLY a valid JSON object in this format:\n"
|
| 1956 |
+
f"{{\n"
|
| 1957 |
+
f' "channels": [\n'
|
| 1958 |
+
f' {{"username": "telegram_handle_without_at", "title": "Channel/Group Name", "type": "channel"}}\n'
|
| 1959 |
+
f" ]\n"
|
| 1960 |
+
f"}}\n"
|
| 1961 |
+
f"Do NOT include markdown explanation, preamble, or code fences. Only valid raw JSON."
|
| 1962 |
+
)
|
| 1963 |
+
|
| 1964 |
+
discovered_candidates: List[Dict[str, str]] = []
|
| 1965 |
+
|
| 1966 |
+
async with httpx.AsyncClient(timeout=35.0) as client:
|
| 1967 |
+
try:
|
| 1968 |
+
if prov == "openai":
|
| 1969 |
+
res = await client.post(
|
| 1970 |
+
"https://api.openai.com/v1/chat/completions",
|
| 1971 |
+
headers={"Authorization": f"Bearer {key}", "Content-Type": "application/json"},
|
| 1972 |
+
json={
|
| 1973 |
+
"model": model or "gpt-4o-mini",
|
| 1974 |
+
"messages": [
|
| 1975 |
+
{"role": "system", "content": "You are a Telegram directory and web intelligence engine. Output valid JSON only."},
|
| 1976 |
+
{"role": "user", "content": prompt}
|
| 1977 |
+
],
|
| 1978 |
+
"temperature": 0.5
|
| 1979 |
+
}
|
| 1980 |
+
)
|
| 1981 |
+
if res.status_code == 200:
|
| 1982 |
+
raw = res.json()["choices"][0]["message"]["content"]
|
| 1983 |
+
match = re.search(r'\{.*\}', raw, re.DOTALL)
|
| 1984 |
+
if match:
|
| 1985 |
+
parsed = json.loads(match.group(0))
|
| 1986 |
+
discovered_candidates = parsed.get("channels", [])
|
| 1987 |
+
else:
|
| 1988 |
+
if queue:
|
| 1989 |
+
await queue.put({"type": "error", "msg": f"OpenAI error ({res.status_code}): {res.text[:120]}"})
|
| 1990 |
+
return []
|
| 1991 |
+
|
| 1992 |
+
elif prov in ("anthropic", "claude"):
|
| 1993 |
+
res = await client.post(
|
| 1994 |
+
"https://api.anthropic.com/v1/messages",
|
| 1995 |
+
headers={
|
| 1996 |
+
"x-api-key": key,
|
| 1997 |
+
"anthropic-version": "2023-06-01",
|
| 1998 |
+
"content-type": "application/json"
|
| 1999 |
+
},
|
| 2000 |
+
json={
|
| 2001 |
+
"model": model or "claude-3-5-haiku-20241022",
|
| 2002 |
+
"max_tokens": 2048,
|
| 2003 |
+
"messages": [{"role": "user", "content": prompt}]
|
| 2004 |
+
}
|
| 2005 |
+
)
|
| 2006 |
+
if res.status_code == 200:
|
| 2007 |
+
raw = res.json()["content"][0]["text"]
|
| 2008 |
+
match = re.search(r'\{.*\}', raw, re.DOTALL)
|
| 2009 |
+
if match:
|
| 2010 |
+
parsed = json.loads(match.group(0))
|
| 2011 |
+
discovered_candidates = parsed.get("channels", [])
|
| 2012 |
+
else:
|
| 2013 |
+
if queue:
|
| 2014 |
+
await queue.put({"type": "error", "msg": f"Claude error ({res.status_code}): {res.text[:120]}"})
|
| 2015 |
+
return []
|
| 2016 |
+
|
| 2017 |
+
elif prov == "openrouter":
|
| 2018 |
+
res = await client.post(
|
| 2019 |
+
"https://openrouter.ai/api/v1/chat/completions",
|
| 2020 |
+
headers={
|
| 2021 |
+
"Authorization": f"Bearer {key}",
|
| 2022 |
+
"Content-Type": "application/json",
|
| 2023 |
+
"HTTP-Referer": "https://arkitel.com",
|
| 2024 |
+
"X-Title": "ArkiTel"
|
| 2025 |
+
},
|
| 2026 |
+
json={
|
| 2027 |
+
"model": model or "openai/gpt-4o-mini",
|
| 2028 |
+
"messages": [
|
| 2029 |
+
{"role": "system", "content": "You are a Telegram directory and web intelligence engine. Output valid JSON only."},
|
| 2030 |
+
{"role": "user", "content": prompt}
|
| 2031 |
+
],
|
| 2032 |
+
"temperature": 0.5
|
| 2033 |
+
}
|
| 2034 |
+
)
|
| 2035 |
+
if res.status_code == 200:
|
| 2036 |
+
raw = res.json()["choices"][0]["message"]["content"]
|
| 2037 |
+
match = re.search(r'\{.*\}', raw, re.DOTALL)
|
| 2038 |
+
if match:
|
| 2039 |
+
parsed = json.loads(match.group(0))
|
| 2040 |
+
discovered_candidates = parsed.get("channels", [])
|
| 2041 |
+
else:
|
| 2042 |
+
if queue:
|
| 2043 |
+
await queue.put({"type": "error", "msg": f"OpenRouter error ({res.status_code}): {res.text[:120]}"})
|
| 2044 |
+
return []
|
| 2045 |
+
except Exception as e:
|
| 2046 |
+
if queue:
|
| 2047 |
+
await queue.put({"type": "error", "msg": f"AI Web Discovery exception: {str(e)}"})
|
| 2048 |
+
return []
|
| 2049 |
+
|
| 2050 |
+
# Also extract any handles matching regex from raw response if JSON extraction was sparse
|
| 2051 |
+
handles_to_verify: List[Dict[str, str]] = []
|
| 2052 |
+
for cand in discovered_candidates:
|
| 2053 |
+
u = cand.get("username", "").replace("@", "").strip()
|
| 2054 |
+
if u and len(u) >= 4 and u.lower() not in seen:
|
| 2055 |
+
seen.add(u.lower())
|
| 2056 |
+
handles_to_verify.append({
|
| 2057 |
+
"username": u,
|
| 2058 |
+
"title": cand.get("title") or u,
|
| 2059 |
+
"type": cand.get("type") or "channel"
|
| 2060 |
+
})
|
| 2061 |
+
|
| 2062 |
+
if queue:
|
| 2063 |
+
await queue.put({
|
| 2064 |
+
"type": "progress",
|
| 2065 |
+
"msg": f"AI Web Discovery: {len(handles_to_verify)} public handles discovered. Verifying live subscriber data..."
|
| 2066 |
+
})
|
| 2067 |
+
|
| 2068 |
+
# Concurrently verify live status and subscriber counts using verify_telegram_info
|
| 2069 |
+
semaphore = asyncio.Semaphore(6)
|
| 2070 |
+
async def verify_and_stream(cand):
|
| 2071 |
+
u = cand["username"]
|
| 2072 |
+
async with semaphore:
|
| 2073 |
+
try:
|
| 2074 |
+
v_info = await verify_telegram_info(u)
|
| 2075 |
+
if not v_info["exists"]:
|
| 2076 |
+
return
|
| 2077 |
+
|
| 2078 |
+
title = v_info.get("title") or cand["title"]
|
| 2079 |
+
# Apply anti-spam relevance check
|
| 2080 |
+
if not is_relevant_channel(title, u, base_query):
|
| 2081 |
+
return
|
| 2082 |
+
|
| 2083 |
+
item = {
|
| 2084 |
+
"id": f"@{u}",
|
| 2085 |
+
"title": title,
|
| 2086 |
+
"username": u,
|
| 2087 |
+
"participants_count": v_info.get("participants_count", 0),
|
| 2088 |
+
"type": cand["type"],
|
| 2089 |
+
"is_private": False,
|
| 2090 |
+
"country": country or "Global",
|
| 2091 |
+
"global_shows": 1,
|
| 2092 |
+
"user_shows": 1,
|
| 2093 |
+
"source": f"ai_{prov}"
|
| 2094 |
+
}
|
| 2095 |
+
results.append(item)
|
| 2096 |
+
if user_id:
|
| 2097 |
+
save_scraped_group(user_id, item)
|
| 2098 |
+
if queue:
|
| 2099 |
+
await queue.put({"type": "result", "layer": "AI Intelligence", "data": item})
|
| 2100 |
+
except Exception as e:
|
| 2101 |
+
pass
|
| 2102 |
+
|
| 2103 |
+
await asyncio.gather(*[verify_and_stream(c) for c in handles_to_verify], return_exceptions=True)
|
| 2104 |
+
|
| 2105 |
+
if queue:
|
| 2106 |
+
await queue.put({
|
| 2107 |
+
"type": "progress",
|
| 2108 |
+
"msg": f"AI Web Discovery complete: Verified {len(results)} active communities."
|
| 2109 |
+
})
|
| 2110 |
+
|
| 2111 |
+
return results
|
| 2112 |
+
|
| 2113 |
+
|
| 2114 |
@app.get("/api/telegram/scrape_stream")
|
| 2115 |
async def scrape_keyword_stream(
|
| 2116 |
query: str,
|
|
|
|
| 2118 |
limit: int = 100,
|
| 2119 |
phone_number: Optional[str] = None,
|
| 2120 |
mode: Optional[str] = "fixed",
|
| 2121 |
+
ai_provider: Optional[str] = None,
|
| 2122 |
+
ai_key: Optional[str] = None,
|
| 2123 |
+
ai_model: Optional[str] = None,
|
| 2124 |
user_id: str = Depends(get_current_user_id)
|
| 2125 |
):
|
| 2126 |
conn = get_db_connection()
|
|
|
|
| 2192 |
# Use ALL active accounts to maximize yield for the sweep
|
| 2193 |
rows = conn.execute("SELECT session_string, api_id, api_hash, phone_number FROM accounts WHERE user_id = ? AND status = 'active' ORDER BY is_active DESC", (user_id,)).fetchall()
|
| 2194 |
if hasattr(conn, "close"): conn.close()
|
| 2195 |
+
if not rows and mode != "ai":
|
| 2196 |
+
raise HTTPException(status_code=404, detail="No active accounts found.")
|
| 2197 |
|
| 2198 |
base_query = query.strip()
|
| 2199 |
if country:
|
|
|
|
| 2204 |
async def scraper_task():
|
| 2205 |
try:
|
| 2206 |
search_mode = (mode or "fixed").lower().strip()
|
|
|
|
|
|
|
| 2207 |
|
| 2208 |
+
if search_mode == "ai":
|
| 2209 |
+
# AI Scraper: Uses configured AI model for web & directory discovery
|
| 2210 |
+
await queue.put({"type": "progress", "msg": f"Initializing AI Web Discovery Engine for '{base_query}'..."})
|
| 2211 |
+
await _scrape_ai_web_discovery(
|
| 2212 |
+
base_query=base_query,
|
| 2213 |
+
country=country,
|
| 2214 |
+
queue=queue,
|
| 2215 |
+
user_id=user_id,
|
| 2216 |
+
provider=ai_provider or "openai",
|
| 2217 |
+
api_key=ai_key or "",
|
| 2218 |
+
model=ai_model,
|
| 2219 |
+
rows=rows
|
| 2220 |
+
)
|
| 2221 |
+
await queue.put({"type": "done", "msg": "AI Scrape completed"})
|
| 2222 |
+
return
|
| 2223 |
+
|
| 2224 |
+
if search_mode == "free":
|
| 2225 |
+
# Free Mode: Pure natural keyword search (No spidering, no cross-contamination)
|
| 2226 |
+
await queue.put({"type": "progress", "msg": f"Layer 1 & 2: Natural Telegram Search & Lyzem Engine for '{base_query}'..."})
|
| 2227 |
+
t_task = asyncio.create_task(_scrape_telegram_search(base_query, rows, queue, user_id, mode="free"))
|
| 2228 |
+
l_task = asyncio.create_task(_scrape_lyzem(base_query, 10, queue, user_id))
|
| 2229 |
+
await asyncio.gather(t_task, l_task, return_exceptions=True)
|
| 2230 |
+
await queue.put({"type": "done", "msg": "Natural search completed"})
|
| 2231 |
+
return
|
| 2232 |
+
|
| 2233 |
+
# Fixed Mode: 60+ Universal variations + Lyzem + Spider (with relevance verification)
|
| 2234 |
+
await queue.put({"type": "progress", "msg": f"Layer 1 & 2: 60+ Suffix Sweep & Lyzem Engine for '{base_query}'..."})
|
| 2235 |
+
t_task = asyncio.create_task(_scrape_telegram_search(base_query, rows, queue, user_id, mode="fixed"))
|
| 2236 |
l_task = asyncio.create_task(_scrape_lyzem(base_query, 10, queue, user_id))
|
| 2237 |
t_res, l_res = await asyncio.gather(t_task, l_task, return_exceptions=True)
|
| 2238 |
|
|
|
|
| 2242 |
k = f"@{item.get('username', '')}"
|
| 2243 |
if k not in ug and item.get('username'): ug[k] = item
|
| 2244 |
|
| 2245 |
+
await queue.put({"type": "progress", "msg": f"Layer 3: Spidering {len(ug)} prominent groups (Relevance verified)..."})
|
| 2246 |
+
await _scrape_spider(list(ug.values()), rows, 15, queue, user_id, base_query=base_query)
|
|
|
|
|
|
|
| 2247 |
|
| 2248 |
+
await queue.put({"type": "done", "msg": "Fixed mode sweep completed"})
|
| 2249 |
except asyncio.CancelledError:
|
| 2250 |
print("SCRAPER_STREAM canceled by client disconnect")
|
| 2251 |
raise
|
| 2252 |
except Exception as e:
|
| 2253 |
+
await queue.put({"type": "error", "msg": str(e)})
|
| 2254 |
|
| 2255 |
# Start explicitly outside event_generator
|
| 2256 |
bg_task = asyncio.create_task(scraper_task())
|
|
|
|
| 3775 |
key = (req.api_key or "").strip()
|
| 3776 |
target_count = max(10, min(50, req.count or 30))
|
| 3777 |
|
| 3778 |
+
if not key:
|
| 3779 |
+
raise HTTPException(
|
| 3780 |
+
status_code=400,
|
| 3781 |
+
detail="No AI API key configured. Please click 'AI Provider' to connect your OpenAI, Claude, or OpenRouter key first."
|
| 3782 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3783 |
|
| 3784 |
ai_keywords: List[str] = []
|
| 3785 |
error_note = None
|
| 3786 |
|
| 3787 |
+
async with httpx.AsyncClient(timeout=25.0) as client:
|
| 3788 |
+
prompt = (
|
| 3789 |
+
f"You are a Telegram search & lead generation intelligence specialist. "
|
| 3790 |
+
f"Generate exactly {target_count} highly targeted, natural Telegram search keywords, "
|
| 3791 |
+
f"phrases, and community terms for the niche: '{seed}'. "
|
| 3792 |
+
f"These must be terms that active Telegram groups, channels, and communities actually use in their titles/usernames. "
|
| 3793 |
+
f"Return ONLY a valid JSON array of strings (e.g. [\"keyword 1\", \"keyword 2\"]). "
|
| 3794 |
+
f"Do not include any other markdown formatting, explanation, or code fences."
|
| 3795 |
+
)
|
| 3796 |
+
|
| 3797 |
+
try:
|
| 3798 |
+
if provider == "openai":
|
| 3799 |
+
res = await client.post(
|
| 3800 |
+
"https://api.openai.com/v1/chat/completions",
|
| 3801 |
+
headers={"Authorization": f"Bearer {key}", "Content-Type": "application/json"},
|
| 3802 |
+
json={
|
| 3803 |
+
"model": req.model or "gpt-4o-mini",
|
| 3804 |
+
"messages": [
|
| 3805 |
+
{"role": "system", "content": "You are a Telegram keyword intelligence engine. Output only JSON arrays."},
|
| 3806 |
+
{"role": "user", "content": prompt}
|
| 3807 |
+
],
|
| 3808 |
+
"temperature": 0.7
|
| 3809 |
+
}
|
| 3810 |
+
)
|
| 3811 |
+
if res.status_code == 200:
|
| 3812 |
+
data = res.json()
|
| 3813 |
+
raw_content = data["choices"][0]["message"]["content"]
|
| 3814 |
+
match = re.search(r'\[.*\]', raw_content, re.DOTALL)
|
| 3815 |
+
if match:
|
| 3816 |
+
ai_keywords = json.loads(match.group(0))
|
| 3817 |
+
else:
|
| 3818 |
+
error_note = f"OpenAI error ({res.status_code}): {res.text[:120]}"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3819 |
|
| 3820 |
+
elif provider in ("anthropic", "claude"):
|
| 3821 |
+
res = await client.post(
|
| 3822 |
+
"https://api.anthropic.com/v1/messages",
|
| 3823 |
+
headers={
|
| 3824 |
+
"x-api-key": key,
|
| 3825 |
+
"anthropic-version": "2023-06-01",
|
| 3826 |
+
"content-type": "application/json"
|
| 3827 |
+
},
|
| 3828 |
+
json={
|
| 3829 |
+
"model": req.model or "claude-3-5-haiku-20241022",
|
| 3830 |
+
"max_tokens": 1200,
|
| 3831 |
+
"messages": [{"role": "user", "content": prompt}]
|
| 3832 |
+
}
|
| 3833 |
+
)
|
| 3834 |
+
if res.status_code == 200:
|
| 3835 |
+
data = res.json()
|
| 3836 |
+
raw_content = data["content"][0]["text"]
|
| 3837 |
+
match = re.search(r'\[.*\]', raw_content, re.DOTALL)
|
| 3838 |
+
if match:
|
| 3839 |
+
ai_keywords = json.loads(match.group(0))
|
| 3840 |
+
else:
|
| 3841 |
+
error_note = f"Claude error ({res.status_code}): {res.text[:120]}"
|
| 3842 |
+
|
| 3843 |
+
elif provider == "openrouter":
|
| 3844 |
+
res = await client.post(
|
| 3845 |
+
"https://openrouter.ai/api/v1/chat/completions",
|
| 3846 |
+
headers={
|
| 3847 |
+
"Authorization": f"Bearer {key}",
|
| 3848 |
+
"Content-Type": "application/json",
|
| 3849 |
+
"HTTP-Referer": "https://arkitel.com",
|
| 3850 |
+
"X-Title": "ArkiTel"
|
| 3851 |
+
},
|
| 3852 |
+
json={
|
| 3853 |
+
"model": req.model or "openai/gpt-4o-mini",
|
| 3854 |
+
"messages": [
|
| 3855 |
+
{"role": "system", "content": "You are a Telegram keyword intelligence engine. Output only JSON arrays."},
|
| 3856 |
+
{"role": "user", "content": prompt}
|
| 3857 |
+
],
|
| 3858 |
+
"temperature": 0.7
|
| 3859 |
+
}
|
| 3860 |
+
)
|
| 3861 |
+
if res.status_code == 200:
|
| 3862 |
+
data = res.json()
|
| 3863 |
+
raw_content = data["choices"][0]["message"]["content"]
|
| 3864 |
+
match = re.search(r'\[.*\]', raw_content, re.DOTALL)
|
| 3865 |
+
if match:
|
| 3866 |
+
ai_keywords = json.loads(match.group(0))
|
| 3867 |
+
else:
|
| 3868 |
+
error_note = f"OpenRouter error ({res.status_code}): {res.text[:120]}"
|
| 3869 |
+
except Exception as e:
|
| 3870 |
+
error_note = f"AI request exception: {str(e)}"
|
| 3871 |
+
|
| 3872 |
+
if error_note and not ai_keywords:
|
| 3873 |
+
raise HTTPException(status_code=400, detail=f"AI Suggestion failed: {error_note}")
|
| 3874 |
+
|
| 3875 |
+
# Clean and deduplicate AI returned strings
|
| 3876 |
clean_keywords: List[str] = []
|
| 3877 |
+
seen = set()
|
| 3878 |
+
for k in (ai_keywords or []):
|
| 3879 |
+
if isinstance(k, str) and k.strip():
|
| 3880 |
+
ks = k.strip().strip('"\'')
|
| 3881 |
+
if ks.lower() not in seen:
|
| 3882 |
+
seen.add(ks.lower())
|
| 3883 |
+
clean_keywords.append(ks)
|
| 3884 |
+
|
| 3885 |
+
if not clean_keywords:
|
| 3886 |
+
raise HTTPException(status_code=400, detail="AI returned an empty keyword list. Please try a different seed or model.")
|
|
|
|
|
|
|
| 3887 |
|
| 3888 |
return {
|
| 3889 |
"seed": seed,
|
| 3890 |
"keywords": clean_keywords,
|
| 3891 |
"total": len(clean_keywords),
|
| 3892 |
+
"source": f"ai_{provider}",
|
| 3893 |
+
"provider": provider
|
|
|
|
| 3894 |
}
|
| 3895 |
|
| 3896 |
@app.delete("/api/admin/users/{user_id}")
|
frontend/src/app/admin/page.tsx
CHANGED
|
@@ -1197,73 +1197,82 @@ export default function AdminDashboard() {
|
|
| 1197 |
</div>
|
| 1198 |
)}
|
| 1199 |
|
| 1200 |
-
{/* TAB 5: MONETIZATION (
|
| 1201 |
{activeTab === 'monetization' && (
|
| 1202 |
<div className="space-y-8">
|
| 1203 |
-
|
| 1204 |
-
|
| 1205 |
-
<div className="
|
| 1206 |
<div className="flex items-center gap-3">
|
| 1207 |
<div className="p-3 bg-indigo-500/10 rounded-2xl text-indigo-400">
|
| 1208 |
<Ticket size={24} />
|
| 1209 |
</div>
|
| 1210 |
<div>
|
| 1211 |
-
<h3 className="font-bold text-xl">Create Coupon</h3>
|
| 1212 |
-
<p className="text-xs text-foreground/
|
| 1213 |
</div>
|
| 1214 |
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1215 |
|
| 1216 |
-
|
| 1217 |
-
|
| 1218 |
-
|
| 1219 |
-
|
| 1220 |
-
|
| 1221 |
-
|
| 1222 |
-
|
| 1223 |
-
|
| 1224 |
-
|
| 1225 |
-
|
| 1226 |
-
|
| 1227 |
-
|
| 1228 |
-
|
| 1229 |
-
<
|
| 1230 |
-
|
| 1231 |
-
|
| 1232 |
-
|
| 1233 |
-
|
| 1234 |
-
|
| 1235 |
-
|
| 1236 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1237 |
</div>
|
| 1238 |
-
|
|
|
|
| 1239 |
<div className="space-y-1">
|
| 1240 |
-
<label className="text-[9px] font-bold text-foreground/40 uppercase tracking-widest px-1">Max Camp</label>
|
| 1241 |
<input
|
| 1242 |
type="number"
|
| 1243 |
-
placeholder="
|
| 1244 |
value={newCoupon.max_daily_campaigns}
|
| 1245 |
onChange={(e) => setNewCoupon({...newCoupon, max_daily_campaigns: e.target.value})}
|
| 1246 |
-
className="w-full bg-white/5 border border-white/10 rounded-
|
| 1247 |
/>
|
| 1248 |
</div>
|
| 1249 |
<div className="space-y-1">
|
| 1250 |
-
<label className="text-[9px] font-bold text-foreground/40 uppercase tracking-widest px-1">Max Key</label>
|
| 1251 |
<input
|
| 1252 |
type="number"
|
| 1253 |
-
placeholder="
|
| 1254 |
value={newCoupon.max_daily_keywords}
|
| 1255 |
onChange={(e) => setNewCoupon({...newCoupon, max_daily_keywords: e.target.value})}
|
| 1256 |
-
className="w-full bg-white/5 border border-white/10 rounded-
|
| 1257 |
/>
|
| 1258 |
</div>
|
| 1259 |
<div className="space-y-1">
|
| 1260 |
<label className="text-[9px] font-bold text-foreground/40 uppercase tracking-widest px-1">Scrape Limit</label>
|
| 1261 |
<input
|
| 1262 |
type="number"
|
| 1263 |
-
placeholder="
|
| 1264 |
value={newCoupon.scrape_limit}
|
| 1265 |
onChange={(e) => setNewCoupon({...newCoupon, scrape_limit: e.target.value})}
|
| 1266 |
-
className="w-full bg-white/5 border border-white/10 rounded-
|
| 1267 |
/>
|
| 1268 |
</div>
|
| 1269 |
</div>
|
|
@@ -1276,26 +1285,29 @@ export default function AdminDashboard() {
|
|
| 1276 |
body: JSON.stringify(newCoupon)
|
| 1277 |
});
|
| 1278 |
if (res.ok) {
|
| 1279 |
-
setSuccessMsg(`Coupon ${newCoupon.code} generated.`);
|
| 1280 |
setNewCoupon({ code: '', price: 5000, max_daily_campaigns: '', max_daily_keywords: '', scrape_limit: '' });
|
| 1281 |
fetchMonetizationData();
|
| 1282 |
}
|
| 1283 |
}}
|
| 1284 |
-
className="w-full py-3
|
| 1285 |
>
|
| 1286 |
-
Issue Access
|
| 1287 |
</button>
|
| 1288 |
</div>
|
| 1289 |
|
| 1290 |
-
{/* Active
|
| 1291 |
-
<div className="
|
| 1292 |
-
<h4 className="text-xs font-bold uppercase tracking-wider text-foreground/40
|
| 1293 |
-
|
|
|
|
|
|
|
|
|
|
| 1294 |
{coupons.map((c) => (
|
| 1295 |
<div key={c.id || c.code} className="flex items-center justify-between p-2.5 bg-white/5 rounded-xl border border-white/5 text-xs">
|
| 1296 |
<div>
|
| 1297 |
<span className="font-mono font-bold text-indigo-400">{c.code}</span>
|
| 1298 |
-
<div className="text-[10px] text-foreground/40 font-mono">#{c.price.toLocaleString()} • {c.claimed_by ? `Claimed
|
| 1299 |
</div>
|
| 1300 |
<button
|
| 1301 |
onClick={async () => {
|
|
@@ -1309,253 +1321,253 @@ export default function AdminDashboard() {
|
|
| 1309 |
</button>
|
| 1310 |
</div>
|
| 1311 |
))}
|
| 1312 |
-
{coupons.length === 0 && <div className="text-[10px] text-center text-foreground/30 italic py-
|
| 1313 |
</div>
|
| 1314 |
</div>
|
| 1315 |
</div>
|
|
|
|
| 1316 |
|
| 1317 |
-
|
| 1318 |
-
|
| 1319 |
-
|
| 1320 |
-
|
| 1321 |
-
|
| 1322 |
-
|
| 1323 |
-
</div>
|
| 1324 |
-
<div>
|
| 1325 |
-
<h3 className="font-bold text-xl">Monetization Registry</h3>
|
| 1326 |
-
<p className="text-xs text-foreground/45 uppercase font-bold tracking-widest mt-0.5">Streamlined plan limits, payment approvals & usage capsules</p>
|
| 1327 |
-
</div>
|
| 1328 |
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1329 |
|
| 1330 |
-
|
| 1331 |
-
|
| 1332 |
-
|
| 1333 |
-
|
| 1334 |
-
|
| 1335 |
-
|
| 1336 |
-
|
| 1337 |
-
|
| 1338 |
-
|
| 1339 |
-
|
| 1340 |
-
|
| 1341 |
-
|
| 1342 |
-
|
| 1343 |
-
|
| 1344 |
-
|
| 1345 |
-
|
| 1346 |
-
|
| 1347 |
-
|
| 1348 |
-
</div>
|
| 1349 |
-
<span className="text-xs font-mono px-3 py-1.5 rounded-full bg-red-500/10 text-red-400 border border-red-500/20 font-bold">
|
| 1350 |
-
{filteredMonoUsers.length} Users
|
| 1351 |
-
</span>
|
| 1352 |
</div>
|
|
|
|
|
|
|
|
|
|
| 1353 |
</div>
|
|
|
|
| 1354 |
|
| 1355 |
-
|
| 1356 |
-
|
| 1357 |
-
|
| 1358 |
-
|
| 1359 |
-
|
| 1360 |
-
|
| 1361 |
-
|
| 1362 |
-
|
| 1363 |
-
|
| 1364 |
-
|
| 1365 |
-
|
| 1366 |
-
|
| 1367 |
-
|
| 1368 |
-
|
| 1369 |
-
|
| 1370 |
-
|
| 1371 |
-
|
| 1372 |
-
|
| 1373 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1374 |
|
| 1375 |
-
|
| 1376 |
-
|
| 1377 |
-
|
| 1378 |
-
|
| 1379 |
-
|
| 1380 |
-
|
| 1381 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1382 |
const now = new Date();
|
| 1383 |
const expires = new Date(now);
|
| 1384 |
expires.setDate(expires.getDate() + 30);
|
| 1385 |
setMonetizationUsers(prev => prev.map(mu =>
|
| 1386 |
mu.id === u.id ? {
|
| 1387 |
...mu,
|
| 1388 |
-
|
| 1389 |
-
|
| 1390 |
-
plan_activated_at:
|
| 1391 |
-
plan_expires_at:
|
| 1392 |
} : mu
|
| 1393 |
));
|
| 1394 |
const res = await apiFetch(`/api/admin/monetization/users/${u.id}/vitals`, {
|
| 1395 |
method: 'POST',
|
| 1396 |
-
body: JSON.stringify({ plan:
|
| 1397 |
});
|
| 1398 |
if (res.ok) {
|
| 1399 |
-
setSuccessMsg(`
|
| 1400 |
-
setTimeout(() => setSuccessMsg(''),
|
| 1401 |
} else {
|
| 1402 |
-
setErrorMsg('
|
| 1403 |
setTimeout(() => setErrorMsg(''), 4000);
|
| 1404 |
}
|
| 1405 |
fetchMonetizationData();
|
| 1406 |
-
}
|
| 1407 |
-
|
| 1408 |
-
|
| 1409 |
-
|
| 1410 |
-
|
| 1411 |
-
|
| 1412 |
-
|
| 1413 |
-
|
| 1414 |
-
</
|
| 1415 |
-
|
| 1416 |
-
|
| 1417 |
-
|
| 1418 |
-
|
| 1419 |
-
|
| 1420 |
-
|
| 1421 |
-
|
| 1422 |
-
|
| 1423 |
-
|
| 1424 |
-
|
| 1425 |
-
|
| 1426 |
-
|
| 1427 |
-
|
| 1428 |
-
|
| 1429 |
-
|
| 1430 |
-
|
| 1431 |
-
|
| 1432 |
-
⚡ {u.daily_campaign_count ?? 0}/{u.max_daily_campaigns ?? 20}
|
| 1433 |
-
</span>
|
| 1434 |
-
<span
|
| 1435 |
-
className="px-2 py-0.5 rounded-lg bg-emerald-500/10 text-emerald-400 font-mono text-[10px] font-bold border border-emerald-500/20"
|
| 1436 |
-
title="Daily Keyword Searches: Used / Max"
|
| 1437 |
-
>
|
| 1438 |
-
🔍 {u.daily_keyword_count ?? 0}/{u.max_daily_keywords ?? 5}
|
| 1439 |
-
</span>
|
| 1440 |
-
<span
|
| 1441 |
-
className="px-2 py-0.5 rounded-lg bg-amber-500/10 text-amber-400 font-mono text-[10px] font-bold border border-amber-500/20"
|
| 1442 |
-
title="Scrape Leads Limit"
|
| 1443 |
-
>
|
| 1444 |
-
📥 {u.scrape_limit ?? 100}
|
| 1445 |
-
</span>
|
| 1446 |
-
<span
|
| 1447 |
-
className="px-2 py-0.5 rounded-lg bg-blue-500/10 text-blue-400 font-mono text-[10px] font-bold border border-blue-500/20"
|
| 1448 |
-
title="Max Telegram Accounts"
|
| 1449 |
-
>
|
| 1450 |
-
📱 {u.max_accounts ?? 1}
|
| 1451 |
-
</span>
|
| 1452 |
-
<span
|
| 1453 |
-
className="px-2 py-0.5 rounded-lg bg-rose-500/10 text-rose-400 font-mono text-[10px] font-bold border border-rose-500/20"
|
| 1454 |
-
title="Max Templates Allowed"
|
| 1455 |
-
>
|
| 1456 |
-
📝 {u.max_templates || 1}
|
| 1457 |
-
</span>
|
| 1458 |
-
</div>
|
| 1459 |
-
</td>
|
| 1460 |
-
|
| 1461 |
-
<td className="px-5 py-3.5">
|
| 1462 |
-
{u.payment_proof ? (
|
| 1463 |
-
<div className="max-w-[140px] space-y-0.5">
|
| 1464 |
-
<div className="text-[10px] font-medium text-emerald-400 truncate bg-emerald-500/10 px-2 py-0.5 rounded-lg border border-emerald-500/20" title={u.payment_proof}>
|
| 1465 |
-
{u.payment_proof}
|
| 1466 |
-
</div>
|
| 1467 |
-
<div className="text-[8px] text-foreground/40 uppercase font-bold text-center">Submitted</div>
|
| 1468 |
-
</div>
|
| 1469 |
-
) : (
|
| 1470 |
-
<span className="text-[10px] text-foreground/30 italic">No proof</span>
|
| 1471 |
-
)}
|
| 1472 |
-
</td>
|
| 1473 |
|
| 1474 |
-
|
| 1475 |
-
|
| 1476 |
-
|
| 1477 |
-
|
| 1478 |
-
|
| 1479 |
-
|
| 1480 |
-
const now = new Date();
|
| 1481 |
-
const expires = new Date(now);
|
| 1482 |
-
expires.setDate(expires.getDate() + 30);
|
| 1483 |
-
setMonetizationUsers(prev => prev.map(mu =>
|
| 1484 |
-
mu.id === u.id ? {
|
| 1485 |
-
...mu,
|
| 1486 |
-
is_approved: 1,
|
| 1487 |
-
plan: planToApprove,
|
| 1488 |
-
plan_activated_at: now.toISOString(),
|
| 1489 |
-
plan_expires_at: expires.toISOString()
|
| 1490 |
-
} : mu
|
| 1491 |
-
));
|
| 1492 |
-
const res = await apiFetch(`/api/admin/monetization/users/${u.id}/vitals`, {
|
| 1493 |
-
method: 'POST',
|
| 1494 |
-
body: JSON.stringify({ plan: planToApprove, is_approved: 1 })
|
| 1495 |
-
});
|
| 1496 |
-
if (res.ok) {
|
| 1497 |
-
setSuccessMsg(`Approved ${u.username} on ${planToApprove}!`);
|
| 1498 |
-
setTimeout(() => setSuccessMsg(''), 5000);
|
| 1499 |
-
} else {
|
| 1500 |
-
setErrorMsg('Approval failed.');
|
| 1501 |
-
setTimeout(() => setErrorMsg(''), 4000);
|
| 1502 |
-
}
|
| 1503 |
-
fetchMonetizationData();
|
| 1504 |
-
}
|
| 1505 |
-
}}
|
| 1506 |
-
className="flex items-center gap-1 px-3 py-1.5 rounded-lg bg-emerald-500 text-black text-[10px] font-extrabold uppercase transition-all hover:bg-emerald-400 active:scale-95 shadow-lg shadow-emerald-500/20 cursor-pointer"
|
| 1507 |
-
>
|
| 1508 |
-
<CheckCircle2 size={12} /> Approve
|
| 1509 |
-
</button>
|
| 1510 |
-
) : u.is_approved === 1 ? (
|
| 1511 |
-
<span className="text-[10px] text-emerald-400 font-bold inline-flex items-center gap-1 px-2 py-0.5 rounded-full bg-emerald-500/10 border border-emerald-500/20">
|
| 1512 |
-
<CheckCircle2 size={11} /> Approved
|
| 1513 |
-
</span>
|
| 1514 |
-
) : (
|
| 1515 |
-
<span className="text-[10px] text-foreground/30 font-medium italic">Pending</span>
|
| 1516 |
-
)}
|
| 1517 |
-
</td>
|
| 1518 |
-
</tr>
|
| 1519 |
-
))}
|
| 1520 |
-
{pagedMonoUsers.length === 0 && (
|
| 1521 |
-
<tr>
|
| 1522 |
-
<td colSpan={5} className="px-5 py-12 text-center text-foreground/30 italic">
|
| 1523 |
-
No monetization records matching search
|
| 1524 |
-
</td>
|
| 1525 |
-
</tr>
|
| 1526 |
-
)}
|
| 1527 |
-
</tbody>
|
| 1528 |
-
</table>
|
| 1529 |
</div>
|
| 1530 |
-
|
| 1531 |
-
|
| 1532 |
-
|
| 1533 |
-
|
| 1534 |
-
|
| 1535 |
-
|
| 1536 |
-
<
|
| 1537 |
-
|
| 1538 |
-
<
|
| 1539 |
-
|
| 1540 |
-
|
| 1541 |
-
|
| 1542 |
-
|
| 1543 |
-
>
|
| 1544 |
-
|
| 1545 |
-
|
| 1546 |
-
|
| 1547 |
-
<span
|
| 1548 |
-
|
| 1549 |
-
|
| 1550 |
-
<button
|
| 1551 |
-
onClick={() => setMonoPage(prev => Math.min(totalMonoPages, prev + 1))}
|
| 1552 |
-
disabled={monoPage >= totalMonoPages}
|
| 1553 |
-
className="px-3 py-1.5 rounded-xl bg-white/5 hover:bg-white/10 border border-white/10 text-foreground font-bold flex items-center gap-1.5 disabled:opacity-30 disabled:pointer-events-none transition-all cursor-pointer"
|
| 1554 |
-
>
|
| 1555 |
-
<span>Next</span>
|
| 1556 |
-
<ChevronRight size={14} />
|
| 1557 |
-
</button>
|
| 1558 |
-
</div>
|
| 1559 |
</div>
|
| 1560 |
</div>
|
| 1561 |
</div>
|
|
@@ -1597,9 +1609,16 @@ export default function AdminDashboard() {
|
|
| 1597 |
</button>
|
| 1598 |
)}
|
| 1599 |
</div>
|
| 1600 |
-
<
|
| 1601 |
-
|
| 1602 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1603 |
</div>
|
| 1604 |
</div>
|
| 1605 |
|
|
|
|
| 1197 |
</div>
|
| 1198 |
)}
|
| 1199 |
|
| 1200 |
+
{/* TAB 5: MONETIZATION (CREATE COUPON ON TOP, REGISTRY UNDERNEATH FOR OPTIMAL SPACE) */}
|
| 1201 |
{activeTab === 'monetization' && (
|
| 1202 |
<div className="space-y-8">
|
| 1203 |
+
{/* TOP: Coupon Management Console (Full Width) */}
|
| 1204 |
+
<div className="bg-white/5 border border-white/10 p-6 sm:p-8 rounded-[32px] shadow-2xl space-y-6">
|
| 1205 |
+
<div className="flex flex-col sm:flex-row sm:items-center justify-between gap-4 border-b border-white/10 pb-5">
|
| 1206 |
<div className="flex items-center gap-3">
|
| 1207 |
<div className="p-3 bg-indigo-500/10 rounded-2xl text-indigo-400">
|
| 1208 |
<Ticket size={24} />
|
| 1209 |
</div>
|
| 1210 |
<div>
|
| 1211 |
+
<h3 className="font-bold text-xl">Create Coupon & Access Vouchers</h3>
|
| 1212 |
+
<p className="text-xs text-foreground/45 uppercase font-bold tracking-widest mt-0.5">Generate customized promotional or automatic plan activation codes</p>
|
| 1213 |
</div>
|
| 1214 |
</div>
|
| 1215 |
+
<span className="text-xs font-mono px-3 py-1.5 rounded-full bg-indigo-500/10 text-indigo-400 border border-indigo-500/20 font-bold self-start sm:self-auto">
|
| 1216 |
+
{coupons.length} Active Keys
|
| 1217 |
+
</span>
|
| 1218 |
+
</div>
|
| 1219 |
|
| 1220 |
+
<div className="grid grid-cols-1 lg:grid-cols-12 gap-8 items-start">
|
| 1221 |
+
{/* Left: Input Form Controls (8 Cols) */}
|
| 1222 |
+
<div className="lg:col-span-8 space-y-4">
|
| 1223 |
+
<div className="grid grid-cols-1 sm:grid-cols-2 gap-4">
|
| 1224 |
+
<div className="space-y-1.5">
|
| 1225 |
+
<label className="text-[10px] font-bold text-foreground/40 uppercase tracking-widest px-1">Coupon Code</label>
|
| 1226 |
+
<input
|
| 1227 |
+
type="text"
|
| 1228 |
+
placeholder="e.g. ARKITEL_VIP_FREE"
|
| 1229 |
+
value={newCoupon.code}
|
| 1230 |
+
onChange={(e) => setNewCoupon({...newCoupon, code: e.target.value.toUpperCase()})}
|
| 1231 |
+
className="w-full bg-white/5 border border-white/10 rounded-xl px-4 py-2.5 text-xs font-mono font-bold focus:ring-2 focus:ring-indigo-500/50 outline-none"
|
| 1232 |
+
/>
|
| 1233 |
+
</div>
|
| 1234 |
+
<div className="space-y-1.5">
|
| 1235 |
+
<label className="text-[10px] font-bold text-foreground/40 uppercase tracking-widest px-1">Set Price (#)</label>
|
| 1236 |
+
<input
|
| 1237 |
+
type="number"
|
| 1238 |
+
placeholder="0"
|
| 1239 |
+
value={newCoupon.price}
|
| 1240 |
+
onChange={(e) => setNewCoupon({...newCoupon, price: parseInt(e.target.value) || 0})}
|
| 1241 |
+
className="w-full bg-white/5 border border-white/10 rounded-xl px-4 py-2.5 text-xs font-mono focus:ring-2 focus:ring-indigo-500/50 outline-none"
|
| 1242 |
+
/>
|
| 1243 |
+
<p className="text-[9px] text-foreground/40 px-1 font-medium italic">* Set to 0 for a free automatic unlock code.</p>
|
| 1244 |
+
</div>
|
| 1245 |
</div>
|
| 1246 |
+
|
| 1247 |
+
<div className="grid grid-cols-3 gap-3 pt-2">
|
| 1248 |
<div className="space-y-1">
|
| 1249 |
+
<label className="text-[9px] font-bold text-foreground/40 uppercase tracking-widest px-1">Max Daily Camp</label>
|
| 1250 |
<input
|
| 1251 |
type="number"
|
| 1252 |
+
placeholder="Default..."
|
| 1253 |
value={newCoupon.max_daily_campaigns}
|
| 1254 |
onChange={(e) => setNewCoupon({...newCoupon, max_daily_campaigns: e.target.value})}
|
| 1255 |
+
className="w-full bg-white/5 border border-white/10 rounded-xl px-3 py-2 text-xs font-mono focus:ring-1 focus:ring-indigo-500/50 outline-none"
|
| 1256 |
/>
|
| 1257 |
</div>
|
| 1258 |
<div className="space-y-1">
|
| 1259 |
+
<label className="text-[9px] font-bold text-foreground/40 uppercase tracking-widest px-1">Max Daily Key</label>
|
| 1260 |
<input
|
| 1261 |
type="number"
|
| 1262 |
+
placeholder="Default..."
|
| 1263 |
value={newCoupon.max_daily_keywords}
|
| 1264 |
onChange={(e) => setNewCoupon({...newCoupon, max_daily_keywords: e.target.value})}
|
| 1265 |
+
className="w-full bg-white/5 border border-white/10 rounded-xl px-3 py-2 text-xs font-mono focus:ring-1 focus:ring-indigo-500/50 outline-none"
|
| 1266 |
/>
|
| 1267 |
</div>
|
| 1268 |
<div className="space-y-1">
|
| 1269 |
<label className="text-[9px] font-bold text-foreground/40 uppercase tracking-widest px-1">Scrape Limit</label>
|
| 1270 |
<input
|
| 1271 |
type="number"
|
| 1272 |
+
placeholder="Default..."
|
| 1273 |
value={newCoupon.scrape_limit}
|
| 1274 |
onChange={(e) => setNewCoupon({...newCoupon, scrape_limit: e.target.value})}
|
| 1275 |
+
className="w-full bg-white/5 border border-white/10 rounded-xl px-3 py-2 text-xs font-mono focus:ring-1 focus:ring-indigo-500/50 outline-none"
|
| 1276 |
/>
|
| 1277 |
</div>
|
| 1278 |
</div>
|
|
|
|
| 1285 |
body: JSON.stringify(newCoupon)
|
| 1286 |
});
|
| 1287 |
if (res.ok) {
|
| 1288 |
+
setSuccessMsg(`Coupon ${newCoupon.code} generated successfully.`);
|
| 1289 |
setNewCoupon({ code: '', price: 5000, max_daily_campaigns: '', max_daily_keywords: '', scrape_limit: '' });
|
| 1290 |
fetchMonetizationData();
|
| 1291 |
}
|
| 1292 |
}}
|
| 1293 |
+
className="w-full py-3 bg-indigo-500 hover:bg-indigo-400 text-white font-extrabold rounded-xl transition-all shadow-lg shadow-indigo-500/20 text-xs uppercase tracking-widest cursor-pointer active:scale-95"
|
| 1294 |
>
|
| 1295 |
+
Issue Access Coupon
|
| 1296 |
</button>
|
| 1297 |
</div>
|
| 1298 |
|
| 1299 |
+
{/* Right: Active Coupon Keys Stream (4 Cols) */}
|
| 1300 |
+
<div className="lg:col-span-4 bg-black/30 border border-white/5 p-4 rounded-2xl space-y-3">
|
| 1301 |
+
<h4 className="text-xs font-bold uppercase tracking-wider text-foreground/40 flex items-center justify-between">
|
| 1302 |
+
<span>Active Keys</span>
|
| 1303 |
+
<span className="font-mono text-indigo-400">{coupons.length}</span>
|
| 1304 |
+
</h4>
|
| 1305 |
+
<div className="space-y-2 max-h-48 overflow-y-auto custom-scrollbar pr-1">
|
| 1306 |
{coupons.map((c) => (
|
| 1307 |
<div key={c.id || c.code} className="flex items-center justify-between p-2.5 bg-white/5 rounded-xl border border-white/5 text-xs">
|
| 1308 |
<div>
|
| 1309 |
<span className="font-mono font-bold text-indigo-400">{c.code}</span>
|
| 1310 |
+
<div className="text-[10px] text-foreground/40 font-mono">#{c.price.toLocaleString()} • {c.claimed_by ? `Claimed: ${c.claimed_by}` : 'Available'}</div>
|
| 1311 |
</div>
|
| 1312 |
<button
|
| 1313 |
onClick={async () => {
|
|
|
|
| 1321 |
</button>
|
| 1322 |
</div>
|
| 1323 |
))}
|
| 1324 |
+
{coupons.length === 0 && <div className="text-[10px] text-center text-foreground/30 italic py-4">No active coupons issued</div>}
|
| 1325 |
</div>
|
| 1326 |
</div>
|
| 1327 |
</div>
|
| 1328 |
+
</div>
|
| 1329 |
|
| 1330 |
+
{/* UNDERNEATH: Full-Width Monetization Registry Card */}
|
| 1331 |
+
<div className="bg-white/5 border border-white/10 rounded-[32px] overflow-hidden flex flex-col shadow-2xl">
|
| 1332 |
+
<div className="p-6 sm:p-8 border-b border-white/10 flex flex-col sm:flex-row sm:items-center justify-between gap-4 bg-white/[0.01]">
|
| 1333 |
+
<div className="flex items-center gap-3">
|
| 1334 |
+
<div className="p-3 bg-red-500/10 rounded-2xl text-red-400">
|
| 1335 |
+
<CreditCard size={24} />
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1336 |
</div>
|
| 1337 |
+
<div>
|
| 1338 |
+
<h3 className="font-bold text-xl">Monetization Registry</h3>
|
| 1339 |
+
<p className="text-xs text-foreground/45 uppercase font-bold tracking-widest mt-0.5">Streamlined plan limits, payment approvals & usage capsules</p>
|
| 1340 |
+
</div>
|
| 1341 |
+
</div>
|
| 1342 |
|
| 1343 |
+
<div className="flex items-center gap-3">
|
| 1344 |
+
<div className="relative">
|
| 1345 |
+
<Search size={14} className="absolute left-3 top-1/2 -translate-y-1/2 text-foreground/40" />
|
| 1346 |
+
<input
|
| 1347 |
+
type="text"
|
| 1348 |
+
placeholder="Filter monetization..."
|
| 1349 |
+
value={monoSearch}
|
| 1350 |
+
onChange={(e) => {
|
| 1351 |
+
setMonoSearch(e.target.value);
|
| 1352 |
+
setMonoPage(1);
|
| 1353 |
+
}}
|
| 1354 |
+
className="pl-8 pr-3 py-1.5 rounded-xl bg-white/5 border border-white/10 text-xs text-foreground placeholder:text-foreground/30 focus:outline-none focus:border-red-500/50 w-44 sm:w-56 transition-all"
|
| 1355 |
+
/>
|
| 1356 |
+
{monoSearch && (
|
| 1357 |
+
<button onClick={() => setMonoSearch('')} className="absolute right-2.5 top-1/2 -translate-y-1/2 text-foreground/40 hover:text-foreground">
|
| 1358 |
+
<X size={12} />
|
| 1359 |
+
</button>
|
| 1360 |
+
)}
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1361 |
</div>
|
| 1362 |
+
<span className="text-xs font-mono px-3 py-1.5 rounded-full bg-red-500/10 text-red-400 border border-red-500/20 font-bold">
|
| 1363 |
+
{filteredMonoUsers.length} Users
|
| 1364 |
+
</span>
|
| 1365 |
</div>
|
| 1366 |
+
</div>
|
| 1367 |
|
| 1368 |
+
{/* Internal Scrollable Table Container */}
|
| 1369 |
+
<div className="overflow-x-auto max-h-[520px] overflow-y-auto custom-scrollbar flex-1">
|
| 1370 |
+
<table className="w-full text-left">
|
| 1371 |
+
<thead className="text-[10px] uppercase tracking-[0.2em] text-foreground/40 border-b border-white/10 sticky top-0 bg-[#0d0f12] z-10 shadow-sm">
|
| 1372 |
+
<tr>
|
| 1373 |
+
<th className="px-5 py-3.5 font-bold">User Identity</th>
|
| 1374 |
+
<th className="px-5 py-3.5 font-bold">Plan Vitals</th>
|
| 1375 |
+
<th className="px-5 py-3.5 font-bold">Limits & Quota Capsule</th>
|
| 1376 |
+
<th className="px-5 py-3.5 font-bold">Payment Proof</th>
|
| 1377 |
+
<th className="px-5 py-3.5 font-bold">Actions</th>
|
| 1378 |
+
</tr>
|
| 1379 |
+
</thead>
|
| 1380 |
+
<tbody className="divide-y divide-white/5 text-xs">
|
| 1381 |
+
{pagedMonoUsers.map((u) => (
|
| 1382 |
+
<tr key={u.id} className="hover:bg-white/[0.03] transition-colors group">
|
| 1383 |
+
<td className="px-5 py-3.5">
|
| 1384 |
+
<div className="font-bold text-foreground text-sm group-hover:text-red-400 transition-colors">{u.username}</div>
|
| 1385 |
+
<div className="text-[10px] text-foreground/35 font-mono">ID: {u.id}</div>
|
| 1386 |
+
</td>
|
| 1387 |
+
|
| 1388 |
+
{/* Compact Plan Vitals with Micro Dates */}
|
| 1389 |
+
<td className="px-5 py-3.5">
|
| 1390 |
+
<div className="flex flex-col gap-1">
|
| 1391 |
+
<select
|
| 1392 |
+
value={u.plan}
|
| 1393 |
+
onChange={async (e) => {
|
| 1394 |
+
const newPlan = e.target.value;
|
| 1395 |
+
const now = new Date();
|
| 1396 |
+
const expires = new Date(now);
|
| 1397 |
+
expires.setDate(expires.getDate() + 30);
|
| 1398 |
+
setMonetizationUsers(prev => prev.map(mu =>
|
| 1399 |
+
mu.id === u.id ? {
|
| 1400 |
+
...mu,
|
| 1401 |
+
plan: newPlan,
|
| 1402 |
+
is_approved: newPlan === 'free' ? 0 : 1,
|
| 1403 |
+
plan_activated_at: newPlan === 'free' ? null : now.toISOString(),
|
| 1404 |
+
plan_expires_at: newPlan === 'free' ? null : expires.toISOString()
|
| 1405 |
+
} : mu
|
| 1406 |
+
));
|
| 1407 |
+
const res = await apiFetch(`/api/admin/monetization/users/${u.id}/vitals`, {
|
| 1408 |
+
method: 'POST',
|
| 1409 |
+
body: JSON.stringify({ plan: newPlan, is_approved: newPlan === 'free' ? 0 : 1 })
|
| 1410 |
+
});
|
| 1411 |
+
if (res.ok) {
|
| 1412 |
+
setSuccessMsg(`Plan set to ${newPlan.toUpperCase()} for ${u.username}`);
|
| 1413 |
+
setTimeout(() => setSuccessMsg(''), 4000);
|
| 1414 |
+
} else {
|
| 1415 |
+
setErrorMsg('Failed to update plan.');
|
| 1416 |
+
setTimeout(() => setErrorMsg(''), 4000);
|
| 1417 |
+
}
|
| 1418 |
+
fetchMonetizationData();
|
| 1419 |
+
}}
|
| 1420 |
+
className={`bg-white/5 border border-white/10 rounded-lg px-2.5 py-1 text-[11px] font-black uppercase transition-all outline-none cursor-pointer ${u.plan !== 'free' ? 'text-indigo-400 border-indigo-400/30' : 'text-foreground/40'}`}
|
| 1421 |
+
>
|
| 1422 |
+
<option value="free">Free</option>
|
| 1423 |
+
<option value="basic">Basic</option>
|
| 1424 |
+
<option value="standard">Standard</option>
|
| 1425 |
+
<option value="premium">Premium</option>
|
| 1426 |
+
<option value="unlimited">Unlimited (Admin)</option>
|
| 1427 |
+
</select>
|
| 1428 |
+
|
| 1429 |
+
{u.plan !== 'free' && u.plan_expires_at && (
|
| 1430 |
+
<div className="text-[9px] font-mono font-bold text-red-400/80 flex items-center gap-1">
|
| 1431 |
+
<Clock size={9} />
|
| 1432 |
+
<span>Exp: {new Date(u.plan_expires_at).toLocaleDateString()}</span>
|
| 1433 |
+
</div>
|
| 1434 |
+
)}
|
| 1435 |
+
</div>
|
| 1436 |
+
</td>
|
| 1437 |
|
| 1438 |
+
{/* CREATIVE COMPACT HORIZONTAL CAPSULE FOR LIMITS */}
|
| 1439 |
+
<td className="px-5 py-3.5">
|
| 1440 |
+
<div className="inline-flex items-center gap-1.5 p-1 bg-black/40 border border-white/10 rounded-xl shadow-inner whitespace-nowrap">
|
| 1441 |
+
<span
|
| 1442 |
+
className="px-2 py-0.5 rounded-lg bg-indigo-500/10 text-indigo-400 font-mono text-[10px] font-bold border border-indigo-500/20"
|
| 1443 |
+
title="Daily Campaigns: Used / Max"
|
| 1444 |
+
>
|
| 1445 |
+
⚡ {u.daily_campaign_count ?? 0}/{u.max_daily_campaigns ?? 20}
|
| 1446 |
+
</span>
|
| 1447 |
+
<span
|
| 1448 |
+
className="px-2 py-0.5 rounded-lg bg-emerald-500/10 text-emerald-400 font-mono text-[10px] font-bold border border-emerald-500/20"
|
| 1449 |
+
title="Daily Keyword Searches: Used / Max"
|
| 1450 |
+
>
|
| 1451 |
+
🔍 {u.daily_keyword_count ?? 0}/{u.max_daily_keywords ?? 5}
|
| 1452 |
+
</span>
|
| 1453 |
+
<span
|
| 1454 |
+
className="px-2 py-0.5 rounded-lg bg-amber-500/10 text-amber-400 font-mono text-[10px] font-bold border border-amber-500/20"
|
| 1455 |
+
title="Scrape Leads Limit"
|
| 1456 |
+
>
|
| 1457 |
+
📥 {u.scrape_limit ?? 100}
|
| 1458 |
+
</span>
|
| 1459 |
+
<span
|
| 1460 |
+
className="px-2 py-0.5 rounded-lg bg-blue-500/10 text-blue-400 font-mono text-[10px] font-bold border border-blue-500/20"
|
| 1461 |
+
title="Max Telegram Accounts"
|
| 1462 |
+
>
|
| 1463 |
+
📱 {u.max_accounts ?? 1}
|
| 1464 |
+
</span>
|
| 1465 |
+
<span
|
| 1466 |
+
className="px-2 py-0.5 rounded-lg bg-rose-500/10 text-rose-400 font-mono text-[10px] font-bold border border-rose-500/20"
|
| 1467 |
+
title="Max Templates Allowed"
|
| 1468 |
+
>
|
| 1469 |
+
📝 {u.max_templates || 1}
|
| 1470 |
+
</span>
|
| 1471 |
+
</div>
|
| 1472 |
+
</td>
|
| 1473 |
+
|
| 1474 |
+
<td className="px-5 py-3.5">
|
| 1475 |
+
{u.payment_proof ? (
|
| 1476 |
+
<div className="max-w-[140px] space-y-0.5">
|
| 1477 |
+
<div className="text-[10px] font-medium text-emerald-400 truncate bg-emerald-500/10 px-2 py-0.5 rounded-lg border border-emerald-500/20" title={u.payment_proof}>
|
| 1478 |
+
{u.payment_proof}
|
| 1479 |
+
</div>
|
| 1480 |
+
<div className="text-[8px] text-foreground/40 uppercase font-bold text-center">Submitted</div>
|
| 1481 |
+
</div>
|
| 1482 |
+
) : (
|
| 1483 |
+
<span className="text-[10px] text-foreground/30 italic">No proof</span>
|
| 1484 |
+
)}
|
| 1485 |
+
</td>
|
| 1486 |
+
|
| 1487 |
+
<td className="px-5 py-3.5">
|
| 1488 |
+
{u.payment_proof && u.is_approved === 0 ? (
|
| 1489 |
+
<button
|
| 1490 |
+
onClick={async () => {
|
| 1491 |
+
const planToApprove = u.plan === 'free' ? 'basic' : u.plan;
|
| 1492 |
+
if (confirm(`Approve ${u.username}'s payment and activate "${planToApprove.toUpperCase()}" plan?`)) {
|
| 1493 |
const now = new Date();
|
| 1494 |
const expires = new Date(now);
|
| 1495 |
expires.setDate(expires.getDate() + 30);
|
| 1496 |
setMonetizationUsers(prev => prev.map(mu =>
|
| 1497 |
mu.id === u.id ? {
|
| 1498 |
...mu,
|
| 1499 |
+
is_approved: 1,
|
| 1500 |
+
plan: planToApprove,
|
| 1501 |
+
plan_activated_at: now.toISOString(),
|
| 1502 |
+
plan_expires_at: expires.toISOString()
|
| 1503 |
} : mu
|
| 1504 |
));
|
| 1505 |
const res = await apiFetch(`/api/admin/monetization/users/${u.id}/vitals`, {
|
| 1506 |
method: 'POST',
|
| 1507 |
+
body: JSON.stringify({ plan: planToApprove, is_approved: 1 })
|
| 1508 |
});
|
| 1509 |
if (res.ok) {
|
| 1510 |
+
setSuccessMsg(`Approved ${u.username} on ${planToApprove}!`);
|
| 1511 |
+
setTimeout(() => setSuccessMsg(''), 5000);
|
| 1512 |
} else {
|
| 1513 |
+
setErrorMsg('Approval failed.');
|
| 1514 |
setTimeout(() => setErrorMsg(''), 4000);
|
| 1515 |
}
|
| 1516 |
fetchMonetizationData();
|
| 1517 |
+
}
|
| 1518 |
+
}}
|
| 1519 |
+
className="flex items-center gap-1 px-3 py-1.5 rounded-lg bg-emerald-500 text-black text-[10px] font-extrabold uppercase transition-all hover:bg-emerald-400 active:scale-95 shadow-lg shadow-emerald-500/20 cursor-pointer"
|
| 1520 |
+
>
|
| 1521 |
+
<CheckCircle2 size={12} /> Approve
|
| 1522 |
+
</button>
|
| 1523 |
+
) : u.is_approved === 1 ? (
|
| 1524 |
+
<span className="text-[10px] text-emerald-400 font-bold inline-flex items-center gap-1 px-2 py-0.5 rounded-full bg-emerald-500/10 border border-emerald-500/20">
|
| 1525 |
+
<CheckCircle2 size={11} /> Approved
|
| 1526 |
+
</span>
|
| 1527 |
+
) : (
|
| 1528 |
+
<span className="text-[10px] text-foreground/30 font-medium italic">Pending</span>
|
| 1529 |
+
)}
|
| 1530 |
+
</td>
|
| 1531 |
+
</tr>
|
| 1532 |
+
))}
|
| 1533 |
+
{pagedMonoUsers.length === 0 && (
|
| 1534 |
+
<tr>
|
| 1535 |
+
<td colSpan={5} className="px-5 py-12 text-center text-foreground/30 italic">
|
| 1536 |
+
No monetization records matching search
|
| 1537 |
+
</td>
|
| 1538 |
+
</tr>
|
| 1539 |
+
)}
|
| 1540 |
+
</tbody>
|
| 1541 |
+
</table>
|
| 1542 |
+
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1543 |
|
| 1544 |
+
{/* Card Footer: Prev & Next Pagination Buttons */}
|
| 1545 |
+
<div className="p-4 border-t border-white/10 flex flex-col sm:flex-row items-center justify-between gap-3 bg-white/[0.01] text-xs">
|
| 1546 |
+
<div className="text-foreground/45 font-medium">
|
| 1547 |
+
Showing <span className="text-foreground font-bold">{Math.min(filteredMonoUsers.length, (monoPage - 1) * MONO_PER_PAGE + 1)}</span> to{' '}
|
| 1548 |
+
<span className="text-foreground font-bold">{Math.min(filteredMonoUsers.length, monoPage * MONO_PER_PAGE)}</span> of{' '}
|
| 1549 |
+
<span className="text-foreground font-bold">{filteredMonoUsers.length}</span> records
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1550 |
</div>
|
| 1551 |
+
<div className="flex items-center gap-2">
|
| 1552 |
+
<button
|
| 1553 |
+
onClick={() => setMonoPage(prev => Math.max(1, prev - 1))}
|
| 1554 |
+
disabled={monoPage <= 1}
|
| 1555 |
+
className="px-3 py-1.5 rounded-xl bg-white/5 hover:bg-white/10 border border-white/10 text-foreground font-bold flex items-center gap-1.5 disabled:opacity-30 disabled:pointer-events-none transition-all cursor-pointer"
|
| 1556 |
+
>
|
| 1557 |
+
<ChevronLeft size={14} />
|
| 1558 |
+
<span>Prev</span>
|
| 1559 |
+
</button>
|
| 1560 |
+
<span className="px-3 py-1.5 rounded-xl bg-white/[0.02] border border-white/5 font-mono text-foreground/70 text-xs">
|
| 1561 |
+
Page {monoPage} of {totalMonoPages}
|
| 1562 |
+
</span>
|
| 1563 |
+
<button
|
| 1564 |
+
onClick={() => setMonoPage(prev => Math.min(totalMonoPages, prev + 1))}
|
| 1565 |
+
disabled={monoPage >= totalMonoPages}
|
| 1566 |
+
className="px-3 py-1.5 rounded-xl bg-white/5 hover:bg-white/10 border border-white/10 text-foreground font-bold flex items-center gap-1.5 disabled:opacity-30 disabled:pointer-events-none transition-all cursor-pointer"
|
| 1567 |
+
>
|
| 1568 |
+
<span>Next</span>
|
| 1569 |
+
<ChevronRight size={14} />
|
| 1570 |
+
</button>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1571 |
</div>
|
| 1572 |
</div>
|
| 1573 |
</div>
|
|
|
|
| 1609 |
</button>
|
| 1610 |
)}
|
| 1611 |
</div>
|
| 1612 |
+
<div className="flex items-center gap-2 whitespace-nowrap">
|
| 1613 |
+
<span className="inline-flex items-center gap-1.5 px-3 py-1.5 rounded-xl bg-indigo-500/10 text-indigo-400 border border-indigo-500/25 text-xs font-bold font-mono">
|
| 1614 |
+
<Users size={13} />
|
| 1615 |
+
<span>{filteredGroupedTemplates.length} Accounts</span>
|
| 1616 |
+
</span>
|
| 1617 |
+
<span className="inline-flex items-center gap-1.5 px-3 py-1.5 rounded-xl bg-white/5 text-foreground/75 border border-white/10 text-xs font-bold font-mono">
|
| 1618 |
+
<FileText size={13} className="text-indigo-400" />
|
| 1619 |
+
<span>{globalTemplates.length} Templates Total</span>
|
| 1620 |
+
</span>
|
| 1621 |
+
</div>
|
| 1622 |
</div>
|
| 1623 |
</div>
|
| 1624 |
|
frontend/src/app/scraper/page.tsx
CHANGED
|
@@ -22,10 +22,40 @@ interface ScrapeResult {
|
|
| 22 |
is_member?: boolean;
|
| 23 |
}
|
| 24 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 25 |
export default function ScraperPage() {
|
| 26 |
const [keyword, setKeyword] = useState('');
|
| 27 |
const [country, setCountry] = useState('');
|
| 28 |
-
const [searchMode, setSearchMode] = useState<'free' | 'fixed'>('free');
|
|
|
|
|
|
|
| 29 |
const [scrapeStatus, setScrapeStatus] = useState('');
|
| 30 |
const abortControllerRef = useRef<AbortController | null>(null);
|
| 31 |
const [loading, setLoading] = useState(false);
|
|
@@ -124,10 +154,17 @@ export default function ScraperPage() {
|
|
| 124 |
setError('Please enter a niche keyword first (e.g. "interior decor", "crypto", "marketing").');
|
| 125 |
return;
|
| 126 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 127 |
setIsSuggesting(true);
|
| 128 |
setError('');
|
| 129 |
try {
|
| 130 |
-
const storedKey = aiApiKey || localStorage.getItem('arkitel_ai_key') || '';
|
| 131 |
const storedProvider = aiProvider || localStorage.getItem('arkitel_ai_provider') || 'openai';
|
| 132 |
const storedModel = aiModel || localStorage.getItem('arkitel_ai_model') || '';
|
| 133 |
|
|
@@ -147,7 +184,7 @@ export default function ScraperPage() {
|
|
| 147 |
setSuggestionSeed(seed);
|
| 148 |
setIsSuggestionsPanelOpen(true);
|
| 149 |
setIsSuggestionsMinimized(false);
|
| 150 |
-
setSuccessMsg(`Generated ${data.keywords.length} keyword variations!`);
|
| 151 |
setTimeout(() => setSuccessMsg(''), 4000);
|
| 152 |
} else {
|
| 153 |
setError(data.detail || data.note || 'Failed to suggest keywords.');
|
|
@@ -391,11 +428,20 @@ export default function ScraperPage() {
|
|
| 391 |
if (e) e.preventDefault();
|
| 392 |
if (!keyword.trim()) return;
|
| 393 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 394 |
setLoading(true);
|
| 395 |
setError('');
|
| 396 |
setSearched(true);
|
| 397 |
setResults([]);
|
| 398 |
-
setScrapeStatus('Connecting to Scrape Engine...');
|
| 399 |
|
| 400 |
// Immediately notify sidebar – backend increments keyword count before streaming starts
|
| 401 |
window.dispatchEvent(new Event('update_status'));
|
|
@@ -408,7 +454,13 @@ export default function ScraperPage() {
|
|
| 408 |
const token = localStorage.getItem('tg_auth_token') || '';
|
| 409 |
const apiBase = getApiBase();
|
| 410 |
const cStr = country.trim() ? `&country=${encodeURIComponent(' ' + country.trim())}` : '';
|
| 411 |
-
const
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 412 |
headers: { 'Authorization': `Bearer ${token}` },
|
| 413 |
signal: controller.signal
|
| 414 |
});
|
|
@@ -670,7 +722,7 @@ export default function ScraperPage() {
|
|
| 670 |
|
| 671 |
{/* Scraper Mode & AI Settings Bar */}
|
| 672 |
<div className="flex flex-col sm:flex-row items-stretch sm:items-center justify-between gap-3 mb-3">
|
| 673 |
-
<div className="flex items-center gap-1.5 p-1 bg-card border border-border/80 rounded-xl shadow-xs
|
| 674 |
<button
|
| 675 |
type="button"
|
| 676 |
onClick={() => setSearchMode('free')}
|
|
@@ -684,18 +736,53 @@ export default function ScraperPage() {
|
|
| 684 |
<span>Free Mode</span>
|
| 685 |
<span className="text-[10px] opacity-75 font-normal hidden sm:inline">(Natural Search)</span>
|
| 686 |
</button>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 687 |
<button
|
| 688 |
type="button"
|
| 689 |
-
onClick={() =>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 690 |
className={`px-3 py-1.5 rounded-lg text-xs font-semibold transition-all flex items-center gap-1.5 cursor-pointer ${
|
| 691 |
-
searchMode === '
|
| 692 |
-
? 'bg-indigo-600 text-white shadow-xs'
|
| 693 |
: 'text-foreground/50 hover:text-foreground'
|
| 694 |
}`}
|
| 695 |
>
|
| 696 |
-
<
|
| 697 |
-
<span>
|
| 698 |
-
<span className="text-[10px] opacity-
|
| 699 |
</button>
|
| 700 |
</div>
|
| 701 |
|
|
@@ -727,7 +814,13 @@ export default function ScraperPage() {
|
|
| 727 |
value={keyword}
|
| 728 |
onChange={(e) => setKeyword(e.target.value)}
|
| 729 |
className="w-full bg-input border border-border/70 text-foreground rounded-lg py-2 pl-9 pr-3 text-xs focus:outline-none focus:ring-2 focus:ring-indigo-500/20 outline-none transition-all placeholder:text-foreground/30"
|
| 730 |
-
placeholder={
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 731 |
required
|
| 732 |
/>
|
| 733 |
</div>
|
|
@@ -1251,7 +1344,7 @@ export default function ScraperPage() {
|
|
| 1251 |
)}
|
| 1252 |
|
| 1253 |
<p className="text-[10px] text-foreground/40 leading-relaxed">
|
| 1254 |
-
💡 Credentials are encrypted locally in your browser.
|
| 1255 |
</p>
|
| 1256 |
</div>
|
| 1257 |
|
|
@@ -1274,6 +1367,106 @@ export default function ScraperPage() {
|
|
| 1274 |
</div>
|
| 1275 |
</div>
|
| 1276 |
)}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1277 |
</div>
|
| 1278 |
</MonetizationOverlay>
|
| 1279 |
);
|
|
|
|
| 22 |
is_member?: boolean;
|
| 23 |
}
|
| 24 |
|
| 25 |
+
const SUFFIX_CATEGORIES = [
|
| 26 |
+
{
|
| 27 |
+
name: "Community & Networking",
|
| 28 |
+
count: 14,
|
| 29 |
+
items: ["official", "group", "channel", "community", "chat", "hub", "network", "team", "zone", "world", "global", "club", "lounge", "forum"]
|
| 30 |
+
},
|
| 31 |
+
{
|
| 32 |
+
name: "Authority & Quality",
|
| 33 |
+
count: 12,
|
| 34 |
+
items: ["main", "real", "original", "vip", "pro", "hq", "direct", "portal", "top", "best", "new", "prime"]
|
| 35 |
+
},
|
| 36 |
+
{
|
| 37 |
+
name: "Information & Updates",
|
| 38 |
+
count: 12,
|
| 39 |
+
items: ["updates", "news", "info", "alerts", "broadcast", "notices", "daily", "feed", "insights", "trends", "guide", "academy"]
|
| 40 |
+
},
|
| 41 |
+
{
|
| 42 |
+
name: "Business & Market",
|
| 43 |
+
count: 12,
|
| 44 |
+
items: ["market", "store", "shop", "deals", "leads", "clients", "services", "support", "help", "prices", "exchange", "b2b"]
|
| 45 |
+
},
|
| 46 |
+
{
|
| 47 |
+
name: "Scope & Connectivity",
|
| 48 |
+
count: 12,
|
| 49 |
+
items: ["online", "free", "live", "premium", "international", "access", "connect", "links", "directory", "showcase", "solutions", "discussion"]
|
| 50 |
+
}
|
| 51 |
+
];
|
| 52 |
+
|
| 53 |
export default function ScraperPage() {
|
| 54 |
const [keyword, setKeyword] = useState('');
|
| 55 |
const [country, setCountry] = useState('');
|
| 56 |
+
const [searchMode, setSearchMode] = useState<'free' | 'fixed' | 'ai'>('free');
|
| 57 |
+
const [isSuffixModalOpen, setIsSuffixModalOpen] = useState(false);
|
| 58 |
+
const [copiedSuffixes, setCopiedSuffixes] = useState(false);
|
| 59 |
const [scrapeStatus, setScrapeStatus] = useState('');
|
| 60 |
const abortControllerRef = useRef<AbortController | null>(null);
|
| 61 |
const [loading, setLoading] = useState(false);
|
|
|
|
| 154 |
setError('Please enter a niche keyword first (e.g. "interior decor", "crypto", "marketing").');
|
| 155 |
return;
|
| 156 |
}
|
| 157 |
+
|
| 158 |
+
const storedKey = aiApiKey || localStorage.getItem('arkitel_ai_key') || '';
|
| 159 |
+
if (!storedKey) {
|
| 160 |
+
setError('No AI Model connected. Please configure your OpenAI, Claude, or OpenRouter API key first to use AI Keyword Suggestions.');
|
| 161 |
+
setIsAiModalOpen(true);
|
| 162 |
+
return;
|
| 163 |
+
}
|
| 164 |
+
|
| 165 |
setIsSuggesting(true);
|
| 166 |
setError('');
|
| 167 |
try {
|
|
|
|
| 168 |
const storedProvider = aiProvider || localStorage.getItem('arkitel_ai_provider') || 'openai';
|
| 169 |
const storedModel = aiModel || localStorage.getItem('arkitel_ai_model') || '';
|
| 170 |
|
|
|
|
| 184 |
setSuggestionSeed(seed);
|
| 185 |
setIsSuggestionsPanelOpen(true);
|
| 186 |
setIsSuggestionsMinimized(false);
|
| 187 |
+
setSuccessMsg(`Generated ${data.keywords.length} AI keyword variations!`);
|
| 188 |
setTimeout(() => setSuccessMsg(''), 4000);
|
| 189 |
} else {
|
| 190 |
setError(data.detail || data.note || 'Failed to suggest keywords.');
|
|
|
|
| 428 |
if (e) e.preventDefault();
|
| 429 |
if (!keyword.trim()) return;
|
| 430 |
|
| 431 |
+
if (searchMode === 'ai') {
|
| 432 |
+
const storedKey = aiApiKey || localStorage.getItem('arkitel_ai_key') || '';
|
| 433 |
+
if (!storedKey) {
|
| 434 |
+
setError('No AI Model connected. Please configure your OpenAI, Claude, or OpenRouter API key first to use the AI Scraper.');
|
| 435 |
+
setIsAiModalOpen(true);
|
| 436 |
+
return;
|
| 437 |
+
}
|
| 438 |
+
}
|
| 439 |
+
|
| 440 |
setLoading(true);
|
| 441 |
setError('');
|
| 442 |
setSearched(true);
|
| 443 |
setResults([]);
|
| 444 |
+
setScrapeStatus(searchMode === 'ai' ? 'Initializing AI Web Discovery Engine...' : 'Connecting to Scrape Engine...');
|
| 445 |
|
| 446 |
// Immediately notify sidebar – backend increments keyword count before streaming starts
|
| 447 |
window.dispatchEvent(new Event('update_status'));
|
|
|
|
| 454 |
const token = localStorage.getItem('tg_auth_token') || '';
|
| 455 |
const apiBase = getApiBase();
|
| 456 |
const cStr = country.trim() ? `&country=${encodeURIComponent(' ' + country.trim())}` : '';
|
| 457 |
+
const storedKey = aiApiKey || localStorage.getItem('arkitel_ai_key') || '';
|
| 458 |
+
const storedProvider = aiProvider || localStorage.getItem('arkitel_ai_provider') || 'openai';
|
| 459 |
+
const storedModel = aiModel || localStorage.getItem('arkitel_ai_model') || '';
|
| 460 |
+
const aiParams = searchMode === 'ai'
|
| 461 |
+
? `&ai_provider=${encodeURIComponent(storedProvider)}&ai_key=${encodeURIComponent(storedKey)}&ai_model=${encodeURIComponent(storedModel)}`
|
| 462 |
+
: '';
|
| 463 |
+
const res = await fetch(`${apiBase}/api/telegram/scrape_stream?query=${encodeURIComponent(keyword)}${cStr}&mode=${searchMode}&limit=500${aiParams}`, {
|
| 464 |
headers: { 'Authorization': `Bearer ${token}` },
|
| 465 |
signal: controller.signal
|
| 466 |
});
|
|
|
|
| 722 |
|
| 723 |
{/* Scraper Mode & AI Settings Bar */}
|
| 724 |
<div className="flex flex-col sm:flex-row items-stretch sm:items-center justify-between gap-3 mb-3">
|
| 725 |
+
<div className="flex items-center gap-1.5 p-1 bg-card border border-border/80 rounded-xl shadow-xs flex-wrap sm:flex-nowrap">
|
| 726 |
<button
|
| 727 |
type="button"
|
| 728 |
onClick={() => setSearchMode('free')}
|
|
|
|
| 736 |
<span>Free Mode</span>
|
| 737 |
<span className="text-[10px] opacity-75 font-normal hidden sm:inline">(Natural Search)</span>
|
| 738 |
</button>
|
| 739 |
+
|
| 740 |
+
<div className="flex items-center">
|
| 741 |
+
<button
|
| 742 |
+
type="button"
|
| 743 |
+
onClick={() => setSearchMode('fixed')}
|
| 744 |
+
className={`px-3 py-1.5 rounded-l-lg text-xs font-semibold transition-all flex items-center gap-1.5 cursor-pointer ${
|
| 745 |
+
searchMode === 'fixed'
|
| 746 |
+
? 'bg-indigo-600 text-white shadow-xs'
|
| 747 |
+
: 'text-foreground/50 hover:text-foreground'
|
| 748 |
+
}`}
|
| 749 |
+
>
|
| 750 |
+
<Sliders size={13} />
|
| 751 |
+
<span>Fixed Mode</span>
|
| 752 |
+
</button>
|
| 753 |
+
<button
|
| 754 |
+
type="button"
|
| 755 |
+
onClick={() => setIsSuffixModalOpen(true)}
|
| 756 |
+
className={`px-2 py-1.5 rounded-r-lg text-[10px] font-mono font-bold transition-all flex items-center gap-1 cursor-pointer border-y border-r ${
|
| 757 |
+
searchMode === 'fixed'
|
| 758 |
+
? 'bg-indigo-700 text-indigo-100 border-indigo-500 hover:bg-indigo-800'
|
| 759 |
+
: 'bg-card border-border/80 text-foreground/50 hover:text-foreground hover:bg-foreground/5'
|
| 760 |
+
}`}
|
| 761 |
+
title="Click to view all 62 systematic suffix variations"
|
| 762 |
+
>
|
| 763 |
+
<span>(60+ Suffixes)</span>
|
| 764 |
+
<ExternalLink size={10} />
|
| 765 |
+
</button>
|
| 766 |
+
</div>
|
| 767 |
+
|
| 768 |
<button
|
| 769 |
type="button"
|
| 770 |
+
onClick={() => {
|
| 771 |
+
setSearchMode('ai');
|
| 772 |
+
const storedKey = aiApiKey || localStorage.getItem('arkitel_ai_key') || '';
|
| 773 |
+
if (!storedKey) {
|
| 774 |
+
setIsAiModalOpen(true);
|
| 775 |
+
}
|
| 776 |
+
}}
|
| 777 |
className={`px-3 py-1.5 rounded-lg text-xs font-semibold transition-all flex items-center gap-1.5 cursor-pointer ${
|
| 778 |
+
searchMode === 'ai'
|
| 779 |
+
? 'bg-gradient-to-r from-indigo-600 to-purple-600 text-white shadow-xs'
|
| 780 |
: 'text-foreground/50 hover:text-foreground'
|
| 781 |
}`}
|
| 782 |
>
|
| 783 |
+
<Sparkles size={13} className={searchMode === 'ai' ? 'animate-pulse text-amber-300' : 'text-indigo-400'} />
|
| 784 |
+
<span>AI Scraper</span>
|
| 785 |
+
<span className="text-[10px] opacity-80 font-normal hidden sm:inline">(Web Intelligence)</span>
|
| 786 |
</button>
|
| 787 |
</div>
|
| 788 |
|
|
|
|
| 814 |
value={keyword}
|
| 815 |
onChange={(e) => setKeyword(e.target.value)}
|
| 816 |
className="w-full bg-input border border-border/70 text-foreground rounded-lg py-2 pl-9 pr-3 text-xs focus:outline-none focus:ring-2 focus:ring-indigo-500/20 outline-none transition-all placeholder:text-foreground/30"
|
| 817 |
+
placeholder={
|
| 818 |
+
searchMode === 'free'
|
| 819 |
+
? "Exact Niche or Keyword for pure natural search (e.g. Website Development, Real Estate)"
|
| 820 |
+
: searchMode === 'fixed'
|
| 821 |
+
? "Base Keyword for systematic 60+ suffix sweep (e.g. Crypto, Design, Marketing)"
|
| 822 |
+
: "Niche, Topic, or Query for AI web intelligence discovery (e.g. Website Development, SaaS Founders)"
|
| 823 |
+
}
|
| 824 |
required
|
| 825 |
/>
|
| 826 |
</div>
|
|
|
|
| 1344 |
)}
|
| 1345 |
|
| 1346 |
<p className="text-[10px] text-foreground/40 leading-relaxed">
|
| 1347 |
+
💡 Credentials are encrypted locally in your browser. Connect your OpenAI, Claude, or OpenRouter API key to unlock AI Keyword Suggestions and the deep AI Web Intelligence Scraper.
|
| 1348 |
</p>
|
| 1349 |
</div>
|
| 1350 |
|
|
|
|
| 1367 |
</div>
|
| 1368 |
</div>
|
| 1369 |
)}
|
| 1370 |
+
|
| 1371 |
+
{/* 60+ Suffixes Modal */}
|
| 1372 |
+
{isSuffixModalOpen && (
|
| 1373 |
+
<div className="fixed inset-0 z-50 flex items-center justify-center p-4 bg-black/70 backdrop-blur-sm animate-in fade-in duration-200">
|
| 1374 |
+
<div className="bg-card border border-border/80 w-full max-w-2xl rounded-2xl shadow-2xl overflow-hidden flex flex-col max-h-[85vh]">
|
| 1375 |
+
{/* Modal Header */}
|
| 1376 |
+
<div className="p-4 px-5 border-b border-border/70 flex items-center justify-between bg-foreground/[0.01]">
|
| 1377 |
+
<div className="flex items-center gap-2.5">
|
| 1378 |
+
<div className="p-2 rounded-xl bg-indigo-500/10 text-indigo-400 border border-indigo-500/20">
|
| 1379 |
+
<Sliders size={18} />
|
| 1380 |
+
</div>
|
| 1381 |
+
<div>
|
| 1382 |
+
<h3 className="text-sm font-bold text-foreground flex items-center gap-2">
|
| 1383 |
+
Fixed Mode Suffix Registry
|
| 1384 |
+
<span className="text-[10px] px-2 py-0.5 rounded-full bg-indigo-500/10 text-indigo-400 border border-indigo-500/20 font-mono font-bold">
|
| 1385 |
+
62 Systematic Variations
|
| 1386 |
+
</span>
|
| 1387 |
+
</h3>
|
| 1388 |
+
<p className="text-[11px] text-foreground/45">
|
| 1389 |
+
Universal business & community keywords tested automatically on your base query
|
| 1390 |
+
</p>
|
| 1391 |
+
</div>
|
| 1392 |
+
</div>
|
| 1393 |
+
<button
|
| 1394 |
+
type="button"
|
| 1395 |
+
onClick={() => setIsSuffixModalOpen(false)}
|
| 1396 |
+
className="p-1.5 text-foreground/40 hover:text-foreground rounded-lg hover:bg-foreground/5 transition-all"
|
| 1397 |
+
>
|
| 1398 |
+
<X size={16} />
|
| 1399 |
+
</button>
|
| 1400 |
+
</div>
|
| 1401 |
+
|
| 1402 |
+
{/* Modal Body: Suffix Categories */}
|
| 1403 |
+
<div className="p-5 space-y-4 overflow-y-auto">
|
| 1404 |
+
<div className="p-3 rounded-xl bg-indigo-500/5 border border-indigo-500/15 text-xs text-foreground/75 leading-relaxed">
|
| 1405 |
+
<span className="font-bold text-indigo-400">How Fixed Mode Works:</span> When you enter a base keyword (e.g. <span className="font-mono text-indigo-300 font-semibold">“web development”</span>), Fixed Mode sweeps through all 62 category-neutral variations below (e.g. <span className="font-mono text-foreground/90 font-medium">“web development community”</span>, <span className="font-mono text-foreground/90 font-medium">“web development official”</span>, <span className="font-mono text-foreground/90 font-medium">“web development leads”</span>) across your connected Telegram accounts, uncovering hidden communities that basic single-word searches miss.
|
| 1406 |
+
</div>
|
| 1407 |
+
|
| 1408 |
+
<div className="space-y-3.5">
|
| 1409 |
+
{SUFFIX_CATEGORIES.map((cat, idx) => (
|
| 1410 |
+
<div key={idx} className="p-3.5 rounded-xl bg-foreground/[0.02] border border-border/60">
|
| 1411 |
+
<div className="flex items-center justify-between mb-2">
|
| 1412 |
+
<h4 className="text-xs font-bold text-foreground/80 flex items-center gap-1.5">
|
| 1413 |
+
<span className="w-1.5 h-1.5 rounded-full bg-indigo-400" />
|
| 1414 |
+
{cat.name}
|
| 1415 |
+
</h4>
|
| 1416 |
+
<span className="text-[10px] font-mono text-foreground/40 font-semibold">
|
| 1417 |
+
{cat.count} variations
|
| 1418 |
+
</span>
|
| 1419 |
+
</div>
|
| 1420 |
+
<div className="flex flex-wrap gap-1.5">
|
| 1421 |
+
{cat.items.map((suffix, sIdx) => (
|
| 1422 |
+
<span
|
| 1423 |
+
key={sIdx}
|
| 1424 |
+
className="px-2 py-0.5 rounded-lg bg-card border border-border text-[11px] font-mono text-foreground/70 hover:text-indigo-400 hover:border-indigo-500/30 transition-all select-all"
|
| 1425 |
+
>
|
| 1426 |
+
+{suffix}
|
| 1427 |
+
</span>
|
| 1428 |
+
))}
|
| 1429 |
+
</div>
|
| 1430 |
+
</div>
|
| 1431 |
+
))}
|
| 1432 |
+
</div>
|
| 1433 |
+
</div>
|
| 1434 |
+
|
| 1435 |
+
{/* Modal Footer */}
|
| 1436 |
+
<div className="p-4 px-5 border-t border-border/70 flex items-center justify-between bg-foreground/[0.01]">
|
| 1437 |
+
<button
|
| 1438 |
+
type="button"
|
| 1439 |
+
onClick={() => {
|
| 1440 |
+
const allSuffixes = SUFFIX_CATEGORIES.flatMap(c => c.items).join(', ');
|
| 1441 |
+
navigator.clipboard.writeText(allSuffixes);
|
| 1442 |
+
setCopiedSuffixes(true);
|
| 1443 |
+
setTimeout(() => setCopiedSuffixes(false), 3000);
|
| 1444 |
+
}}
|
| 1445 |
+
className="px-3 py-1.5 rounded-lg border border-border bg-card hover:bg-foreground/5 text-foreground/70 hover:text-foreground text-xs font-semibold flex items-center gap-1.5 transition-all"
|
| 1446 |
+
>
|
| 1447 |
+
{copiedSuffixes ? (
|
| 1448 |
+
<>
|
| 1449 |
+
<Check size={13} className="text-emerald-400" />
|
| 1450 |
+
<span className="text-emerald-400">Copied 62 Suffixes!</span>
|
| 1451 |
+
</>
|
| 1452 |
+
) : (
|
| 1453 |
+
<>
|
| 1454 |
+
<Copy size={13} />
|
| 1455 |
+
<span>Copy All Suffixes</span>
|
| 1456 |
+
</>
|
| 1457 |
+
)}
|
| 1458 |
+
</button>
|
| 1459 |
+
<button
|
| 1460 |
+
type="button"
|
| 1461 |
+
onClick={() => setIsSuffixModalOpen(false)}
|
| 1462 |
+
className="px-4 py-1.5 text-xs text-white bg-indigo-600 hover:bg-indigo-500 font-bold rounded-lg transition-all shadow-sm active:scale-95"
|
| 1463 |
+
>
|
| 1464 |
+
Done
|
| 1465 |
+
</button>
|
| 1466 |
+
</div>
|
| 1467 |
+
</div>
|
| 1468 |
+
</div>
|
| 1469 |
+
)}
|
| 1470 |
</div>
|
| 1471 |
</MonetizationOverlay>
|
| 1472 |
);
|