mirror of
https://github.com/NoCLin/LightMirrors
synced 2025-07-24 02:21:44 +08:00
fix: typo and pass correct headers to aira2
This commit is contained in:
parent
f744284c82
commit
1bc250d33c
1
.gitignore
vendored
1
.gitignore
vendored
@ -5,3 +5,4 @@ caddy/caddy_data
|
|||||||
.idea
|
.idea
|
||||||
.env
|
.env
|
||||||
node_modules
|
node_modules
|
||||||
|
**/__pycache__
|
@ -1,6 +1,7 @@
|
|||||||
import json
|
import json
|
||||||
import logging
|
import logging
|
||||||
import uuid
|
import uuid
|
||||||
|
from typing import Optional
|
||||||
|
|
||||||
import httpx
|
import httpx
|
||||||
|
|
||||||
@ -33,18 +34,20 @@ async def send_request(method, params=None):
|
|||||||
raise e
|
raise e
|
||||||
|
|
||||||
|
|
||||||
async def add_download(url, save_dir="/app/cache", out_file=None):
|
async def add_download(
|
||||||
logger.info(f"[Aria2] add_download {url=} {save_dir=} {out_file=}")
|
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"
|
method = "aria2.addUri"
|
||||||
options = {
|
options = {
|
||||||
"dir": save_dir,
|
"dir": save_dir,
|
||||||
"header": [],
|
|
||||||
"out": out_file,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if out_file:
|
if out_file:
|
||||||
options["out"] = out_file
|
options["out"] = out_file
|
||||||
|
if headers:
|
||||||
|
options["header"] = [f"{k}: {v}" for k, v in headers.items()]
|
||||||
|
|
||||||
params = [[url], options]
|
params = [[url], options]
|
||||||
response = await send_request(method, params)
|
response = await send_request(method, params)
|
||||||
|
@ -100,6 +100,11 @@ async def try_file_based_cache(
|
|||||||
processed_url,
|
processed_url,
|
||||||
save_dir=cache_file_dir,
|
save_dir=cache_file_dir,
|
||||||
out_file=os.path.basename(cache_file),
|
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:
|
except Exception as e:
|
||||||
logger.error(f"Download error, return 500 for {target_url}", exc_info=e)
|
logger.error(f"Download error, return 500 for {target_url}", exc_info=e)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user