File size: 1,962 Bytes
222f19c
350b6eb
 
 
4b81f85
3140238
4b81f85
350b6eb
222f19c
350b6eb
222f19c
350b6eb
 
 
 
 
3140238
350b6eb
 
 
 
 
222f19c
350b6eb
4b81f85
350b6eb
 
 
 
 
 
 
 
 
4b81f85
350b6eb
 
 
4b81f85
350b6eb
 
 
 
 
 
4b81f85
 
 
 
350b6eb
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
222f19c
350b6eb
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# main.py
import os
import logging
import asyncio

from fastapi import FastAPI
from fastapi.responses import HTMLResponse
import uvicorn

from bot import bot, setup_dispatcher, TASK_QUEUE, BATCH_JOBS

# Setup logging
logging.basicConfig(
    level=logging.INFO,
    format="%(asctime)s - %(name)s - %(levelname)s - %(message)s",
)

app = FastAPI(
    title="Terabox Bot Admin",
    description="Web interface for checking Terabox Bot status.",
    version="1.0.0",
)

dp = setup_dispatcher()

@app.on_event("startup")
async def on_startup():
    logging.info("Starting bot polling in background...")
    asyncio.create_task(dp.start_polling(bot))

# Routes
@app.get("/", response_class=HTMLResponse)
async def root():
    return """
    <html>
    <head>
        <title>Terabox Bot - Admin Panel</title>
    </head>
    <body>
        <h2>πŸš€ Terabox Bot is running!</h2>
        <p>Endpoints:</p>
        <ul>
            <li><a href="/health">/health</a> β†’ Health check</li>
            <li><a href="/status">/status</a> β†’ Bot queue status</li>
        </ul>
    </body>
    </html>
    """

@app.get("/health")
async def health():
    return {"status": "ok", "message": "Bot is healthy!"}

@app.get("/status", response_class=HTMLResponse)
async def status():
    html = "<h3>πŸ“Š Terabox Bot - Current Status</h3>"
    html += f"<p>Pending queue size: {TASK_QUEUE.qsize()}</p>"

    if not BATCH_JOBS:
        html += "<p>βœ… No active batches.</p>"
    else:
        html += "<ul>"
        for batch_id, batch in BATCH_JOBS.items():
            processed = batch["processed_links"]
            total = batch["total_links"]
            html += f"<li>Batch <b>{batch_id[:6]}</b>: {processed}/{total} processed</li>"
        html += "</ul>"

    return html

# Run with uvicorn
if __name__ == "__main__":
    port = int(os.getenv("PORT", 7860))  # HuggingFace prefers PORT env sometimes
    uvicorn.run("main:app", host="0.0.0.0", port=port, reload=False)