Spaces:
Running
Running
Update main.py
Browse files
main.py
CHANGED
|
@@ -135,7 +135,8 @@ async def stream_file(target_url, range_header):
|
|
| 135 |
raise HTTPException(status_code=500, detail=str(e))
|
| 136 |
|
| 137 |
async def process_response(r):
|
| 138 |
-
|
|
|
|
| 139 |
response_headers = {n: v for n, v in r.headers.items() if n.lower() not in excluded}
|
| 140 |
|
| 141 |
# Video Seeking အတွက် မရှိမဖြစ်လိုအပ်သော Headers များ
|
|
@@ -145,11 +146,15 @@ async def process_response(r):
|
|
| 145 |
if 'Content-Range' in r.headers:
|
| 146 |
response_headers['Content-Range'] = r.headers['Content-Range']
|
| 147 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 148 |
return StreamingResponse(
|
| 149 |
r.aiter_bytes(chunk_size=131072), # 128KB chunks for perfect buffering
|
| 150 |
status_code=r.status_code,
|
| 151 |
headers=response_headers,
|
| 152 |
-
media_type=
|
| 153 |
)
|
| 154 |
|
| 155 |
if __name__ == "__main__":
|
|
|
|
| 135 |
raise HTTPException(status_code=500, detail=str(e))
|
| 136 |
|
| 137 |
async def process_response(r):
|
| 138 |
+
# မူလလာတဲ့ content-disposition ကို ဖယ်ထုတ်ဖို့ excluded ထဲ ထည့်လိုက်ပါမယ်
|
| 139 |
+
excluded = ['content-encoding', 'content-length', 'transfer-encoding', 'connection', 'content-disposition']
|
| 140 |
response_headers = {n: v for n, v in r.headers.items() if n.lower() not in excluded}
|
| 141 |
|
| 142 |
# Video Seeking အတွက် မရှိမဖြစ်လိုအပ်သော Headers များ
|
|
|
|
| 146 |
if 'Content-Range' in r.headers:
|
| 147 |
response_headers['Content-Range'] = r.headers['Content-Range']
|
| 148 |
|
| 149 |
+
# --- Direct Download ဖြစ်စေရန် ပြင်ဆင်ချက် ---
|
| 150 |
+
# content-disposition ကို attachment လို့ သတ်မှတ်ပေးလိုက်ရင် browser က တန်း download လုပ်ပါလိမ့်မယ်
|
| 151 |
+
response_headers['Content-Disposition'] = 'attachment'
|
| 152 |
+
|
| 153 |
return StreamingResponse(
|
| 154 |
r.aiter_bytes(chunk_size=131072), # 128KB chunks for perfect buffering
|
| 155 |
status_code=r.status_code,
|
| 156 |
headers=response_headers,
|
| 157 |
+
media_type='application/octet-stream' # stream အနေနဲ့ တန်းဆွဲဖို့ application/octet-stream ပြောင်းလိုက်ပါတယ်
|
| 158 |
)
|
| 159 |
|
| 160 |
if __name__ == "__main__":
|