MyanmarSwe commited on
Commit
abed419
·
verified ·
1 Parent(s): 3699aa4

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +12 -5
main.py CHANGED
@@ -33,7 +33,7 @@ async def lifespan(app: FastAPI):
33
 
34
  app = FastAPI(lifespan=lifespan)
35
 
36
- # --- Cron-job.org အတွက် Health Check Endpoint ---
37
  @app.get("/")
38
  async def health_check():
39
  return JSONResponse(content={"status": "running", "message": "Server is alive!"})
@@ -60,10 +60,16 @@ async def stream_telegram(request: Request, url: str, key: str = None):
60
 
61
  try:
62
  msg = await client.get_messages(chat_id, msg_id)
 
63
  media = msg.video or msg.document or msg.audio or msg.animation
64
- if not media: raise Exception()
65
- except:
66
- raise HTTPException(status_code=404, detail="File not found")
 
 
 
 
 
67
 
68
  file_size = media.file_size
69
  range_header = request.headers.get("range")
@@ -75,6 +81,7 @@ async def stream_telegram(request: Request, url: str, key: str = None):
75
  start_byte = int(match.group(1))
76
 
77
  async def refined_generator():
 
78
  offset_in_mb = start_byte // (1024 * 1024)
79
  skip_bytes = start_byte % (1024 * 1024)
80
 
@@ -89,7 +96,7 @@ async def stream_telegram(request: Request, url: str, key: str = None):
89
  else:
90
  yield chunk
91
  except Exception as e:
92
- print(f"Stream interrupted: {e}")
93
  return
94
 
95
  headers = {
 
33
 
34
  app = FastAPI(lifespan=lifespan)
35
 
36
+ # --- Health Check Endpoint ---
37
  @app.get("/")
38
  async def health_check():
39
  return JSONResponse(content={"status": "running", "message": "Server is alive!"})
 
60
 
61
  try:
62
  msg = await client.get_messages(chat_id, msg_id)
63
+ # Media ရှိမရှိ စစ်ဆေးခြင်း
64
  media = msg.video or msg.document or msg.audio or msg.animation
65
+
66
+ if not media:
67
+ print(f" Media Not Found in Message: {msg_id}")
68
+ raise Exception("No media found")
69
+
70
+ except Exception as e:
71
+ print(f"❌ Error fetching message {msg_id}: {str(e)}")
72
+ raise HTTPException(status_code=404, detail=f"File not found or Access Denied: {str(e)}")
73
 
74
  file_size = media.file_size
75
  range_header = request.headers.get("range")
 
81
  start_byte = int(match.group(1))
82
 
83
  async def refined_generator():
84
+ # Telegram ရဲ့ offset က MB နဲ့ သွားတာမို့လို့ပါ
85
  offset_in_mb = start_byte // (1024 * 1024)
86
  skip_bytes = start_byte % (1024 * 1024)
87
 
 
96
  else:
97
  yield chunk
98
  except Exception as e:
99
+ print(f"⚠️ Stream interrupted for {msg_id}: {e}")
100
  return
101
 
102
  headers = {