Karan Adhikari commited on
Commit
12bd388
·
unverified ·
1 Parent(s): 7274a13

Update dashboard.html

Browse files
Files changed (1) hide show
  1. Backend/fastapi/templates/dashboard.html +311 -610
Backend/fastapi/templates/dashboard.html CHANGED
@@ -3,480 +3,323 @@
3
  {% block title %}Dashboard - Telegram Stremio{% endblock %}
4
 
5
  {% block content %}
6
- <div class="min-h-screen">
7
- <!-- Header with just status pill -->
8
- <header class="theme-card shadow-lg mb-8">
9
- <div class="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8 py-6">
10
- <div class="flex items-center justify-between">
11
- <div class="flex items-center space-x-4">
12
- <h1 class="text-3xl font-bold text-primary">Dashboard</h1>
13
- </div>
14
- <button onclick="refreshSystemStats()"
15
- class="flex items-center space-x-2 px-4 py-2 rounded-lg bg-blue-600 hover:bg-blue-700 text-white transition-all shadow-md active:scale-95 group focus:outline-none"
16
- title="Refresh System Stats">
17
- <svg id="refresh-icon" xmlns="http://www.w3.org/2000/svg"
18
- class="w-5 h-5 group-hover:rotate-180 transition-transform duration-500" fill="none"
19
- viewBox="0 0 24 24" stroke="currentColor">
20
- <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
21
- d="M4 4v5h.582m15.356 2A8.001 8.001 0 004.582 9m0 0H9m11 11v-5h-.581m0 0a8.003 8.003 0 01-15.357-2m15.357 2H15" />
22
- </svg>
23
- <span class="font-medium">Refresh Data</span>
24
- </button>
25
  </div>
 
 
 
 
 
 
 
 
 
 
 
26
  </div>
27
- </header>
28
 
29
- <main class="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8 pb-12">
30
- <!-- System Status Section -->
31
- <div class="mb-8">
32
- <div class="grid lg:grid-cols-2 gap-8">
33
- <!-- System Status Card -->
34
- <div class="theme-card rounded-xl p-8 shadow-xl">
35
- <div class="flex items-center mb-6">
36
- <div
37
- class="w-12 h-12 theme-primary rounded-lg flex items-center justify-center mr-4 bg-opacity-20 text-primary">
38
- <svg xmlns="http://www.w3.org/2000/svg" class="w-6 h-6" fill="none" viewBox="0 0 24 24"
39
- stroke="white">
40
- <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
41
- d="M9 19v-6a2 2 0 00-2-2H5a2 2 0 00-2 2v6a2 2 0 002 2h2a2 2 0 002-2zm0 0V9a2 2 0 012-2h2a2 2 0 012 2v10m-6 0a2 2 0 002 2h2a2 2 0 002-2m0 0V5a2 2 0 012-2h2a2 2 0 012 2v14a2 2 0 01-2 2h-2a2 2 0 01-2-2z">
42
- </path>
43
- </svg>
44
- </div>
45
- <h3 class="text-2xl font-semibold">System Status</h3>
46
  </div>
 
 
47
 
48
- <div class="space-y-4">
49
- <div class="flex justify-between items-center py-3 px-4 bg-gray-50 rounded-lg">
50
- <span class="font-medium theme-text-secondary">Uptime</span>
51
- <span id="sys-uptime" class="text-primary font-semibold">{{ system_stats.uptime or 'N/A'
52
- }}</span>
53
- </div>
54
- <div class="flex justify-between items-center py-3 px-4 bg-gray-50 rounded-lg">
55
- <span class="font-medium theme-text-secondary">Telegram Bot</span>
56
- <span id="sys-bot-name" class="text-primary font-semibold">{{ system_stats.telegram_bot or
57
- '@StreamBot'
58
- }}</span>
59
- </div>
60
- <div class="flex justify-between items-center py-3 px-4 bg-gray-50 rounded-lg">
61
- <span class="font-medium theme-text-secondary">Connected Bots</span>
62
- <span id="sys-bots-count" class="text-primary font-semibold">{{
63
- system_stats.connected_bots|default(0) }}</span>
64
- </div>
65
- <div class="flex justify-between items-center py-3 px-4 bg-gray-50 rounded-lg">
66
- <span class="font-medium theme-text-secondary">Backend Version</span>
67
- <span id="sys-version" class="text-primary font-semibold">v{{ system_stats.version or
68
- '1.0.0' }}</span>
69
  </div>
70
  </div>
 
 
 
 
71
  </div>
 
72
 
73
- <!-- Bot Workload Section -->
74
- <!-- Live Streaming Status Card -->
75
- <div class="streams-container">
76
- <div class="theme-card rounded-xl p-8 shadow-xl">
77
- <div class="flex items-center mb-6">
78
- <div
79
- class="w-12 h-12 theme-primary rounded-lg flex items-center justify-center mr-4 bg-opacity-20 text-primary">
80
- <svg xmlns="http://www.w3.org/2000/svg" class="w-6 h-6" fill="none" viewBox="0 0 24 24"
81
- stroke="white">
82
- <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
83
- d="M14.752 11.168l-3.197-2.132A1 1 0 0010 9.87v4.263a1 1 0 001.555.832l3.197-2.132a1 1 0 000-1.664z">
84
- </path>
85
- <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
86
- d="M21 12a9 9 0 11-18 0 9 9 0 0118 0z"></path>
87
- </svg>
88
- </div>
89
- <div class="flex-1">
90
- <h3 class="text-2xl font-semibold">Live Streaming Status</h3>
91
  </div>
92
- <span class="px-3 py-1 bg-red-500 text-white rounded-full text-sm font-semibold">
93
- {{ system_stats.total_active_streams }} Active
94
- </span>
95
  </div>
 
 
 
 
96
 
97
- <div class="space-y-4">
98
- {% if system_stats.active_streams and system_stats.active_streams|length > 0 %}
99
  {% for stream in system_stats.active_streams %}
100
- <div
101
- class="p-4 bg-gray-50 rounded-lg border-l-4 {% if stream.status == 'active' %}border-green-500{% elif stream.status == 'cancelled' %}border-yellow-500{% else %}border-red-500{% endif %}">
102
- <div class="flex justify-between items-start mb-3">
103
- <div class="flex items-center gap-2 max-w-[70%]">
104
- <svg xmlns="http://www.w3.org/2000/svg" class="w-4 h-4 text-primary shrink-0"
105
- fill="currentColor" viewBox="0 0 24 24">
106
- <path d="M8 5v14l11-7z" />
107
- </svg>
108
  <div class="truncate">
109
- <span class="font-semibold"
110
- title="{{ stream.meta.get('title') or stream.stream_id }}">{{
111
- stream.meta.get('title') or
112
- 'Unknown Stream' }}</span>
113
- <div class="text-[10px] text-gray-500 font-mono mt-0.5"
114
- title="{{ stream.stream_id }}">
115
- ID: {{ stream.stream_id[:8] }}...
116
- </div>
117
  </div>
118
  </div>
119
- <span
120
- class="px-2 py-1 rounded text-xs font-semibold shrink-0 {% if stream.status == 'active' %}bg-green-100 text-green-800{% elif stream.status == 'cancelled' %}bg-yellow-100 text-yellow-800{% else %}bg-red-100 text-red-800{% endif %}">
121
- {{ stream.status|upper }}
122
  </span>
123
  </div>
124
-
125
- <div class="grid grid-cols-2 gap-3 mb-3">
126
- <div class="flex justify-between py-2 px-3 bg-white rounded">
127
- <span class="text-sm theme-text-secondary">Bot:</span>
128
- <span class="text-sm font-semibold">Bot{{ stream.client_index + 1 }} </span>
129
- </div>
130
- <div class="flex justify-between py-2 px-3 bg-white rounded">
131
- <span class="text-sm theme-text-secondary">File:</span>
132
- <span class="text-sm font-semibold">DC{{ stream.dc_id }}</span>
133
- </div>
134
- <div class="flex justify-between py-2 px-3 bg-white rounded col-span-2">
135
- <span class="text-sm theme-text-secondary">Duration:</span>
136
- <span class="text-sm font-semibold">{{ stream.duration }}s</span>
137
- </div>
138
-
139
- <div class="flex justify-between py-2 px-3 bg-white rounded col-span-2">
140
- <span class="text-sm theme-text-secondary">Data Transferred:</span>
141
- <span class="text-sm font-semibold">{{ "%.2f"|format(stream.total_bytes / 1024 /
142
- 1024) }} MB</span>
143
- </div>
144
  </div>
145
-
146
- <div class="grid grid-cols-3 gap-3">
147
- <div class="text-center py-3 bg-white rounded">
148
- <div class="text-xs theme-text-secondary mb-1">Instant</div>
149
- <div class="text-sm font-bold text-primary">{{ stream.instant_mbps }} MB/s</div>
150
- </div>
151
- <div class="text-center py-3 bg-white rounded">
152
- <div class="text-xs theme-text-secondary mb-1">Average</div>
153
- <div class="text-sm font-bold text-primary">{{ stream.avg_mbps }} MB/s</div>
154
- </div>
155
- <div class="text-center py-3 bg-white rounded">
156
- <div class="text-xs theme-text-secondary mb-1">Peak</div>
157
- <div class="text-sm font-bold text-primary">{{ stream.peak_mbps }} MB/s</div>
158
- </div>
159
  </div>
160
-
161
  {% if stream.meta and (stream.meta.client_host or stream.meta.user_name) %}
162
- <div class="mt-3 pt-3 border-t border-gray-200">
163
- <div class="flex flex-col gap-1">
164
- {% if stream.meta.client_host %}
165
- <div class="flex justify-between items-center text-sm">
166
- <div class="flex items-center gap-2">
167
- <svg xmlns="http://www.w3.org/2000/svg"
168
- class="w-4 h-4 theme-text-secondary" fill="none" viewBox="0 0 24 24"
169
- stroke="currentColor">
170
- <path stroke-linecap="round" stroke-linejoin="round"
171
- stroke-width="2"
172
- d="M21 12a9 9 0 01-9 9m9-9a9 9 0 00-9-9m9 9H3m9 9a9 9 0 01-9-9m9 9c1.657 0 3-4.03 3-9s-1.343-9-3-9m0 18c-1.657 0-3-4.03-3-9s1.343-9 3-9m-9 9a9 9 0 019-9">
173
- </path>
174
- </svg>
175
- <span class="theme-text-secondary">Client IPv4:</span>
176
- </div>
177
- <span class="font-mono text-xs">{{ stream.meta.client_host }}</span>
178
- </div>
179
- {% endif %}
180
- {% if stream.meta.user_name %}
181
- <div class="flex justify-between items-center text-sm">
182
- <div class="flex items-center gap-2">
183
- <svg xmlns="http://www.w3.org/2000/svg"
184
- class="w-4 h-4 theme-text-secondary" fill="none" viewBox="0 0 24 24"
185
- stroke="currentColor">
186
- <path stroke-linecap="round" stroke-linejoin="round"
187
- stroke-width="2"
188
- d="M16 7a4 4 0 11-8 0 4 4 0 018 0zM12 14a7 7 0 00-7 7h14a7 7 0 00-7-7z">
189
- </path>
190
- </svg>
191
- <span class="theme-text-secondary">User:</span>
192
- </div>
193
- <span class="font-mono text-xs font-semibold">{{ stream.meta.user_name
194
- }}</span>
195
- </div>
196
- {% endif %}
197
- </div>
198
  </div>
199
  {% endif %}
200
  </div>
201
  {% endfor %}
202
- {% else %}
203
- <div class="text-center py-12">
204
- <svg xmlns="http://www.w3.org/2000/svg" class="w-16 h-16 mx-auto mb-4 text-gray-300"
205
- fill="none" viewBox="0 0 24 24" stroke="currentColor">
206
- <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
207
- d="M14.752 11.168l-3.197-2.132A1 1 0 0010 9.87v4.263a1 1 0 001.555.832l3.197-2.132a1 1 0 000-1.664z">
208
- </path>
209
- <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
210
- d="M21 12a9 9 0 11-18 0 9 9 0 0118 0z"></path>
211
- </svg>
212
- <p class="text-gray-500 font-medium mb-1">No active streams</p>
213
- <p class="text-gray-400 text-sm">Streams will appear here when users start watching
214
- content</p>
215
  </div>
216
- {% endif %}
217
- </div>
218
  </div>
219
  </div>
220
  </div>
221
  </div>
222
 
223
- <!-- Database Statistics Section -->
224
- <div class="mb-8 mt-4">
225
- <h2 class="text-2xl font-bold mb-6 text-center">Database and Commands</h2>
226
  <div class="grid lg:grid-cols-2 gap-6">
227
  {% if system_stats.databases %}
228
- {% for db_stat in system_stats.databases %}
229
- <div class="theme-card rounded-xl p-8 shadow-xl w-full flex flex-col h-full">
230
- <div class="flex items-center justify-between mb-6">
231
- <h3 class="text-xl font-semibold">{{ db_stat.db_name.replace("storage_", "Database ") }}</h3>
232
- <div
233
- class="w-12 h-12 theme-primary rounded-lg flex items-center justify-center bg-opacity-20 text-primary">
234
- <svg xmlns="http://www.w3.org/2000/svg" class="w-6 h-6" fill="none" viewBox="0 0 24 24"
235
- stroke="white">
236
- <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
237
- d="M4 7v10c0 2.21 3.582 4 8 4s8-1.79 8-4V7M4 7c0 2.21 3.582 4 8 4s8-1.79 8-4M4 7c0-2.21 3.582-4 8-4s8 1.79 8 4">
238
- </path>
239
- </svg>
240
- </div>
241
- </div>
242
-
243
- <div class="space-y-4 flex-grow">
244
- <div class="flex justify-between items-center py-3 px-4 bg-gray-50 rounded-lg">
245
- <span class="font-medium theme-text-secondary">Movies</span>
246
- <span id="db-movies-{{ loop.index0 }}" class="text-primary font-semibold">{{
247
- "{:,}".format(db_stat.movie_count) }}</span>
248
- </div>
249
- <div class="flex justify-between items-center py-3 px-4 bg-gray-50 rounded-lg">
250
- <span class="font-medium theme-text-secondary">TV Shows</span>
251
- <span id="db-tv-{{ loop.index0 }}" class="text-primary font-semibold">{{
252
- "{:,}".format(db_stat.tv_count) }}</span>
253
  </div>
254
 
255
- <div class="py-3 px-4 bg-gray-50 rounded-lg">
256
- <div class="flex justify-between items-center mb-2">
257
- <span class="font-medium theme-text-secondary">Storage Used</span>
258
- <span id="db-storage-{{ loop.index0 }}" class="text-primary font-semibold text-sm">{{
259
- "%.1f"|format(db_stat.storageSize /
260
- 1024 / 1024) }} MB</span>
 
 
261
  </div>
262
- {% set storage_percent = (db_stat.storageSize / (500 * 1024 * 1024) * 100) | round %}
263
- <div class="w-full bg-gray-200 rounded-full h-2.5">
264
- <div class="theme-primary h-2.5 rounded-full" style="width: {{ storage_percent }}%">
 
 
 
 
 
 
 
 
265
  </div>
266
  </div>
267
  </div>
268
  </div>
269
- </div>
270
- {% endfor %}
271
  {% else %}
272
- <div class="col-span-full text-center theme-text-secondary py-8">No database statistics available</div>
273
- {% endif %} <!-- Add this closing tag -->
274
  </div>
275
  </div>
276
 
277
-
278
-
279
- <!-- Media Management Section -->
280
- <div class="mb-8">
281
  <div class="grid lg:grid-cols-2 gap-6">
282
- <a href="/media/manage?media_type=movie"
283
- class="block theme-card rounded-xl p-8 shadow-xl hover:shadow-2xl transition-all group w-full">
284
- <div class="flex items-center">
285
- <div
286
- class="w-16 h-16 theme-primary rounded-lg flex items-center justify-center mr-6 group-hover:scale-110 transition-transform bg-opacity-20 text-primary">
287
- <svg xmlns="http://www.w3.org/2000/svg" class="w-8 h-8" fill="none" viewBox="0 0 24 24"
288
- stroke="white">
289
- <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
290
- d="M7 4V2a1 1 0 011-1h8a1 1 0 011 1v2h4a1 1 0 110 2h-1v12a2 2 0 01-2-2V6H3a1 1 0 110-2h4zM9 6v10h6V6H9z">
291
- </path>
292
- </svg>
293
  </div>
294
  <div>
295
- <h3 class="text-xl font-semibold mb-2">Manage Movies</h3>
296
- <p class="theme-text-secondary">Edit and organize movie collections</p>
297
- <div class="mt-2 text-primary font-semibold text-sm">{{ system_stats.movies|default(0) }}
298
- movies</div>
299
  </div>
300
  </div>
301
  </a>
302
 
303
- <a href="/media/manage?media_type=tv"
304
- class="block theme-card rounded-xl p-8 shadow-xl hover:shadow-2xl transition-all group w-full">
305
- <div class="flex items-center">
306
- <div
307
- class="w-16 h-16 theme-primary rounded-lg flex items-center justify-center mr-6 group-hover:scale-110 transition-transform bg-opacity-20 text-primary">
308
- <svg xmlns="http://www.w3.org/2000/svg" class="w-8 h-8" fill="none" viewBox="0 0 24 24"
309
- stroke="white">
310
- <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
311
- d="M9.75 17L9 20l-1 1h8l-1-1-.75-3M3 13h18M5 17h14a2 2 0 002-2V5a2 2 0 00-2-2H5a2 2 0 00-2 2v10a2 2 0 002 2z">
312
- </path>
313
- </svg>
314
  </div>
315
  <div>
316
- <h3 class="text-xl font-semibold mb-2">Manage TV Shows</h3>
317
- <p class="theme-text-secondary">Edit and organize TV series</p>
318
- <div class="mt-2 text-primary font-semibold text-sm">{{ system_stats.tv_shows|default(0) }}
319
- shows</div>
320
  </div>
321
  </div>
322
  </a>
323
  </div>
324
  </div>
325
 
326
- <!-- Access Management Section -->
327
- <div class="theme-card rounded-xl p-8 shadow-xl mb-8">
328
- <div class="text-center mb-8">
329
- <div
330
- class="w-16 h-16 theme-primary rounded-full flex items-center justify-center mx-auto mb-4 bg-opacity-20 text-primary">
331
- <svg xmlns="http://www.w3.org/2000/svg" class="w-8 h-8" fill="none" viewBox="0 0 24 24"
332
- stroke="white">
333
- <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
334
- d="M15 7a2 2 0 012 2m4 0a6 6 0 01-7.743 5.743L11.536 16.464l-4.786 1.768a3 3 0 01-3.951-3.951l1.768-4.786L14.464 11.536A6 6 0 0121 9z">
335
- </path>
336
- </svg>
337
  </div>
338
- <h3 class="text-2xl font-bold mb-2">Access Management</h3>
339
- <p class="theme-text-secondary">Manage API tokens for Stremio addon access</p>
340
- </div>
341
-
342
- <!-- Create Token Form -->
343
- <div class="mb-8">
344
  <div id="create-btn-container">
345
- <button onclick="toggleCreateForm()"
346
- class="bg-blue-600 hover:bg-blue-700 text-white px-6 py-3 rounded-lg font-semibold transition-colors duration-200 flex items-center shadow-md">
347
- <svg xmlns="http://www.w3.org/2000/svg" class="w-5 h-5 mr-2" fill="none" viewBox="0 0 24 24"
348
- stroke="currentColor">
349
- <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
350
- d="M12 6v6m0 0v6m0-6h6m-6 0H6" />
351
- </svg>
352
- New Token
353
  </button>
354
  </div>
 
355
 
356
- <div id="create-form-container"
357
- class="hidden mt-4 bg-gray-50 p-6 rounded-xl border border-gray-200 transition-all duration-300">
358
- <form onsubmit="createToken(event)" class="flex flex-col md:flex-row gap-4 items-end">
359
- <div class="flex-1 w-full">
360
- <label class="block text-sm font-medium theme-text-secondary mb-1">Token Name</label>
361
- <input type="text" id="token-name" placeholder="E.g., Family iPad" required
362
- class="w-full theme-card border border-gray-300 rounded-lg px-4 py-3 focus:outline-none focus:border-primary">
363
- </div>
364
 
365
- <div class="w-full md:w-32">
366
- <label class="block text-sm font-medium theme-text-secondary mb-1">Daily Limit</label>
367
- <div class="relative">
368
- <input type="number" id="daily-limit" placeholder="0" step="0.1" min="0"
369
- class="w-full theme-card border border-gray-300 rounded-lg pl-4 pr-12 py-3 focus:outline-none focus:border-primary">
370
- <span class="absolute right-4 top-3 text-gray-400 text-sm pointer-events-none">GB</span>
371
- </div>
372
  </div>
 
373
 
374
- <div class="w-full md:w-32">
375
- <label class="block text-sm font-medium theme-text-secondary mb-1">Monthly Limit</label>
376
- <div class="relative">
377
- <input type="number" id="monthly-limit" placeholder="0" step="0.1" min="0"
378
- class="w-full theme-card border border-gray-300 rounded-lg pl-4 pr-12 py-3 focus:outline-none focus:border-primary">
379
- <span class="absolute right-4 top-3 text-gray-400 text-sm pointer-events-none">GB</span>
380
- </div>
381
  </div>
 
382
 
383
- <div class="flex gap-2 w-full md:w-auto">
384
- <button type="button" onclick="toggleCreateForm()"
385
- class="w-full md:w-auto bg-gray-200 text-gray-700 px-6 py-3 rounded-lg font-semibold hover:bg-gray-300 transition-colors duration-200">
386
- Cancel
387
- </button>
388
- <button type="submit"
389
- class="w-full md:w-auto bg-blue-600 hover:bg-blue-700 text-white px-6 py-3 rounded-lg font-semibold transition-colors duration-200 flex items-center justify-center">
390
- Create
391
- </button>
392
- </div>
393
- </form>
394
- </div>
395
  </div>
396
 
397
- <!-- Token List -->
398
- <div class="overflow-x-auto">
399
- <table class="w-full text-left border-collapse">
400
  <thead>
401
- <tr class="border-b border-gray-200">
402
- <th class="py-4 px-4 font-semibold theme-text-secondary">Name</th>
403
- <th class="py-4 px-4 font-semibold theme-text-secondary">Usage (Today / Month)</th>
404
- <th class="py-4 px-4 font-semibold theme-text-secondary">Limits (GB)</th>
405
- <th class="py-4 px-4 font-semibold theme-text-secondary">Manifest URL</th>
406
- <th class="py-4 px-4 font-semibold theme-text-secondary text-right">Actions</th>
407
  </tr>
408
  </thead>
409
- <tbody>
410
  {% for token in api_tokens %}
411
- <tr class="border-b border-gray-100 hover:bg-gray-50 transition-colors">
412
- <td class="py-4 px-4 font-medium">
413
- {{ token.name }}<br>
414
- <span class="text-xs theme-text-secondary">{{ token.created_at.strftime('%Y-%m-%d')
415
- }}</span>
416
  </td>
417
- <td class="py-4 px-4 text-sm">
418
- <span class="block">Today: <span class="font-semibold text-primary"
419
- data-bytes="{{ token.usage.daily.bytes|default(0) }}"></span></span>
420
- <span class="block text-gray-500">Month: <span
421
- data-bytes="{{ token.usage.monthly.bytes|default(0) }}"></span></span>
422
  </td>
423
- <td class="py-4 px-4 text-sm">
424
- <div class="text-gray-600">
425
- <div class="flex items-center gap-1">
426
- <span class="w-4 text-gray-400">D:</span>
427
- {% if token.limits.daily_limit_gb %}
428
- <span
429
- data-bytes="{{ (token.limits.daily_limit_gb * 1024 * 1024 * 1024)|int }}"></span>
430
- {% else %}
431
- <span>∞</span>
432
- {% endif %}
433
- </div>
434
- <div class="flex items-center gap-1">
435
- <span class="w-4 text-gray-400">M:</span>
436
- {% if token.limits.monthly_limit_gb %}
437
- <span
438
- data-bytes="{{ (token.limits.monthly_limit_gb * 1024 * 1024 * 1024)|int }}"></span>
439
- {% else %}
440
- <span>∞</span>
441
- {% endif %}
442
- </div>
443
  </div>
444
  </td>
445
- <td class="py-4 px-4">
446
- <div class="flex flex-col items-start space-y-1">
447
- <code
448
- class="text-xs bg-gray-100 text-gray-600 px-2 py-1 rounded select-all border border-gray-200">
449
- API={{ token.token[:3] }}.......{{ token.token[-3:] }}
450
  </code>
451
- <button
452
- onclick="copyUrl('{{ (request.base_url|string).replace('http:', 'https:') }}stremio/{{ token.token }}/manifest.json')"
453
- class="text-primary hover:text-opacity-80 flex items-center space-x-1 text-sm font-medium"
454
- title="Copy URL">
455
- <svg xmlns="http://www.w3.org/2000/svg" class="w-4 h-4" fill="none"
456
- viewBox="0 0 24 24" stroke="currentColor">
457
- <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
458
- d="M8 5H6a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2v-1M8 5a2 2 0 002 2h2a2 2 0 002-2M8 5a2 2 0 012-2h2a2 2 0 012 2m0 0h2a2 2 0 012 2v3m2 4H10m0 0l3-3m-3 3l3 3" />
459
- </svg>
460
- <span class="underline">Copy Link</span>
461
  </button>
462
  </div>
463
  </td>
464
- <td class="py-4 px-4 text-right">
465
- <button
466
- onclick="openEditModal('{{ token.token }}', '{{ token.limits.daily_limit_gb|default(0) }}', '{{ token.limits.monthly_limit_gb|default(0) }}')"
467
- class="text-blue-500 hover:text-blue-700 font-medium text-sm px-3 py-1 mr-2 rounded border border-blue-200 hover:bg-blue-50 transition-colors">
468
- Edit
469
- </button>
470
- <button onclick="revokeToken('{{ token.token }}')"
471
- class="text-red-500 hover:text-red-700 font-medium text-sm px-3 py-1 rounded border border-red-200 hover:bg-red-50 transition-colors">
472
- Revoke
473
- </button>
 
474
  </td>
475
  </tr>
476
  {% else %}
477
  <tr>
478
- <td colspan="5" class="py-8 text-center theme-text-secondary">No tokens found. Create one to
479
- get started.</td>
 
 
 
 
480
  </tr>
481
  {% endfor %}
482
  </tbody>
@@ -484,45 +327,39 @@
484
  </div>
485
  </div>
486
 
487
- <!-- Edit Limit Modal -->
488
- <div id="edit-modal" class="fixed inset-0 bg-black bg-opacity-50 hidden flex items-center justify-center z-50">
489
- <div class="bg-white rounded-lg p-6 w-full max-w-md shadow-xl transform transition-all">
490
- <h3 class="text-lg font-bold mb-4 theme-text-primary">Edit Token Limits</h3>
491
  <input type="hidden" id="edit-token-id">
492
 
493
- <div class="space-y-4">
494
  <div>
495
- <label class="block text-sm font-medium theme-text-secondary mb-1">Daily Limit (GB)</label>
496
  <input type="number" id="edit-daily" placeholder="0 for unlimited" step="0.1" min="0"
497
- class="w-full theme-card border border-gray-300 rounded-lg px-4 py-2 focus:outline-none focus:border-primary">
498
  </div>
499
  <div>
500
- <label class="block text-sm font-medium theme-text-secondary mb-1">Monthly Limit (GB)</label>
501
  <input type="number" id="edit-monthly" placeholder="0 for unlimited" step="0.1" min="0"
502
- class="w-full theme-card border border-gray-300 rounded-lg px-4 py-2 focus:outline-none focus:border-primary">
503
  </div>
504
  </div>
505
 
506
- <div class="mt-6 flex justify-end space-x-3">
507
- <button onclick="closeEditModal()"
508
- class="px-4 py-2 text-gray-600 hover:bg-gray-100 rounded-lg transition-colors">Cancel</button>
509
- <button onclick="saveTokenLimits()"
510
- class="px-4 py-2 bg-blue-600 hover:bg-blue-700 text-white rounded-lg transition-colors">Save
511
- Changes</button>
512
  </div>
513
  </div>
514
  </div>
515
-
516
-
517
  </main>
518
  </div>
519
 
520
- <!-- JS for Workload Updates -->
521
  <script>
 
522
  function toggleCreateForm() {
523
  const formContainer = document.getElementById('create-form-container');
524
  const btnContainer = document.getElementById('create-btn-container');
525
-
526
  if (formContainer.classList.contains('hidden')) {
527
  formContainer.classList.remove('hidden');
528
  btnContainer.classList.add('hidden');
@@ -533,13 +370,11 @@
533
  }
534
 
535
  let currentEditToken = null;
536
-
537
  function openEditModal(token, daily, monthly) {
538
  currentEditToken = token;
539
  document.getElementById('edit-token-id').value = token;
540
  document.getElementById('edit-daily').value = daily == 'None' ? 0 : daily;
541
  document.getElementById('edit-monthly').value = monthly == 'None' ? 0 : monthly;
542
-
543
  document.getElementById('edit-modal').classList.remove('hidden');
544
  }
545
 
@@ -550,23 +385,16 @@
550
 
551
  async function saveTokenLimits() {
552
  if (!currentEditToken) return;
553
-
554
  const daily = document.getElementById('edit-daily').value;
555
  const monthly = document.getElementById('edit-monthly').value;
556
-
557
  try {
558
  const response = await fetch('/api/tokens/' + currentEditToken, {
559
  method: 'PUT',
560
  headers: { 'Content-Type': 'application/json' },
561
- body: JSON.stringify({
562
- daily_limit_gb: daily,
563
- monthly_limit_gb: monthly
564
- })
565
  });
566
-
567
  if (response.ok) {
568
  closeEditModal();
569
- // Refresh page to show new limits (or update DOM dynamically if we want)
570
  window.location.reload();
571
  } else {
572
  alert("Failed to update limits");
@@ -578,39 +406,34 @@
578
  }
579
  </script>
580
 
581
- <!-- System Stats Auto-Refresh -->
582
  <script>
 
583
  async function refreshSystemStats() {
584
  const icon = document.getElementById('refresh-icon');
585
- if (icon) icon.classList.add('animate-spin'); // Add tailwind spin class
586
 
587
  try {
588
  const response = await fetch('/api/system/stats');
589
  if (response.ok) {
590
  const stats = await response.json();
591
-
592
- // Update Static Elements
593
  const elUptime = document.getElementById('sys-uptime');
594
  if (elUptime) elUptime.innerText = stats.uptime;
595
-
596
  const elBotName = document.getElementById('sys-bot-name');
597
  if (elBotName) elBotName.innerText = stats.telegram_bot;
598
-
599
  const elBotCount = document.getElementById('sys-bots-count');
600
  if (elBotCount) elBotCount.innerText = stats.connected_bots;
601
-
602
  const elVersion = document.getElementById('sys-version');
603
  if (elVersion) elVersion.innerText = 'v' + stats.version;
604
 
605
- // Update Database Stats
606
  if (stats.databases && Array.isArray(stats.databases)) {
607
  stats.databases.forEach((db, index) => {
608
  const elMovies = document.getElementById(`db-movies-${index}`);
609
  if (elMovies) elMovies.innerText = db.movie_count.toLocaleString();
610
-
611
  const elTv = document.getElementById(`db-tv-${index}`);
612
  if (elTv) elTv.innerText = db.tv_count.toLocaleString();
613
-
614
  const elStorage = document.getElementById(`db-storage-${index}`);
615
  if (elStorage) {
616
  const mb = db.storageSize / (1024 * 1024);
@@ -619,26 +442,19 @@
619
  });
620
  }
621
 
622
- // Update API Token Usage Data
623
  if (stats.api_tokens && Array.isArray(stats.api_tokens)) {
624
  stats.api_tokens.forEach((token, index) => {
625
- // Find all elements with data-bytes attributes for this token
626
  const tokenRows = document.querySelectorAll('tbody tr');
627
-
628
- // Get the token's row (skip the "No tokens found" row)
629
  if (tokenRows.length > index && !tokenRows[index].querySelector('[colspan]')) {
630
  const row = tokenRows[index];
631
-
632
- // Update daily usage
633
- const dailyUsageSpan = row.querySelector('td:nth-child(2) span.font-semibold');
634
  if (dailyUsageSpan && token.usage && token.usage.daily) {
635
  const dailyBytes = token.usage.daily.bytes || 0;
636
  dailyUsageSpan.setAttribute('data-bytes', dailyBytes);
637
  dailyUsageSpan.textContent = formatBytes(dailyBytes);
638
  }
639
-
640
- // Update monthly usage
641
- const monthlyUsageSpan = row.querySelector('td:nth-child(2) span.text-gray-500 span');
642
  if (monthlyUsageSpan && token.usage && token.usage.monthly) {
643
  const monthlyBytes = token.usage.monthly.bytes || 0;
644
  monthlyUsageSpan.setAttribute('data-bytes', monthlyBytes);
@@ -648,19 +464,13 @@
648
  });
649
  }
650
 
651
- // Update Bot Workloads
652
- await updateBotWorkloads();
653
-
654
- // Update Active Streams
655
  await updateActiveStreams();
656
  }
657
  } catch (error) {
658
  console.error("Failed to refresh system stats:", error);
659
  } finally {
660
- // Remove spin after short delay to make it visible
661
- setTimeout(() => {
662
- if (icon) icon.classList.remove('animate-spin');
663
- }, 500);
664
  }
665
  }
666
 
@@ -671,33 +481,21 @@
671
  const data = await response.json();
672
  const allStreams = data.active_streams || [];
673
  const container = document.getElementById('active-streams-container');
674
- // Only show streams that are actively sending data
675
- const now = Date.now() / 1000;
676
-
677
- const liveStreams = allStreams.filter(s =>
678
- s.status === 'active' &&
679
- (s.total_bytes || 0) > 0 &&
680
- (now - (s.start_ts || now)) < 15
681
- );
682
 
683
  if (liveStreams.length === 0) {
684
- container.innerHTML = `<div class="p-8 text-center bg-gray-50 border border-dashed rounded-lg">
685
- <i class="fas fa-video-slash text-gray-300 text-3xl mb-3"></i>
686
- <p class="text-gray-500 font-medium">No active streams at the moment</p>
687
- <p class="text-xs text-gray-400 mt-1">Users are not currently watching any media.</p>
688
- </div>`;
 
 
689
  } else {
690
  const escapeHtml = (unsafe) => {
691
  if (!unsafe) return '';
692
- return unsafe
693
- .toString()
694
- .replace(/&/g, "&amp;")
695
- .replace(/</g, "&lt;")
696
- .replace(/>/g, "&gt;")
697
- .replace(/"/g, "&quot;")
698
- .replace(/'/g, "&#039;");
699
  };
700
-
701
  const formatBytesStr = (bytes) => {
702
  if (bytes === 0) return '0 B';
703
  const k = 1024;
@@ -706,210 +504,118 @@
706
  return parseFloat((bytes / Math.pow(k, i)).toFixed(2)) + ' ' + sizes[i];
707
  };
708
 
 
709
  container.innerHTML = liveStreams.map(stream => {
710
- let statusColor = 'bg-red-100 text-red-800';
711
- let statusPulse = 'hidden';
712
- if (stream.status === 'active') {
713
- statusColor = 'bg-green-100 text-green-800';
714
- statusPulse = '';
715
- } else if (stream.status === 'cancelled') {
716
- statusColor = 'bg-yellow-100 text-yellow-800';
717
- }
718
 
719
  const streamIdStr = stream.stream_id ? stream.stream_id.substring(0, 8) + '...' : 'Unknown';
720
  const titleStr = (stream.meta && stream.meta.title) ? stream.meta.title : (stream.title || 'Unknown Stream');
721
 
722
  return `
723
- <div class="p-4 bg-gray-50 rounded-lg border-l-4 border-green-500">
724
- <div class="flex justify-between items-start mb-3">
725
- <div class="flex items-center gap-2 max-w-[70%]">
726
- <svg xmlns="http://www.w3.org/2000/svg" class="w-4 h-4 text-primary shrink-0" fill="currentColor" viewBox="0 0 24 24">
727
- <path d="M8 5v14l11-7z" />
728
- </svg>
729
  <div class="truncate">
730
- <span class="font-semibold" title="${escapeHtml(stream.title || stream.stream_id)}">${escapeHtml(titleStr)}</span>
731
- <div class="text-[10px] text-gray-500 font-mono mt-0.5" title="${escapeHtml(stream.stream_id)}">
732
- ID: ${escapeHtml(streamIdStr)}
733
- </div>
734
  </div>
735
  </div>
736
- <span class="px-2 py-1 rounded text-xs font-semibold shrink-0 uppercase ${statusColor}">
737
  ${escapeHtml(stream.status)}
738
  </span>
739
  </div>
740
-
741
- <div class="grid grid-cols-2 gap-3 mb-3">
742
- <div class="flex justify-between py-2 px-3 bg-white rounded">
743
- <span class="text-sm theme-text-secondary">Bot:</span>
744
- <span class="text-sm font-semibold">Bot${(stream.client_index || 0) + 1} </span>
745
- </div>
746
- <div class="flex justify-between py-2 px-3 bg-white rounded">
747
- <span class="text-sm theme-text-secondary">File:</span>
748
- <span class="text-sm font-semibold">DC${stream.dc_id || '-'}</span>
749
- </div>
750
- <div class="flex justify-between py-2 px-3 bg-white rounded col-span-2">
751
- <span class="text-sm theme-text-secondary">Duration:</span>
752
- <span class="text-sm font-semibold">${stream.duration || 0}s</span>
753
- </div>
754
-
755
- <div class="flex justify-between py-2 px-3 bg-white rounded col-span-2">
756
- <span class="text-sm theme-text-secondary">Data Transferred:</span>
757
- <span class="text-sm font-semibold">${formatBytesStr(stream.total_bytes)}</span>
758
- </div>
759
- </div>
760
-
761
- <div class="grid grid-cols-3 gap-3">
762
- <div class="text-center py-3 bg-white rounded">
763
- <div class="text-xs theme-text-secondary mb-1">Instant</div>
764
- <div class="text-sm font-bold text-primary">${stream.instant_mbps || 0} MB/s</div>
765
- </div>
766
- <div class="text-center py-3 bg-white rounded">
767
- <div class="text-xs theme-text-secondary mb-1">Average</div>
768
- <div class="text-sm font-bold text-primary">${stream.avg_mbps || 0} MB/s</div>
769
- </div>
770
- <div class="text-center py-3 bg-white rounded">
771
- <div class="text-xs theme-text-secondary mb-1">Peak</div>
772
- <div class="text-sm font-bold text-primary">${stream.peak_mbps || 0} MB/s</div>
773
- </div>
774
  </div>
 
 
 
 
775
  </div>
776
-
777
  ${stream.meta && (stream.meta.client_host || stream.meta.user_name) ? `
778
- <div class="mt-3 pt-3 border-t border-gray-200">
779
- <div class="flex flex-col gap-1">
780
- ${stream.meta.client_host ? `
781
- <div class="flex justify-between items-center text-sm">
782
- <div class="flex items-center gap-2">
783
- <svg xmlns="http://www.w3.org/2000/svg" class="w-4 h-4 theme-text-secondary" fill="none" viewBox="0 0 24 24" stroke="currentColor">
784
- <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M21 12a9 9 0 01-9 9m9-9a9 9 0 00-9-9m9 9H3m9 9a9 9 0 01-9-9m9 9c1.657 0 3-4.03 3-9s-1.343-9-3-9m0 18c-1.657 0-3-4.03-3-9s1.343-9 3-9m-9 9a9 9 0 019-9"></path>
785
- </svg>
786
- <span class="theme-text-secondary">Client IPv4:</span>
787
- </div>
788
- <span class="font-mono text-xs">${escapeHtml(stream.meta.client_host)}</span>
789
- </div>
790
- ` : ''}
791
- ${stream.meta.user_name ? `
792
- <div class="flex justify-between items-center text-sm">
793
- <div class="flex items-center gap-2">
794
- <svg xmlns="http://www.w3.org/2000/svg" class="w-4 h-4 theme-text-secondary" fill="none" viewBox="0 0 24 24" stroke="currentColor">
795
- <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M16 7a4 4 0 11-8 0 4 4 0 018 0zM12 14a7 7 0 00-7 7h14a7 7 0 00-7-7z"></path>
796
- </svg>
797
- <span class="theme-text-secondary">User:</span>
798
- </div>
799
- <span class="font-mono text-xs font-semibold">${escapeHtml(stream.meta.user_name)}</span>
800
- </div>
801
- ` : ''}
802
- </div>
803
- </div>
804
- ` : ''}
805
  </div>
806
- `;
807
  }).join('');
808
  }
809
  }
810
- }
811
  } catch (error) {
812
- console.error("Failed to update active streams:", error);
813
- }
814
  }
815
 
816
- // Auto-refresh every 2 minutes
817
  const statsInterval = setInterval(refreshSystemStats, 120000);
818
- </script>
819
- <script>
820
  async function createToken(event) {
821
  event.preventDefault();
822
- const nameInput = document.getElementById('token-name');
823
- const dailyInput = document.getElementById('daily-limit');
824
- const monthlyInput = document.getElementById('monthly-limit');
825
-
826
  const payload = {
827
- name: nameInput.value,
828
- daily_limit_gb: dailyInput.value,
829
- monthly_limit_gb: monthlyInput.value
830
  };
831
-
832
  try {
833
  const response = await fetch('/api/tokens', {
834
  method: 'POST',
835
  headers: { 'Content-Type': 'application/json' },
836
  body: JSON.stringify(payload)
837
  });
838
-
839
  if (response.ok) {
840
- showToast('Token created successfully!');
841
  setTimeout(() => window.location.reload(), 1000);
842
  } else {
843
  const data = await response.json();
844
- showToast('Error: ' + data.detail);
845
  }
846
  } catch (error) {
847
- showToast('Error creating token');
848
  }
849
  }
850
 
851
  async function revokeToken(token) {
852
  if (!confirm('Are you sure you want to revoke this token? The user will lose access immediately.')) return;
853
-
854
  try {
855
- const response = await fetch('/api/tokens/' + token, {
856
- method: 'DELETE'
857
- });
858
-
859
  if (response.ok) {
860
- showToast('Token revoked successfully!');
861
  setTimeout(() => window.location.reload(), 1000);
862
  } else {
863
- showToast('Error revoking token');
864
  }
865
  } catch (error) {
866
- showToast('Error revoking token');
867
  }
868
  }
869
 
870
  function copyUrl(url) {
871
  navigator.clipboard.writeText(url).then(function () {
872
- showToast('Manifest URL copied to clipboard!');
873
- });
874
- }
875
- </script>
876
- </main>
877
- </div>
878
-
879
- <script>
880
- function copyToClipboard() {
881
- const manifestUrl = document.getElementById('manifest-url').value;
882
- navigator.clipboard.writeText(manifestUrl).then(function () {
883
- showToast('Manifest URL copied to clipboard!');
884
  });
885
  }
886
 
887
- function showToast(message, duration = 3000) {
888
  const toast = document.createElement('div');
889
- toast.className = 'fixed top-4 right-4 bg-blue-600 text-white px-6 py-3 rounded-lg shadow-lg z-50 transform transition-all duration-300 translate-x-full';
890
- toast.textContent = message;
 
891
  document.body.appendChild(toast);
892
-
893
- setTimeout(() => toast.classList.remove('translate-x-full'), 100);
894
  setTimeout(() => {
895
- toast.classList.add('translate-x-full');
896
  setTimeout(() => document.body.removeChild(toast), 300);
897
  }, duration);
898
  }
899
 
900
- function toggleAccordion(id) {
901
- const content = document.getElementById(id);
902
- const icon = document.getElementById(id + '-icon');
903
-
904
- if (content.classList.contains('hidden')) {
905
- content.classList.remove('hidden');
906
- icon.classList.add('rotate-180');
907
- } else {
908
- content.classList.add('hidden');
909
- icon.classList.remove('rotate-180');
910
- }
911
- }
912
-
913
  function formatBytes(bytes, decimals = 2) {
914
  if (!+bytes) return '0 B';
915
  const k = 1024;
@@ -919,18 +625,13 @@
919
  return `${parseFloat((bytes / Math.pow(k, i)).toFixed(dm))} ${sizes[i]}`;
920
  }
921
 
922
- // Auto-format bytes on load
923
  document.addEventListener("DOMContentLoaded", () => {
924
  document.querySelectorAll('[data-bytes]').forEach(el => {
925
  el.textContent = formatBytes(el.getAttribute('data-bytes'));
926
  });
927
-
928
- // Store the first API token in localStorage so other pages (e.g. media edit) can build stream links
929
  {% if api_tokens %}
930
  const firstToken = '{{ api_tokens[0].token }}';
931
- if (firstToken) {
932
- localStorage.setItem('api_token', firstToken);
933
- }
934
  {% endif %}
935
  });
936
  </script>
 
3
  {% block title %}Dashboard - Telegram Stremio{% endblock %}
4
 
5
  {% block content %}
6
+ <div class="min-h-screen py-8">
7
+ <main class="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8 pb-12">
8
+
9
+ <div class="flex flex-col sm:flex-row items-start sm:items-center justify-between mb-10 gap-4">
10
+ <div>
11
+ <h1 class="text-3xl md:text-4xl font-extrabold text-transparent bg-clip-text bg-gradient-to-r from-blue-400 to-purple-400 mb-2">Overview Dashboard</h1>
12
+ <p class="text-gray-400">Monitor your system performance and user access.</p>
 
 
 
 
 
 
 
 
 
 
 
 
13
  </div>
14
+ <button onclick="refreshSystemStats()"
15
+ class="flex items-center space-x-2 px-5 py-2.5 rounded-xl bg-white/5 border border-white/10 hover:bg-white/10 text-white transition-all shadow-lg active:scale-95 group focus:outline-none backdrop-blur-md"
16
+ title="Refresh System Stats">
17
+ <svg id="refresh-icon" xmlns="http://www.w3.org/2000/svg"
18
+ class="w-5 h-5 text-purple-400 group-hover:rotate-180 transition-transform duration-500" fill="none"
19
+ viewBox="0 0 24 24" stroke="currentColor">
20
+ <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
21
+ d="M4 4v5h.582m15.356 2A8.001 8.001 0 004.582 9m0 0H9m11 11v-5h-.581m0 0a8.003 8.003 0 01-15.357-2m15.357 2H15" />
22
+ </svg>
23
+ <span class="font-semibold text-sm">Refresh Data</span>
24
+ </button>
25
  </div>
 
26
 
27
+ <div class="grid lg:grid-cols-2 gap-8 mb-8">
28
+
29
+ <div class="glass-panel rounded-2xl p-8 relative overflow-hidden group">
30
+ <div class="absolute -top-24 -right-24 w-48 h-48 bg-blue-500/20 rounded-full blur-[80px] pointer-events-none transition-all group-hover:bg-blue-500/30"></div>
31
+
32
+ <div class="flex items-center mb-8 relative z-10">
33
+ <div class="w-14 h-14 rounded-2xl bg-gradient-to-br from-blue-500/20 to-cyan-500/20 flex items-center justify-center mr-5 border border-blue-500/20 shadow-inner">
34
+ <i class="fas fa-server text-2xl text-blue-400"></i>
 
 
 
 
 
 
 
 
 
35
  </div>
36
+ <h3 class="text-2xl font-bold text-white tracking-tight">System Status</h3>
37
+ </div>
38
 
39
+ <div class="space-y-3 relative z-10">
40
+ <div class="flex justify-between items-center py-3.5 px-5 bg-black/20 rounded-xl border border-white/5 hover:border-white/10 transition-colors">
41
+ <span class="font-medium text-gray-400">Uptime</span>
42
+ <span id="sys-uptime" class="text-white font-semibold">{{ system_stats.uptime or 'N/A' }}</span>
43
+ </div>
44
+ <div class="flex justify-between items-center py-3.5 px-5 bg-black/20 rounded-xl border border-white/5 hover:border-white/10 transition-colors">
45
+ <span class="font-medium text-gray-400">Telegram Bot</span>
46
+ <span id="sys-bot-name" class="text-blue-400 font-semibold">{{ system_stats.telegram_bot or '@StreamBot' }}</span>
47
+ </div>
48
+ <div class="flex justify-between items-center py-3.5 px-5 bg-black/20 rounded-xl border border-white/5 hover:border-white/10 transition-colors">
49
+ <span class="font-medium text-gray-400">Connected Bots</span>
50
+ <div class="flex items-center gap-2">
51
+ <span class="w-2 h-2 rounded-full bg-green-400 shadow-[0_0_8px_rgba(74,222,128,0.8)] animate-pulse"></span>
52
+ <span id="sys-bots-count" class="text-white font-semibold">{{ system_stats.connected_bots|default(0) }}</span>
 
 
 
 
 
 
 
53
  </div>
54
  </div>
55
+ <div class="flex justify-between items-center py-3.5 px-5 bg-black/20 rounded-xl border border-white/5 hover:border-white/10 transition-colors">
56
+ <span class="font-medium text-gray-400">Backend Version</span>
57
+ <span id="sys-version" class="bg-white/10 px-3 py-1 rounded-lg text-sm text-gray-200 font-mono border border-white/5">v{{ system_stats.version or '1.0.0' }}</span>
58
+ </div>
59
  </div>
60
+ </div>
61
 
62
+ <div class="streams-container">
63
+ <div class="glass-panel rounded-2xl p-8 relative overflow-hidden h-full flex flex-col group">
64
+ <div class="absolute -bottom-24 -left-24 w-48 h-48 bg-purple-500/20 rounded-full blur-[80px] pointer-events-none transition-all group-hover:bg-purple-500/30"></div>
65
+
66
+ <div class="flex items-center justify-between mb-8 relative z-10">
67
+ <div class="flex items-center">
68
+ <div class="w-14 h-14 rounded-2xl bg-gradient-to-br from-purple-500/20 to-pink-500/20 flex items-center justify-center mr-5 border border-purple-500/20 shadow-inner">
69
+ <i class="fas fa-broadcast-tower text-2xl text-purple-400"></i>
 
 
 
 
 
 
 
 
 
 
70
  </div>
71
+ <h3 class="text-2xl font-bold text-white tracking-tight">Live Streams</h3>
 
 
72
  </div>
73
+ <span class="px-4 py-1.5 bg-red-500/20 border border-red-500/30 text-red-400 rounded-full text-sm font-bold shadow-[0_0_15px_rgba(239,68,68,0.2)]">
74
+ {{ system_stats.total_active_streams }} Active
75
+ </span>
76
+ </div>
77
 
78
+ <div id="active-streams-container" class="space-y-4 flex-1 overflow-y-auto pr-2 relative z-10 custom-scrollbar max-h-[340px]">
79
+ {% if system_stats.active_streams and system_stats.active_streams|length > 0 %}
80
  {% for stream in system_stats.active_streams %}
81
+ <div class="p-5 bg-black/20 rounded-xl border-l-4 border border-white/5 {% if stream.status == 'active' %}border-l-green-500{% elif stream.status == 'cancelled' %}border-l-yellow-500{% else %}border-l-red-500{% endif %} shadow-md">
82
+ <div class="flex justify-between items-start mb-4">
83
+ <div class="flex items-center gap-3 max-w-[70%]">
84
+ <i class="fas fa-play-circle text-purple-400 text-lg"></i>
 
 
 
 
85
  <div class="truncate">
86
+ <span class="font-bold text-gray-100" title="{{ stream.meta.get('title') or stream.stream_id }}">{{ stream.meta.get('title') or 'Unknown Stream' }}</span>
87
+ <div class="text-xs text-gray-500 font-mono mt-1" title="{{ stream.stream_id }}">ID: {{ stream.stream_id[:8] }}...</div>
 
 
 
 
 
 
88
  </div>
89
  </div>
90
+ <span class="px-2.5 py-1 rounded-md text-[11px] font-bold tracking-wider uppercase {% if stream.status == 'active' %}bg-green-500/20 text-green-400 border border-green-500/30{% elif stream.status == 'cancelled' %}bg-yellow-500/20 text-yellow-400 border border-yellow-500/30{% else %}bg-red-500/20 text-red-400 border border-red-500/30{% endif %}">
91
+ {{ stream.status }}
 
92
  </span>
93
  </div>
94
+ <div class="grid grid-cols-2 gap-2 mb-3">
95
+ <div class="flex justify-between py-2 px-3 bg-white/5 rounded-lg border border-white/5"><span class="text-xs text-gray-400">Bot:</span><span class="text-xs text-white font-semibold">Bot{{ stream.client_index + 1 }}</span></div>
96
+ <div class="flex justify-between py-2 px-3 bg-white/5 rounded-lg border border-white/5"><span class="text-xs text-gray-400">File:</span><span class="text-xs text-white font-semibold">DC{{ stream.dc_id }}</span></div>
97
+ <div class="flex justify-between py-2 px-3 bg-white/5 rounded-lg border border-white/5 col-span-2"><span class="text-xs text-gray-400">Duration:</span><span class="text-xs text-white font-semibold">{{ stream.duration }}s</span></div>
98
+ <div class="flex justify-between py-2 px-3 bg-white/5 rounded-lg border border-white/5 col-span-2"><span class="text-xs text-gray-400">Transferred:</span><span class="text-xs text-white font-semibold">{{ "%.2f"|format(stream.total_bytes / 1024 / 1024) }} MB</span></div>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
99
  </div>
100
+ <div class="grid grid-cols-3 gap-2">
101
+ <div class="text-center py-2 bg-white/5 rounded-lg border border-white/5"><div class="text-[10px] text-gray-500 uppercase tracking-wider mb-1">Instant</div><div class="text-sm font-bold text-blue-400">{{ stream.instant_mbps }} <span class="text-[10px] text-gray-500">MB/s</span></div></div>
102
+ <div class="text-center py-2 bg-white/5 rounded-lg border border-white/5"><div class="text-[10px] text-gray-500 uppercase tracking-wider mb-1">Average</div><div class="text-sm font-bold text-purple-400">{{ stream.avg_mbps }} <span class="text-[10px] text-gray-500">MB/s</span></div></div>
103
+ <div class="text-center py-2 bg-white/5 rounded-lg border border-white/5"><div class="text-[10px] text-gray-500 uppercase tracking-wider mb-1">Peak</div><div class="text-sm font-bold text-pink-400">{{ stream.peak_mbps }} <span class="text-[10px] text-gray-500">MB/s</span></div></div>
 
 
 
 
 
 
 
 
 
 
104
  </div>
 
105
  {% if stream.meta and (stream.meta.client_host or stream.meta.user_name) %}
106
+ <div class="mt-3 pt-3 border-t border-white/10 text-xs">
107
+ {% if stream.meta.client_host %}<div class="flex justify-between mb-1"><span class="text-gray-500"><i class="fas fa-network-wired mr-1"></i> IPv4:</span><span class="font-mono text-gray-300">{{ stream.meta.client_host }}</span></div>{% endif %}
108
+ {% if stream.meta.user_name %}<div class="flex justify-between"><span class="text-gray-500"><i class="fas fa-user mr-1"></i> User:</span><span class="font-semibold text-gray-300">{{ stream.meta.user_name }}</span></div>{% endif %}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
109
  </div>
110
  {% endif %}
111
  </div>
112
  {% endfor %}
113
+ {% else %}
114
+ <div class="flex flex-col items-center justify-center py-12 px-4 h-full border border-dashed border-white/10 rounded-xl bg-white/5">
115
+ <div class="w-16 h-16 rounded-full bg-white/5 flex items-center justify-center mb-4 border border-white/5">
116
+ <i class="fas fa-video-slash text-2xl text-gray-500"></i>
117
+ </div>
118
+ <p class="text-gray-300 font-semibold mb-1">No active streams</p>
119
+ <p class="text-gray-500 text-sm text-center">Streams will appear here when users start watching content</p>
 
 
 
 
 
 
120
  </div>
121
+ {% endif %}
 
122
  </div>
123
  </div>
124
  </div>
125
  </div>
126
 
127
+ <div class="mb-10">
128
+ <h2 class="text-2xl font-bold mb-6 text-transparent bg-clip-text bg-gradient-to-r from-gray-100 to-gray-400">Storage & Collections</h2>
 
129
  <div class="grid lg:grid-cols-2 gap-6">
130
  {% if system_stats.databases %}
131
+ {% for db_stat in system_stats.databases %}
132
+ <div class="glass-panel rounded-2xl p-8 flex flex-col h-full relative overflow-hidden group hover:border-white/20 transition-all">
133
+ <div class="flex items-center justify-between mb-8">
134
+ <h3 class="text-xl font-bold text-white">{{ db_stat.db_name.replace("storage_", "Database ") }}</h3>
135
+ <div class="w-12 h-12 rounded-xl bg-gradient-to-br from-indigo-500/20 to-blue-500/20 flex items-center justify-center border border-indigo-500/20 text-indigo-400">
136
+ <i class="fas fa-database text-xl"></i>
137
+ </div>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
138
  </div>
139
 
140
+ <div class="space-y-4 flex-grow">
141
+ <div class="flex justify-between items-center py-3 px-5 bg-black/20 rounded-xl border border-white/5">
142
+ <span class="font-medium text-gray-400 flex items-center gap-2"><i class="fas fa-film text-gray-500"></i> Movies</span>
143
+ <span id="db-movies-{{ loop.index0 }}" class="text-white font-bold">{{ "{:,}".format(db_stat.movie_count) }}</span>
144
+ </div>
145
+ <div class="flex justify-between items-center py-3 px-5 bg-black/20 rounded-xl border border-white/5">
146
+ <span class="font-medium text-gray-400 flex items-center gap-2"><i class="fas fa-tv text-gray-500"></i> TV Shows</span>
147
+ <span id="db-tv-{{ loop.index0 }}" class="text-white font-bold">{{ "{:,}".format(db_stat.tv_count) }}</span>
148
  </div>
149
+
150
+ <div class="py-4 px-5 bg-black/20 rounded-xl border border-white/5">
151
+ <div class="flex justify-between items-center mb-3">
152
+ <span class="font-medium text-gray-400">Storage Used</span>
153
+ <span id="db-storage-{{ loop.index0 }}" class="text-blue-400 font-bold text-sm">{{ "%.1f"|format(db_stat.storageSize / 1024 / 1024) }} MB</span>
154
+ </div>
155
+ {% set storage_percent = (db_stat.storageSize / (500 * 1024 * 1024) * 100) | round %}
156
+ <div class="w-full bg-gray-800 rounded-full h-2.5 overflow-hidden border border-white/5 shadow-inner">
157
+ <div class="h-2.5 rounded-full bg-gradient-to-r from-blue-500 to-indigo-500 relative" style="width: {{ storage_percent }}%">
158
+ <div class="absolute inset-0 bg-white/20 w-full h-full animate-[shimmer_2s_infinite] -translate-x-full" style="background-image: linear-gradient(90deg, transparent, rgba(255,255,255,0.2), transparent);"></div>
159
+ </div>
160
  </div>
161
  </div>
162
  </div>
163
  </div>
164
+ {% endfor %}
 
165
  {% else %}
166
+ <div class="col-span-full text-center text-gray-500 py-8 glass-panel rounded-2xl">No database statistics available</div>
167
+ {% endif %}
168
  </div>
169
  </div>
170
 
171
+ <div class="mb-10">
 
 
 
172
  <div class="grid lg:grid-cols-2 gap-6">
173
+ <a href="/media/manage?media_type=movie" class="block glass-panel rounded-2xl p-8 hover:bg-white/5 border border-white/5 hover:border-white/20 transition-all group overflow-hidden relative">
174
+ <div class="absolute -right-10 -bottom-10 opacity-5 group-hover:opacity-10 transition-opacity"><i class="fas fa-film text-9xl"></i></div>
175
+ <div class="flex items-center relative z-10">
176
+ <div class="w-16 h-16 rounded-2xl bg-gradient-to-br from-pink-500/20 to-rose-500/20 flex items-center justify-center mr-6 group-hover:scale-110 transition-transform duration-300 border border-pink-500/20 text-pink-400 shadow-lg">
177
+ <i class="fas fa-film text-2xl"></i>
 
 
 
 
 
 
178
  </div>
179
  <div>
180
+ <h3 class="text-xl font-bold text-white mb-1">Manage Movies</h3>
181
+ <p class="text-gray-400 text-sm mb-2">Edit and organize movie collections</p>
182
+ <span class="inline-block px-3 py-1 bg-white/10 rounded-lg text-xs font-bold text-pink-300 border border-white/5">{{ system_stats.movies|default(0) }} movies</span>
 
183
  </div>
184
  </div>
185
  </a>
186
 
187
+ <a href="/media/manage?media_type=tv" class="block glass-panel rounded-2xl p-8 hover:bg-white/5 border border-white/5 hover:border-white/20 transition-all group overflow-hidden relative">
188
+ <div class="absolute -right-10 -bottom-10 opacity-5 group-hover:opacity-10 transition-opacity"><i class="fas fa-tv text-9xl"></i></div>
189
+ <div class="flex items-center relative z-10">
190
+ <div class="w-16 h-16 rounded-2xl bg-gradient-to-br from-emerald-500/20 to-teal-500/20 flex items-center justify-center mr-6 group-hover:scale-110 transition-transform duration-300 border border-emerald-500/20 text-emerald-400 shadow-lg">
191
+ <i class="fas fa-tv text-2xl"></i>
 
 
 
 
 
 
192
  </div>
193
  <div>
194
+ <h3 class="text-xl font-bold text-white mb-1">Manage TV Shows</h3>
195
+ <p class="text-gray-400 text-sm mb-2">Edit and organize TV series</p>
196
+ <span class="inline-block px-3 py-1 bg-white/10 rounded-lg text-xs font-bold text-emerald-300 border border-white/5">{{ system_stats.tv_shows|default(0) }} shows</span>
 
197
  </div>
198
  </div>
199
  </a>
200
  </div>
201
  </div>
202
 
203
+ <div class="glass-panel rounded-2xl p-8 mb-8 border border-white/5 relative overflow-hidden">
204
+ <div class="flex flex-col md:flex-row justify-between items-start md:items-end mb-8 gap-4 border-b border-white/10 pb-6">
205
+ <div>
206
+ <div class="flex items-center gap-4 mb-2">
207
+ <div class="w-12 h-12 rounded-xl bg-gradient-to-br from-amber-500/20 to-orange-500/20 flex items-center justify-center border border-amber-500/20 text-amber-400">
208
+ <i class="fas fa-key text-xl"></i>
209
+ </div>
210
+ <h3 class="text-2xl font-bold text-white">Access Management</h3>
211
+ </div>
212
+ <p class="text-gray-400 ml-16">Manage API tokens for Stremio addon access</p>
 
213
  </div>
214
+
 
 
 
 
 
215
  <div id="create-btn-container">
216
+ <button onclick="toggleCreateForm()" class="bg-gradient-to-r from-blue-600 to-indigo-600 hover:from-blue-500 hover:to-indigo-500 text-white px-6 py-3 rounded-xl font-bold transition-all flex items-center shadow-lg shadow-blue-500/20 border border-blue-400/30">
217
+ <i class="fas fa-plus mr-2"></i> New Token
 
 
 
 
 
 
218
  </button>
219
  </div>
220
+ </div>
221
 
222
+ <div id="create-form-container" class="hidden mb-8 bg-black/30 p-6 rounded-2xl border border-white/10 backdrop-blur-md transition-all duration-300">
223
+ <form onsubmit="createToken(event)" class="flex flex-col md:flex-row gap-5 items-end">
224
+ <div class="flex-1 w-full">
225
+ <label class="block text-sm font-semibold text-gray-300 mb-2">Token Name</label>
226
+ <input type="text" id="token-name" placeholder="E.g., Family iPad" required
227
+ class="w-full glass-input rounded-xl px-4 py-3 text-sm placeholder-gray-500">
228
+ </div>
 
229
 
230
+ <div class="w-full md:w-36">
231
+ <label class="block text-sm font-semibold text-gray-300 mb-2">Daily Limit</label>
232
+ <div class="relative">
233
+ <input type="number" id="daily-limit" placeholder="0" step="0.1" min="0"
234
+ class="w-full glass-input rounded-xl pl-4 pr-12 py-3 text-sm">
235
+ <span class="absolute right-4 top-3 text-gray-500 text-sm font-semibold pointer-events-none">GB</span>
 
236
  </div>
237
+ </div>
238
 
239
+ <div class="w-full md:w-36">
240
+ <label class="block text-sm font-semibold text-gray-300 mb-2">Monthly Limit</label>
241
+ <div class="relative">
242
+ <input type="number" id="monthly-limit" placeholder="0" step="0.1" min="0"
243
+ class="w-full glass-input rounded-xl pl-4 pr-12 py-3 text-sm">
244
+ <span class="absolute right-4 top-3 text-gray-500 text-sm font-semibold pointer-events-none">GB</span>
 
245
  </div>
246
+ </div>
247
 
248
+ <div class="flex gap-3 w-full md:w-auto">
249
+ <button type="button" onclick="toggleCreateForm()" class="flex-1 md:flex-none bg-white/5 text-gray-300 border border-white/10 px-6 py-3 rounded-xl font-semibold hover:bg-white/10 transition-colors">
250
+ Cancel
251
+ </button>
252
+ <button type="submit" class="flex-1 md:flex-none bg-gradient-to-r from-blue-600 to-indigo-600 hover:from-blue-500 hover:to-indigo-500 text-white px-8 py-3 rounded-xl font-bold transition-all shadow-lg border border-blue-400/30">
253
+ Create
254
+ </button>
255
+ </div>
256
+ </form>
 
 
 
257
  </div>
258
 
259
+ <div class="overflow-x-auto custom-scrollbar rounded-xl border border-white/5">
260
+ <table class="w-full text-left border-collapse whitespace-nowrap">
 
261
  <thead>
262
+ <tr class="bg-black/40 border-b border-white/10 text-sm uppercase tracking-wider text-gray-400 font-semibold">
263
+ <th class="py-4 px-5">Name</th>
264
+ <th class="py-4 px-5">Usage (Today / Month)</th>
265
+ <th class="py-4 px-5">Limits (GB)</th>
266
+ <th class="py-4 px-5">Manifest URL</th>
267
+ <th class="py-4 px-5 text-right">Actions</th>
268
  </tr>
269
  </thead>
270
+ <tbody class="divide-y divide-white/5">
271
  {% for token in api_tokens %}
272
+ <tr class="hover:bg-white/5 transition-colors group">
273
+ <td class="py-4 px-5">
274
+ <div class="font-bold text-gray-100">{{ token.name }}</div>
275
+ <div class="text-xs text-gray-500 mt-1"><i class="far fa-calendar-alt mr-1"></i> {{ token.created_at.strftime('%Y-%m-%d') }}</div>
 
276
  </td>
277
+ <td class="py-4 px-5 text-sm">
278
+ <div class="mb-1">Today: <span class="font-bold text-blue-400" data-bytes="{{ token.usage.daily.bytes|default(0) }}"></span></div>
279
+ <div class="text-gray-500">Month: <span class="font-medium text-gray-400" data-bytes="{{ token.usage.monthly.bytes|default(0) }}"></span></div>
 
 
280
  </td>
281
+ <td class="py-4 px-5 text-sm">
282
+ <div class="flex items-center gap-2 mb-1">
283
+ <span class="text-xs bg-white/10 px-1.5 py-0.5 rounded text-gray-400 border border-white/5">D</span>
284
+ {% if token.limits.daily_limit_gb %}<span class="font-mono text-gray-300" data-bytes="{{ (token.limits.daily_limit_gb * 1024 * 1024 * 1024)|int }}"></span>{% else %}<span class="text-gray-500">∞</span >{% endif %}
285
+ </div>
286
+ <div class="flex items-center gap-2">
287
+ <span class="text-xs bg-white/10 px-1.5 py-0.5 rounded text-gray-400 border border-white/5">M</span>
288
+ {% if token.limits.monthly_limit_gb %}<span class="font-mono text-gray-300" data-bytes="{{ (token.limits.monthly_limit_gb * 1024 * 1024 * 1024)|int }}"></span>{% else %}<span class="text-gray-500">∞</span >{% endif %}
 
 
 
 
 
 
 
 
 
 
 
 
289
  </div>
290
  </td>
291
+ <td class="py-4 px-5">
292
+ <div class="flex flex-col items-start gap-2">
293
+ <code class="text-xs bg-black/40 text-gray-300 px-3 py-1.5 rounded-lg border border-white/10 font-mono tracking-tight">
294
+ API={{ token.token[:3] }}<span class="text-gray-600">••••••••</span>{{ token.token[-3:] }}
 
295
  </code>
296
+ <button onclick="copyUrl('{{ (request.base_url|string).replace('http:', 'https:') }}stremio/{{ token.token }}/manifest.json')"
297
+ class="text-purple-400 hover:text-purple-300 flex items-center gap-1.5 text-xs font-bold uppercase tracking-wider transition-colors">
298
+ <i class="far fa-copy"></i> Copy Link
 
 
 
 
 
 
 
299
  </button>
300
  </div>
301
  </td>
302
+ <td class="py-4 px-5 text-right">
303
+ <div class="flex justify-end gap-2 opacity-100 lg:opacity-0 lg:group-hover:opacity-100 transition-opacity">
304
+ <button onclick="openEditModal('{{ token.token }}', '{{ token.limits.daily_limit_gb|default(0) }}', '{{ token.limits.monthly_limit_gb|default(0) }}')"
305
+ class="bg-blue-500/10 text-blue-400 hover:bg-blue-500/20 border border-blue-500/20 p-2 rounded-lg transition-colors" title="Edit">
306
+ <i class="fas fa-edit"></i>
307
+ </button>
308
+ <button onclick="revokeToken('{{ token.token }}')"
309
+ class="bg-red-500/10 text-red-400 hover:bg-red-500/20 border border-red-500/20 p-2 rounded-lg transition-colors" title="Revoke">
310
+ <i class="fas fa-trash-alt"></i>
311
+ </button>
312
+ </div>
313
  </td>
314
  </tr>
315
  {% else %}
316
  <tr>
317
+ <td colspan="5" class="py-12 text-center text-gray-500 font-medium">
318
+ <div class="flex flex-col items-center">
319
+ <i class="fas fa-key text-3xl mb-3 opacity-20"></i>
320
+ No tokens found. Create one to get started.
321
+ </div>
322
+ </td>
323
  </tr>
324
  {% endfor %}
325
  </tbody>
 
327
  </div>
328
  </div>
329
 
330
+ <div id="edit-modal" class="fixed inset-0 bg-black/60 backdrop-blur-sm hidden flex items-center justify-center z-[100] p-4">
331
+ <div class="glass-panel bg-[#0f172a]/95 rounded-2xl p-8 w-full max-w-md shadow-2xl border border-white/10 transform transition-all relative overflow-hidden">
332
+ <div class="absolute top-0 left-0 w-full h-1 bg-gradient-to-r from-blue-500 to-purple-500"></div>
333
+ <h3 class="text-xl font-bold mb-6 text-white flex items-center gap-2"><i class="fas fa-sliders-h text-purple-400"></i> Edit Token Limits</h3>
334
  <input type="hidden" id="edit-token-id">
335
 
336
+ <div class="space-y-5">
337
  <div>
338
+ <label class="block text-sm font-semibold text-gray-300 mb-2">Daily Limit (GB)</label>
339
  <input type="number" id="edit-daily" placeholder="0 for unlimited" step="0.1" min="0"
340
+ class="w-full glass-input rounded-xl px-4 py-3 text-sm">
341
  </div>
342
  <div>
343
+ <label class="block text-sm font-semibold text-gray-300 mb-2">Monthly Limit (GB)</label>
344
  <input type="number" id="edit-monthly" placeholder="0 for unlimited" step="0.1" min="0"
345
+ class="w-full glass-input rounded-xl px-4 py-3 text-sm">
346
  </div>
347
  </div>
348
 
349
+ <div class="mt-8 flex justify-end gap-3">
350
+ <button onclick="closeEditModal()" class="px-5 py-2.5 bg-white/5 text-gray-300 hover:bg-white/10 border border-white/10 rounded-xl transition-colors font-semibold">Cancel</button>
351
+ <button onclick="saveTokenLimits()" class="px-5 py-2.5 bg-gradient-to-r from-blue-600 to-indigo-600 hover:from-blue-500 hover:to-indigo-500 text-white rounded-xl transition-all font-bold shadow-lg shadow-blue-500/20 border border-blue-400/30">Save Changes</button>
 
 
 
352
  </div>
353
  </div>
354
  </div>
 
 
355
  </main>
356
  </div>
357
 
 
358
  <script>
359
+ // ... [Original form toggle and modal JS remains unchanged] ...
360
  function toggleCreateForm() {
361
  const formContainer = document.getElementById('create-form-container');
362
  const btnContainer = document.getElementById('create-btn-container');
 
363
  if (formContainer.classList.contains('hidden')) {
364
  formContainer.classList.remove('hidden');
365
  btnContainer.classList.add('hidden');
 
370
  }
371
 
372
  let currentEditToken = null;
 
373
  function openEditModal(token, daily, monthly) {
374
  currentEditToken = token;
375
  document.getElementById('edit-token-id').value = token;
376
  document.getElementById('edit-daily').value = daily == 'None' ? 0 : daily;
377
  document.getElementById('edit-monthly').value = monthly == 'None' ? 0 : monthly;
 
378
  document.getElementById('edit-modal').classList.remove('hidden');
379
  }
380
 
 
385
 
386
  async function saveTokenLimits() {
387
  if (!currentEditToken) return;
 
388
  const daily = document.getElementById('edit-daily').value;
389
  const monthly = document.getElementById('edit-monthly').value;
 
390
  try {
391
  const response = await fetch('/api/tokens/' + currentEditToken, {
392
  method: 'PUT',
393
  headers: { 'Content-Type': 'application/json' },
394
+ body: JSON.stringify({ daily_limit_gb: daily, monthly_limit_gb: monthly })
 
 
 
395
  });
 
396
  if (response.ok) {
397
  closeEditModal();
 
398
  window.location.reload();
399
  } else {
400
  alert("Failed to update limits");
 
406
  }
407
  </script>
408
 
 
409
  <script>
410
+ // System Stats Auto-Refresh
411
  async function refreshSystemStats() {
412
  const icon = document.getElementById('refresh-icon');
413
+ if (icon) icon.classList.add('animate-spin');
414
 
415
  try {
416
  const response = await fetch('/api/system/stats');
417
  if (response.ok) {
418
  const stats = await response.json();
419
+
420
+ // Static Updates
421
  const elUptime = document.getElementById('sys-uptime');
422
  if (elUptime) elUptime.innerText = stats.uptime;
 
423
  const elBotName = document.getElementById('sys-bot-name');
424
  if (elBotName) elBotName.innerText = stats.telegram_bot;
 
425
  const elBotCount = document.getElementById('sys-bots-count');
426
  if (elBotCount) elBotCount.innerText = stats.connected_bots;
 
427
  const elVersion = document.getElementById('sys-version');
428
  if (elVersion) elVersion.innerText = 'v' + stats.version;
429
 
430
+ // DB Updates
431
  if (stats.databases && Array.isArray(stats.databases)) {
432
  stats.databases.forEach((db, index) => {
433
  const elMovies = document.getElementById(`db-movies-${index}`);
434
  if (elMovies) elMovies.innerText = db.movie_count.toLocaleString();
 
435
  const elTv = document.getElementById(`db-tv-${index}`);
436
  if (elTv) elTv.innerText = db.tv_count.toLocaleString();
 
437
  const elStorage = document.getElementById(`db-storage-${index}`);
438
  if (elStorage) {
439
  const mb = db.storageSize / (1024 * 1024);
 
442
  });
443
  }
444
 
445
+ // API Token Usage Data Update
446
  if (stats.api_tokens && Array.isArray(stats.api_tokens)) {
447
  stats.api_tokens.forEach((token, index) => {
 
448
  const tokenRows = document.querySelectorAll('tbody tr');
 
 
449
  if (tokenRows.length > index && !tokenRows[index].querySelector('[colspan]')) {
450
  const row = tokenRows[index];
451
+ const dailyUsageSpan = row.querySelector('td:nth-child(2) div.mb-1 span.font-bold');
 
 
452
  if (dailyUsageSpan && token.usage && token.usage.daily) {
453
  const dailyBytes = token.usage.daily.bytes || 0;
454
  dailyUsageSpan.setAttribute('data-bytes', dailyBytes);
455
  dailyUsageSpan.textContent = formatBytes(dailyBytes);
456
  }
457
+ const monthlyUsageSpan = row.querySelector('td:nth-child(2) div.text-gray-500 span');
 
 
458
  if (monthlyUsageSpan && token.usage && token.usage.monthly) {
459
  const monthlyBytes = token.usage.monthly.bytes || 0;
460
  monthlyUsageSpan.setAttribute('data-bytes', monthlyBytes);
 
464
  });
465
  }
466
 
467
+ if (typeof updateBotWorkloads === "function") await updateBotWorkloads();
 
 
 
468
  await updateActiveStreams();
469
  }
470
  } catch (error) {
471
  console.error("Failed to refresh system stats:", error);
472
  } finally {
473
+ setTimeout(() => { if (icon) icon.classList.remove('animate-spin'); }, 500);
 
 
 
474
  }
475
  }
476
 
 
481
  const data = await response.json();
482
  const allStreams = data.active_streams || [];
483
  const container = document.getElementById('active-streams-container');
484
+ const liveStreams = allStreams.filter(s => s.status === 'active' && (s.total_bytes || 0) > 0);
 
 
 
 
 
 
 
485
 
486
  if (liveStreams.length === 0) {
487
+ container.innerHTML = `<div class="flex flex-col items-center justify-center py-12 px-4 h-full border border-dashed border-white/10 rounded-xl bg-white/5">
488
+ <div class="w-16 h-16 rounded-full bg-white/5 flex items-center justify-center mb-4 border border-white/5">
489
+ <i class="fas fa-video-slash text-2xl text-gray-500"></i>
490
+ </div>
491
+ <p class="text-gray-300 font-semibold mb-1">No active streams</p>
492
+ <p class="text-gray-500 text-sm text-center">Streams will appear here when users start watching content</p>
493
+ </div>`;
494
  } else {
495
  const escapeHtml = (unsafe) => {
496
  if (!unsafe) return '';
497
+ return unsafe.toString().replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&#039;");
 
 
 
 
 
 
498
  };
 
499
  const formatBytesStr = (bytes) => {
500
  if (bytes === 0) return '0 B';
501
  const k = 1024;
 
504
  return parseFloat((bytes / Math.pow(k, i)).toFixed(2)) + ' ' + sizes[i];
505
  };
506
 
507
+ // Rebuilt HTML string to match Glassmorphism theme
508
  container.innerHTML = liveStreams.map(stream => {
509
+ let statusColor = 'bg-red-500/20 text-red-400 border border-red-500/30 border-l-red-500';
510
+ if (stream.status === 'active') { statusColor = 'bg-green-500/20 text-green-400 border border-green-500/30 border-l-green-500'; }
511
+ else if (stream.status === 'cancelled') { statusColor = 'bg-yellow-500/20 text-yellow-400 border border-yellow-500/30 border-l-yellow-500'; }
 
 
 
 
 
512
 
513
  const streamIdStr = stream.stream_id ? stream.stream_id.substring(0, 8) + '...' : 'Unknown';
514
  const titleStr = (stream.meta && stream.meta.title) ? stream.meta.title : (stream.title || 'Unknown Stream');
515
 
516
  return `
517
+ <div class="p-5 bg-black/20 rounded-xl border-l-4 border-t border-r border-b border-white/5 shadow-md ${statusColor.split(' ')[4]}">
518
+ <div class="flex justify-between items-start mb-4">
519
+ <div class="flex items-center gap-3 max-w-[70%]">
520
+ <i class="fas fa-play-circle text-purple-400 text-lg"></i>
 
 
521
  <div class="truncate">
522
+ <span class="font-bold text-gray-100" title="${escapeHtml(stream.title || stream.stream_id)}">${escapeHtml(titleStr)}</span>
523
+ <div class="text-xs text-gray-500 font-mono mt-1" title="${escapeHtml(stream.stream_id)}">ID: ${escapeHtml(streamIdStr)}</div>
 
 
524
  </div>
525
  </div>
526
+ <span class="px-2.5 py-1 rounded-md text-[11px] font-bold tracking-wider uppercase ${statusColor.split(' ').slice(0,3).join(' ')}">
527
  ${escapeHtml(stream.status)}
528
  </span>
529
  </div>
530
+ <div class="grid grid-cols-2 gap-2 mb-3">
531
+ <div class="flex justify-between py-2 px-3 bg-white/5 rounded-lg border border-white/5"><span class="text-xs text-gray-400">Bot:</span><span class="text-xs text-white font-semibold">Bot${(stream.client_index || 0) + 1}</span></div>
532
+ <div class="flex justify-between py-2 px-3 bg-white/5 rounded-lg border border-white/5"><span class="text-xs text-gray-400">File:</span><span class="text-xs text-white font-semibold">DC${stream.dc_id || '-'}</span></div>
533
+ <div class="flex justify-between py-2 px-3 bg-white/5 rounded-lg border border-white/5 col-span-2"><span class="text-xs text-gray-400">Duration:</span><span class="text-xs text-white font-semibold">${stream.duration || 0}s</span></div>
534
+ <div class="flex justify-between py-2 px-3 bg-white/5 rounded-lg border border-white/5 col-span-2"><span class="text-xs text-gray-400">Transferred:</span><span class="text-xs text-white font-semibold">${formatBytesStr(stream.total_bytes)}</span></div>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
535
  </div>
536
+ <div class="grid grid-cols-3 gap-2">
537
+ <div class="text-center py-2 bg-white/5 rounded-lg border border-white/5"><div class="text-[10px] text-gray-500 uppercase tracking-wider mb-1">Instant</div><div class="text-sm font-bold text-blue-400">${stream.instant_mbps || 0} <span class="text-[10px] text-gray-500">MB/s</span></div></div>
538
+ <div class="text-center py-2 bg-white/5 rounded-lg border border-white/5"><div class="text-[10px] text-gray-500 uppercase tracking-wider mb-1">Average</div><div class="text-sm font-bold text-purple-400">${stream.avg_mbps || 0} <span class="text-[10px] text-gray-500">MB/s</span></div></div>
539
+ <div class="text-center py-2 bg-white/5 rounded-lg border border-white/5"><div class="text-[10px] text-gray-500 uppercase tracking-wider mb-1">Peak</div><div class="text-sm font-bold text-pink-400">${stream.peak_mbps || 0} <span class="text-[10px] text-gray-500">MB/s</span></div></div>
540
  </div>
 
541
  ${stream.meta && (stream.meta.client_host || stream.meta.user_name) ? `
542
+ <div class="mt-3 pt-3 border-t border-white/10 text-xs">
543
+ ${stream.meta.client_host ? `<div class="flex justify-between mb-1"><span class="text-gray-500"><i class="fas fa-network-wired mr-1"></i> IPv4:</span><span class="font-mono text-gray-300">${escapeHtml(stream.meta.client_host)}</span></div>` : ''}
544
+ ${stream.meta.user_name ? `<div class="flex justify-between"><span class="text-gray-500"><i class="fas fa-user mr-1"></i> User:</span><span class="font-semibold text-gray-300">${escapeHtml(stream.meta.user_name)}</span></div>` : ''}
545
+ </div>` : ''}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
546
  </div>
547
+ `;
548
  }).join('');
549
  }
550
  }
 
551
  } catch (error) {
552
+ console.error("Failed to update active streams:", error);
553
+ }
554
  }
555
 
 
556
  const statsInterval = setInterval(refreshSystemStats, 120000);
557
+
558
+ // API Creation functions
559
  async function createToken(event) {
560
  event.preventDefault();
 
 
 
 
561
  const payload = {
562
+ name: document.getElementById('token-name').value,
563
+ daily_limit_gb: document.getElementById('daily-limit').value,
564
+ monthly_limit_gb: document.getElementById('monthly-limit').value
565
  };
 
566
  try {
567
  const response = await fetch('/api/tokens', {
568
  method: 'POST',
569
  headers: { 'Content-Type': 'application/json' },
570
  body: JSON.stringify(payload)
571
  });
 
572
  if (response.ok) {
573
+ showToast('Token created successfully!', 'success');
574
  setTimeout(() => window.location.reload(), 1000);
575
  } else {
576
  const data = await response.json();
577
+ showToast('Error: ' + data.detail, 'error');
578
  }
579
  } catch (error) {
580
+ showToast('Error creating token', 'error');
581
  }
582
  }
583
 
584
  async function revokeToken(token) {
585
  if (!confirm('Are you sure you want to revoke this token? The user will lose access immediately.')) return;
 
586
  try {
587
+ const response = await fetch('/api/tokens/' + token, { method: 'DELETE' });
 
 
 
588
  if (response.ok) {
589
+ showToast('Token revoked successfully!', 'success');
590
  setTimeout(() => window.location.reload(), 1000);
591
  } else {
592
+ showToast('Error revoking token', 'error');
593
  }
594
  } catch (error) {
595
+ showToast('Error revoking token', 'error');
596
  }
597
  }
598
 
599
  function copyUrl(url) {
600
  navigator.clipboard.writeText(url).then(function () {
601
+ showToast('Manifest URL copied!', 'success');
 
 
 
 
 
 
 
 
 
 
 
602
  });
603
  }
604
 
605
+ function showToast(message, type = 'success', duration = 3000) {
606
  const toast = document.createElement('div');
607
+ const bg = type === 'success' ? 'bg-emerald-500/90' : 'bg-red-500/90';
608
+ toast.className = `fixed bottom-4 right-4 ${bg} backdrop-blur-md text-white px-6 py-3 rounded-xl shadow-2xl z-[200] transform transition-all duration-300 translate-y-full opacity-0 border border-white/20 font-medium flex items-center gap-2`;
609
+ toast.innerHTML = `<i class="fas ${type === 'success' ? 'fa-check-circle' : 'fa-exclamation-circle'}"></i> ${message}`;
610
  document.body.appendChild(toast);
611
+
612
+ setTimeout(() => { toast.classList.remove('translate-y-full', 'opacity-0'); }, 10);
613
  setTimeout(() => {
614
+ toast.classList.add('translate-y-full', 'opacity-0');
615
  setTimeout(() => document.body.removeChild(toast), 300);
616
  }, duration);
617
  }
618
 
 
 
 
 
 
 
 
 
 
 
 
 
 
619
  function formatBytes(bytes, decimals = 2) {
620
  if (!+bytes) return '0 B';
621
  const k = 1024;
 
625
  return `${parseFloat((bytes / Math.pow(k, i)).toFixed(dm))} ${sizes[i]}`;
626
  }
627
 
 
628
  document.addEventListener("DOMContentLoaded", () => {
629
  document.querySelectorAll('[data-bytes]').forEach(el => {
630
  el.textContent = formatBytes(el.getAttribute('data-bytes'));
631
  });
 
 
632
  {% if api_tokens %}
633
  const firstToken = '{{ api_tokens[0].token }}';
634
+ if (firstToken) localStorage.setItem('api_token', firstToken);
 
 
635
  {% endif %}
636
  });
637
  </script>