Skip to content

Commit

Permalink
fix: typo and pass correct headers to aira2
Browse files Browse the repository at this point in the history
  • Loading branch information
Anonymous committed Jun 14, 2024
1 parent f744284 commit 1bc250d
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ data/*
caddy/caddy_data
.idea
.env
node_modules
node_modules
**/__pycache__
11 changes: 7 additions & 4 deletions src/mirrorsrun/aria2_api.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import json
import logging
import uuid
from typing import Optional

import httpx

Expand Down Expand Up @@ -33,18 +34,20 @@ async def send_request(method, params=None):
raise e


async def add_download(url, save_dir="/app/cache", out_file=None):
logger.info(f"[Aria2] add_download {url=} {save_dir=} {out_file=}")
async def add_download(
url, save_dir="/app/cache", out_file=None, headers: Optional[dict] = None
):
logger.info(f"[Aria2] add_download {url=} {save_dir=} {out_file=} {headers=}")

method = "aria2.addUri"
options = {
"dir": save_dir,
"header": [],
"out": out_file,
}

if out_file:
options["out"] = out_file
if headers:
options["header"] = [f"{k}: {v}" for k, v in headers.items()]

params = [[url], options]
response = await send_request(method, params)
Expand Down
5 changes: 5 additions & 0 deletions src/mirrorsrun/proxy/file_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,11 @@ async def try_file_based_cache(
processed_url,
save_dir=cache_file_dir,
out_file=os.path.basename(cache_file),
headers={
key: value
for key, value in request.headers.items()
if key in ["user-agent", "accept", "authorization"]
},
)
except Exception as e:
logger.error(f"Download error, return 500 for {target_url}", exc_info=e)
Expand Down

0 comments on commit 1bc250d

Please sign in to comment.