File size: 11,959 Bytes
60e9648
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
from aiohttp import web
import markdown
import os
import psutil
import shutil
import platform

routes = web.RouteTableDef()

@routes.get("/", allow_head=True)
async def root_route_handler(request):
    # Try directory path containing this file first, then check parent directory
    readme_path = os.path.join(os.path.dirname(__file__), "README.md")
    if not os.path.exists(readme_path):
        readme_path = os.path.join(os.path.dirname(os.path.dirname(__file__)), "README.md")
        
    if os.path.exists(readme_path):
        with open(readme_path, "r", encoding="utf-8") as f:
            md_text = f.read()
        
        # Strip YAML frontmatter if present (Hugging Face metadata tags)
        if md_text.startswith("---"):
            parts = md_text.split("---", 2)
            if len(parts) >= 3:
                md_text = parts[2].strip()
        
        readme_html = markdown.markdown(md_text, extensions=["fenced_code", "codehilite", "tables"])
    else:
        readme_html = "<h3>Yugen File Store Bot Documentation</h3><p>README.md not found. Create it in the root or plugins folder to display documentation here.</p>"

    # Fetch system metrics using psutil and shutil
    try:
        cpu_usage = psutil.cpu_percent()
        ram_usage = psutil.virtual_memory().percent
        total, used, free = shutil.disk_usage("/")
        disk_usage = round((used / total) * 100, 1)
    except Exception:
        cpu_usage = 0
        ram_usage = 0
        disk_usage = 0

    space_id = os.environ.get("SPACE_ID", "Local Node")
    
    html_page = f"""<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>File Store Bot - Dashboard</title>
    <link href="https://fonts.googleapis.com/css2?family=Plus+Jakarta+Sans:wght@300;400;500;600;700&display=swap" rel="stylesheet">
    <style>
        :root {{
            --bg-color: #0b0f19;
            --card-bg: rgba(17, 24, 39, 0.7);
            --border-color: rgba(255, 255, 255, 0.08);
            --text-primary: #f3f4f6;
            --text-secondary: #9ca3af;
            --accent-color: #6366f1;
            --accent-glow: rgba(99, 102, 241, 0.15);
            --success-color: #10b981;
        }}

        body {{
            font-family: 'Plus Jakarta Sans', sans-serif;
            background-color: var(--bg-color);
            background-image: 
                radial-gradient(at 0% 0%, rgba(99, 102, 241, 0.15) 0px, transparent 50%),
                radial-gradient(at 100% 100%, rgba(168, 85, 247, 0.15) 0px, transparent 50%);
            color: var(--text-primary);
            margin: 0;
            padding: 2rem 1rem;
            min-height: 100vh;
            display: flex;
            justify-content: center;
            align-items: center;
            box-sizing: border-box;
        }}

        .container {{
            max-width: 800px;
            width: 100%;
            background: var(--card-bg);
            backdrop-filter: blur(16px);
            border: 1px solid var(--border-color);
            border-radius: 24px;
            padding: 2.5rem;
            box-shadow: 0 20px 40px rgba(0, 0, 0, 0.4), inset 0 1px 0 rgba(255, 255, 255, 0.1);
        }}

        .header {{
            display: flex;
            align-items: center;
            justify-content: space-between;
            border-bottom: 1px solid var(--border-color);
            padding-bottom: 1.5rem;
            margin-bottom: 2rem;
            flex-wrap: wrap;
            gap: 1rem;
        }}

        .bot-profile {{
            display: flex;
            align-items: center;
            gap: 1rem;
        }}

        .bot-avatar {{
            font-size: 2rem;
            background: linear-gradient(135deg, #6366f1, #a855f7);
            padding: 0.5rem;
            border-radius: 16px;
            display: flex;
            align-items: center;
            justify-content: center;
            box-shadow: 0 8px 16px rgba(99, 102, 241, 0.3);
            width: 40px;
            height: 40px;
        }}

        .bot-info h1 {{
            margin: 0;
            font-size: 1.5rem;
            font-weight: 700;
            letter-spacing: -0.025em;
        }}

        .bot-info p {{
            margin: 4px 0 0;
            font-size: 0.875rem;
            color: var(--text-secondary);
        }}

        .status-badge {{
            display: flex;
            align-items: center;
            gap: 8px;
            background: rgba(16, 185, 129, 0.1);
            border: 1px solid rgba(16, 185, 129, 0.2);
            padding: 6px 12px;
            border-radius: 9999px;
            font-size: 0.813rem;
            font-weight: 600;
            color: var(--success-color);
        }}

        .status-dot {{
            width: 8px;
            height: 8px;
            background-color: var(--success-color);
            border-radius: 50%;
            display: inline-block;
            box-shadow: 0 0 8px var(--success-color);
            animation: pulse 2s infinite;
        }}

        @keyframes pulse {{
            0% {{ transform: scale(0.95); box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.7); }}
            70% {{ transform: scale(1); box-shadow: 0 0 0 6px rgba(16, 185, 129, 0); }}
            100% {{ transform: scale(0.95); box-shadow: 0 0 0 0 rgba(16, 185, 129, 0); }}
        }}

        .stats-grid {{
            display: grid;
            grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
            gap: 1.5rem;
            margin-bottom: 2rem;
        }}

        .stat-card {{
            background: rgba(255, 255, 255, 0.03);
            border: 1px solid var(--border-color);
            border-radius: 16px;
            padding: 1.25rem;
            transition: all 0.3s ease;
        }}

        .stat-card:hover {{
            transform: translateY(-2px);
            border-color: var(--accent-color);
            box-shadow: 0 8px 24px var(--accent-glow);
        }}

        .stat-label {{
            font-size: 0.813rem;
            color: var(--text-secondary);
            text-transform: uppercase;
            letter-spacing: 0.05em;
            margin-bottom: 8px;
        }}

        .stat-value {{
            font-size: 1.5rem;
            font-weight: 700;
            margin-bottom: 12px;
        }}

        .progress-bar-bg {{
            background: rgba(255, 255, 255, 0.08);
            height: 6px;
            border-radius: 9999px;
            overflow: hidden;
        }}

        .progress-bar-fill {{
            background: linear-gradient(90deg, #6366f1, #a855f7);
            height: 100%;
            border-radius: 9999px;
            transition: width 0.5s ease-out;
        }}

        .links-flex {{
            display: flex;
            gap: 1rem;
            flex-wrap: wrap;
            margin-bottom: 2rem;
        }}

        .btn {{
            flex: 1;
            min-width: 140px;
            display: inline-flex;
            align-items: center;
            justify-content: center;
            gap: 8px;
            padding: 0.75rem 1.25rem;
            border-radius: 12px;
            font-size: 0.875rem;
            font-weight: 600;
            text-decoration: none;
            transition: all 0.2s ease;
            box-sizing: border-box;
        }}

        .btn-primary {{
            background: linear-gradient(135deg, #6366f1, #4f46e5);
            color: #fff;
            box-shadow: 0 4px 12px rgba(99, 102, 241, 0.25);
        }}

        .btn-primary:hover {{
            transform: translateY(-1px);
            box-shadow: 0 6px 16px rgba(99, 102, 241, 0.4);
        }}

        .btn-secondary {{
            background: rgba(255, 255, 255, 0.05);
            color: var(--text-primary);
            border: 1px solid var(--border-color);
        }}

        .btn-secondary:hover {{
            background: rgba(255, 255, 255, 0.1);
            border-color: rgba(255, 255, 255, 0.2);
        }}

        .readme-section {{
            border-top: 1px solid var(--border-color);
            padding-top: 2rem;
            margin-top: 2rem;
        }}

        .readme-title {{
            font-size: 1.125rem;
            font-weight: 600;
            color: var(--text-secondary);
            margin-bottom: 1rem;
            text-transform: uppercase;
            letter-spacing: 0.05em;
        }}

        .markdown-body {{
            color: var(--text-secondary);
            font-size: 0.938rem;
            line-height: 1.6;
        }}

        .markdown-body h1, .markdown-body h2, .markdown-body h3 {{
            color: var(--text-primary);
            font-weight: 600;
            margin-top: 1.5rem;
            margin-bottom: 0.75rem;
        }}

        .markdown-body p {{
            margin-bottom: 1rem;
        }}

        .markdown-body a {{
            color: var(--accent-color);
            text-decoration: none;
        }}

        .markdown-body a:hover {{
            text-decoration: underline;
        }}

        .markdown-body code {{
            font-family: monospace;
            background: rgba(255, 255, 255, 0.06);
            padding: 2px 6px;
            border-radius: 4px;
            font-size: 0.85em;
            color: #f43f5e;
        }}

        .markdown-body pre {{
            background: #1e1e2e;
            padding: 1rem;
            border-radius: 12px;
            overflow-x: auto;
            border: 1px solid var(--border-color);
        }}

        .markdown-body pre code {{
            background: transparent;
            padding: 0;
            color: unset;
            font-size: 0.9em;
        }}
    </style>
</head>
<body>
    <div class="container">
        <div class="header">
            <div class="bot-profile">
                <div class="bot-avatar">📂</div>
                <div class="bot-info">
                    <h1>File Store Bot</h1>
                    <p>Live on: {space_id}</p>
                </div>
            </div>
            <div class="status-badge">
                <span class="status-dot"></span>
                <span>RUNNING</span>
            </div>
        </div>

        <div class="stats-grid">
            <div class="stat-card">
                <div class="stat-label">CPU Usage</div>
                <div class="stat-value">{cpu_usage}%</div>
                <div class="progress-bar-bg">
                    <div class="progress-bar-fill" style="width: {cpu_usage}%"></div>
                </div>
            </div>
            <div class="stat-card">
                <div class="stat-label">RAM Usage</div>
                <div class="stat-value">{ram_usage}%</div>
                <div class="progress-bar-bg">
                    <div class="progress-bar-fill" style="width: {ram_usage}%"></div>
                </div>
            </div>
            <div class="stat-card">
                <div class="stat-label">Disk Storage</div>
                <div class="stat-value">{disk_usage}%</div>
                <div class="progress-bar-bg">
                    <div class="progress-bar-fill" style="width: {disk_usage}%"></div>
                </div>
            </div>
        </div>

        <div class="links-flex">
            <a href="https://t.me/AnimePiratesTamil" target="_blank" class="btn btn-primary">
                <span>Join Channel</span>
            </a>
            <a href="https://huggingface.co" target="_blank" class="btn btn-secondary">
                <span>Hugging Face Space</span>
            </a>
        </div>

        <div class="readme-section">
            <div class="readme-title">Documentation</div>
            <div class="markdown-body">
                {readme_html}
            </div>
        </div>
    </div>
</body>
</html>"""
    return web.Response(text=html_page, content_type="text/html")


app = web.Application()
app.add_routes(routes)

if __name__ == "__main__":
    web.run_app(app, port=8080)