Spaces:
Runtime error
Runtime error
Update bot/handlers.py
Browse files- bot/handlers.py +34 -3
bot/handlers.py
CHANGED
|
@@ -490,16 +490,47 @@ async def _run_upload(uid: int) -> None:
|
|
| 490 |
last_ui = 0.0
|
| 491 |
start_t = time.time()
|
| 492 |
|
| 493 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 494 |
nonlocal last_ui
|
| 495 |
now = time.time()
|
| 496 |
if now - last_ui < 0.8:
|
| 497 |
return
|
| 498 |
last_ui = now
|
| 499 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 500 |
txt = (
|
| 501 |
"⬆️ Uploading…\n\n"
|
| 502 |
-
f"{human_bytes(
|
| 503 |
f"Speed: {human_bytes(rate)}/s\n"
|
| 504 |
f"ETA: {human_eta(speed.eta_seconds)}"
|
| 505 |
)
|
|
|
|
| 490 |
last_ui = 0.0
|
| 491 |
start_t = time.time()
|
| 492 |
|
| 493 |
+
# ✅ Fix: uploader sometimes passes dict/str instead of int → prevent float(dict) crash
|
| 494 |
+
def _as_int(v: Any) -> int:
|
| 495 |
+
if v is None:
|
| 496 |
+
return 0
|
| 497 |
+
if isinstance(v, bool):
|
| 498 |
+
return int(v)
|
| 499 |
+
if isinstance(v, (int, float)):
|
| 500 |
+
return int(v)
|
| 501 |
+
if isinstance(v, str):
|
| 502 |
+
try:
|
| 503 |
+
return int(float(v.strip()))
|
| 504 |
+
except Exception:
|
| 505 |
+
return 0
|
| 506 |
+
if isinstance(v, dict):
|
| 507 |
+
for k in ("sent", "uploaded", "current", "bytes_sent", "bytes", "done", "value", "progress"):
|
| 508 |
+
if k in v:
|
| 509 |
+
return _as_int(v.get(k))
|
| 510 |
+
if len(v) == 1:
|
| 511 |
+
try:
|
| 512 |
+
return _as_int(next(iter(v.values())))
|
| 513 |
+
except Exception:
|
| 514 |
+
return 0
|
| 515 |
+
return 0
|
| 516 |
+
return 0
|
| 517 |
+
|
| 518 |
+
async def progress_cb(sent: Any, total: Any) -> None:
|
| 519 |
nonlocal last_ui
|
| 520 |
now = time.time()
|
| 521 |
if now - last_ui < 0.8:
|
| 522 |
return
|
| 523 |
last_ui = now
|
| 524 |
+
|
| 525 |
+
sent_i = _as_int(sent)
|
| 526 |
+
total_i = _as_int(total)
|
| 527 |
+
if total_i <= 0:
|
| 528 |
+
total_i = max(sent_i, 1)
|
| 529 |
+
|
| 530 |
+
rate = speed.update(sent_i, total_i)
|
| 531 |
txt = (
|
| 532 |
"⬆️ Uploading…\n\n"
|
| 533 |
+
f"{human_bytes(sent_i)} / {human_bytes(total_i)}\n"
|
| 534 |
f"Speed: {human_bytes(rate)}/s\n"
|
| 535 |
f"ETA: {human_eta(speed.eta_seconds)}"
|
| 536 |
)
|