Spaces:
Paused
Paused
CBV01 commited on
Commit ·
9fb76ee
1
Parent(s): 04042c5
Fix scraper bulk selection, sidebar limits for free plan, and admin monetization UI
Browse files- backend/main.py +16 -0
- frontend/src/app/admin/page.tsx +14 -11
- frontend/src/app/scraper/page.tsx +16 -10
- frontend/src/components/Sidebar.tsx +22 -18
backend/main.py
CHANGED
|
@@ -618,8 +618,10 @@ async def verify_passkey(req: PasskeyVerify, user_id: str = Depends(get_current_
|
|
| 618 |
async def get_me(user_id: str = Depends(get_current_user_id)):
|
| 619 |
if user_id == "admin_virtual_id":
|
| 620 |
return {
|
|
|
|
| 621 |
"username": "System Administrator",
|
| 622 |
"role": "admin",
|
|
|
|
| 623 |
"passkey_verified": True
|
| 624 |
}
|
| 625 |
|
|
@@ -1873,6 +1875,20 @@ async def delete_coupon_admin(code: str, admin_id: str = Depends(get_current_adm
|
|
| 1873 |
|
| 1874 |
@app.get("/api/monetization/status")
|
| 1875 |
async def get_user_status(user_id: str = Depends(get_current_user_id)):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1876 |
conn = get_db_connection()
|
| 1877 |
row = conn.execute("SELECT * FROM users WHERE id = ?", (user_id,)).fetchone()
|
| 1878 |
if hasattr(conn, "close"): conn.close()
|
|
|
|
| 618 |
async def get_me(user_id: str = Depends(get_current_user_id)):
|
| 619 |
if user_id == "admin_virtual_id":
|
| 620 |
return {
|
| 621 |
+
"id": "admin_virtual_id",
|
| 622 |
"username": "System Administrator",
|
| 623 |
"role": "admin",
|
| 624 |
+
"plan": "unlimited",
|
| 625 |
"passkey_verified": True
|
| 626 |
}
|
| 627 |
|
|
|
|
| 1875 |
|
| 1876 |
@app.get("/api/monetization/status")
|
| 1877 |
async def get_user_status(user_id: str = Depends(get_current_user_id)):
|
| 1878 |
+
if user_id == "admin_virtual_id":
|
| 1879 |
+
cfg = PLAN_CONFIGS["unlimited"]
|
| 1880 |
+
return {
|
| 1881 |
+
"plan": "unlimited",
|
| 1882 |
+
"scrape_limit": cfg["scrape_limit"],
|
| 1883 |
+
"max_accounts": cfg["max_accounts"],
|
| 1884 |
+
"max_daily_campaigns": cfg["max_daily_campaigns"],
|
| 1885 |
+
"daily_campaign_count": 0,
|
| 1886 |
+
"max_daily_keywords": cfg["max_daily_keywords"],
|
| 1887 |
+
"daily_keyword_count": 0,
|
| 1888 |
+
"is_approved": 1,
|
| 1889 |
+
"has_proof": True
|
| 1890 |
+
}
|
| 1891 |
+
|
| 1892 |
conn = get_db_connection()
|
| 1893 |
row = conn.execute("SELECT * FROM users WHERE id = ?", (user_id,)).fetchone()
|
| 1894 |
if hasattr(conn, "close"): conn.close()
|
frontend/src/app/admin/page.tsx
CHANGED
|
@@ -639,20 +639,23 @@ export default function AdminDashboard() {
|
|
| 639 |
</select>
|
| 640 |
</td>
|
| 641 |
<td className="px-6 py-4">
|
| 642 |
-
<div className="flex flex-
|
| 643 |
-
<div className="flex items-center gap-2">
|
| 644 |
-
<span className="text-[
|
| 645 |
-
<span className="text-[10px] font-
|
| 646 |
</div>
|
| 647 |
-
<div className="flex items-center gap-2">
|
| 648 |
-
<span className="text-[
|
| 649 |
-
<span className="text-[10px] font-
|
| 650 |
</div>
|
| 651 |
-
<div className="flex items-center gap-2">
|
| 652 |
-
<span className="text-[
|
| 653 |
-
<span className="text-[10px] font-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 654 |
</div>
|
| 655 |
-
<div className="text-[9px] text-foreground/30 font-black uppercase">ACCOUNTS: {u.max_accounts}</div>
|
| 656 |
</div>
|
| 657 |
</td>
|
| 658 |
<td className="px-6 py-4">
|
|
|
|
| 639 |
</select>
|
| 640 |
</td>
|
| 641 |
<td className="px-6 py-4">
|
| 642 |
+
<div className="flex flex-wrap gap-2 max-w-[180px]">
|
| 643 |
+
<div className="flex items-center gap-1.5 px-2 py-1 bg-white/5 rounded-md border border-white/5">
|
| 644 |
+
<span className="text-[8px] text-foreground/30 font-black">CAMP:</span>
|
| 645 |
+
<span className="text-[10px] font-bold text-indigo-400">{u.daily_campaign_count} / {u.max_daily_campaigns}</span>
|
| 646 |
</div>
|
| 647 |
+
<div className="flex items-center gap-1.5 px-2 py-1 bg-white/5 rounded-md border border-white/5">
|
| 648 |
+
<span className="text-[8px] text-foreground/30 font-black">KEY:</span>
|
| 649 |
+
<span className="text-[10px] font-bold text-emerald-400">{u.daily_keyword_count} / {u.max_daily_keywords}</span>
|
| 650 |
</div>
|
| 651 |
+
<div className="flex items-center gap-1.5 px-2 py-1 bg-white/5 rounded-md border border-white/5">
|
| 652 |
+
<span className="text-[8px] text-foreground/30 font-black">SCR:</span>
|
| 653 |
+
<span className="text-[10px] font-bold text-amber-400">{u.scrape_limit}</span>
|
| 654 |
+
</div>
|
| 655 |
+
<div className="flex items-center gap-1.5 px-2 py-1 bg-white/5 rounded-md border border-white/5">
|
| 656 |
+
<span className="text-[8px] text-foreground/30 font-black">ACC:</span>
|
| 657 |
+
<span className="text-[10px] font-bold text-blue-400">{u.max_accounts}</span>
|
| 658 |
</div>
|
|
|
|
| 659 |
</div>
|
| 660 |
</td>
|
| 661 |
<td className="px-6 py-4">
|
frontend/src/app/scraper/page.tsx
CHANGED
|
@@ -334,14 +334,20 @@ export default function ScraperPage() {
|
|
| 334 |
});
|
| 335 |
|
| 336 |
const toggleSelectAll = () => {
|
| 337 |
-
// Treat is_member as false if it's undefined (Layer 2/3 results don't always set it)
|
| 338 |
const selectable = filteredResults.filter(r => !r.is_member);
|
| 339 |
-
|
| 340 |
-
|
| 341 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 342 |
} else {
|
| 343 |
-
|
|
|
|
| 344 |
}
|
|
|
|
| 345 |
};
|
| 346 |
|
| 347 |
return (
|
|
@@ -536,17 +542,17 @@ export default function ScraperPage() {
|
|
| 536 |
<table className="w-full text-left border-collapse">
|
| 537 |
<thead>
|
| 538 |
<tr className="border-b border-black/5 dark:border-white/5 text-foreground/50 text-[11px] uppercase tracking-wider bg-black/[0.02] dark:bg-white/[0.02]">
|
| 539 |
-
<th className="font-semibold p-4 pl-6 w-10">
|
| 540 |
<button
|
| 541 |
onClick={toggleSelectAll}
|
| 542 |
-
title={selectedGroups.
|
| 543 |
-
className={`w-5 h-5 rounded flex items-center justify-center border transition-all ${
|
| 544 |
-
filteredResults.filter(r => !r.is_member).length > 0 &&
|
| 545 |
? 'bg-indigo-600 border-indigo-600 text-white'
|
| 546 |
: 'border-foreground/20 hover:border-indigo-500'
|
| 547 |
}`}
|
| 548 |
>
|
| 549 |
-
{filteredResults.filter(r => !r.is_member).length > 0 &&
|
| 550 |
</button>
|
| 551 |
</th>
|
| 552 |
<th className="font-semibold p-4">Group / Channel Name</th>
|
|
|
|
| 334 |
});
|
| 335 |
|
| 336 |
const toggleSelectAll = () => {
|
|
|
|
| 337 |
const selectable = filteredResults.filter(r => !r.is_member);
|
| 338 |
+
if (selectable.length === 0) return;
|
| 339 |
+
|
| 340 |
+
const allAlreadySelected = selectable.every(r => selectedGroups.has(r.id));
|
| 341 |
+
|
| 342 |
+
const newSelected = new Set(selectedGroups);
|
| 343 |
+
if (allAlreadySelected) {
|
| 344 |
+
// Deselect only the currently visible selectable ones
|
| 345 |
+
selectable.forEach(r => newSelected.delete(r.id));
|
| 346 |
} else {
|
| 347 |
+
// Select all visible selectable ones
|
| 348 |
+
selectable.forEach(r => newSelected.add(r.id));
|
| 349 |
}
|
| 350 |
+
setSelectedGroups(newSelected);
|
| 351 |
};
|
| 352 |
|
| 353 |
return (
|
|
|
|
| 542 |
<table className="w-full text-left border-collapse">
|
| 543 |
<thead>
|
| 544 |
<tr className="border-b border-black/5 dark:border-white/5 text-foreground/50 text-[11px] uppercase tracking-wider bg-black/[0.02] dark:bg-white/[0.02]">
|
| 545 |
+
<th className="font-semibold p-4 pl-6 w-10 text-center">
|
| 546 |
<button
|
| 547 |
onClick={toggleSelectAll}
|
| 548 |
+
title={filteredResults.filter(r => !r.is_member).every(r => selectedGroups.has(r.id)) && filteredResults.filter(r => !r.is_member).length > 0 ? 'Deselect All' : 'Select All'}
|
| 549 |
+
className={`w-5 h-5 rounded flex items-center justify-center border transition-all mx-auto ${
|
| 550 |
+
filteredResults.filter(r => !r.is_member).length > 0 && filteredResults.filter(r => !r.is_member).every(r => selectedGroups.has(r.id))
|
| 551 |
? 'bg-indigo-600 border-indigo-600 text-white'
|
| 552 |
: 'border-foreground/20 hover:border-indigo-500'
|
| 553 |
}`}
|
| 554 |
>
|
| 555 |
+
{filteredResults.filter(r => !r.is_member).length > 0 && filteredResults.filter(r => !r.is_member).every(r => selectedGroups.has(r.id)) && <CheckCircle2 size={14} />}
|
| 556 |
</button>
|
| 557 |
</th>
|
| 558 |
<th className="font-semibold p-4">Group / Channel Name</th>
|
frontend/src/components/Sidebar.tsx
CHANGED
|
@@ -266,25 +266,29 @@ export function Sidebar({ children }: { children: React.ReactNode }) {
|
|
| 266 |
</div>
|
| 267 |
</div>
|
| 268 |
|
| 269 |
-
{
|
| 270 |
-
|
| 271 |
-
|
| 272 |
-
<
|
| 273 |
-
|
| 274 |
-
|
| 275 |
-
|
| 276 |
-
|
| 277 |
-
className="h-full bg-
|
| 278 |
-
|
| 279 |
-
|
| 280 |
-
|
| 281 |
-
|
|
|
|
|
|
|
| 282 |
|
| 283 |
-
|
| 284 |
-
|
| 285 |
-
|
| 286 |
-
|
| 287 |
-
|
|
|
|
|
|
|
| 288 |
</div>
|
| 289 |
|
| 290 |
<div className="pt-2 border-t border-border/50">
|
|
|
|
| 266 |
</div>
|
| 267 |
</div>
|
| 268 |
|
| 269 |
+
{status?.plan !== 'free' && (
|
| 270 |
+
<>
|
| 271 |
+
{/* Keyword Limit */}
|
| 272 |
+
<div className="space-y-1">
|
| 273 |
+
<div className="flex justify-between text-[9px] font-bold text-foreground/30 uppercase">
|
| 274 |
+
<span>Keywords Searched</span>
|
| 275 |
+
<span>{status?.daily_keyword_count || 0} / {status?.max_daily_keywords || 5}</span>
|
| 276 |
+
</div>
|
| 277 |
+
<div className="h-1 w-full bg-foreground/5 rounded-full overflow-hidden">
|
| 278 |
+
<div
|
| 279 |
+
className="h-full bg-emerald-500 transition-all duration-1000"
|
| 280 |
+
style={{ width: `${Math.min(100, ((status?.daily_keyword_count || 0) / (status?.max_daily_keywords || 5)) * 100)}%` }}
|
| 281 |
+
/>
|
| 282 |
+
</div>
|
| 283 |
+
</div>
|
| 284 |
|
| 285 |
+
{/* Scrape Power */}
|
| 286 |
+
<div className="flex justify-between text-[9px] font-bold text-foreground/30 uppercase">
|
| 287 |
+
<span>Scrape Limit</span>
|
| 288 |
+
<span className="text-foreground/60">{status?.scrape_limit || 50} / search</span>
|
| 289 |
+
</div>
|
| 290 |
+
</>
|
| 291 |
+
)}
|
| 292 |
</div>
|
| 293 |
|
| 294 |
<div className="pt-2 border-t border-border/50">
|