mirror of
https://github.com/NoCLin/LightMirrors
synced 2025-06-16 17:09:56 +08:00
fix: typo and pass correct headers to aira2
This commit is contained in:
parent
f744284c82
commit
1bc250d33c
3
.gitignore
vendored
3
.gitignore
vendored
@ -4,4 +4,5 @@ data/*
|
||||
caddy/caddy_data
|
||||
.idea
|
||||
.env
|
||||
node_modules
|
||||
node_modules
|
||||
**/__pycache__
|
@ -1,6 +1,7 @@
|
||||
import json
|
||||
import logging
|
||||
import uuid
|
||||
from typing import Optional
|
||||
|
||||
import httpx
|
||||
|
||||
@ -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)
|
||||
|
@ -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)
|
||||
|
Loading…
x
Reference in New Issue
Block a user