Skip to content

Commit

Permalink
fix image proxy
Browse files Browse the repository at this point in the history
  • Loading branch information
jxxghp committed Jan 8, 2024
1 parent b4cb9c3 commit 8aa1027
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions app/api/endpoints/system.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,17 @@
router = APIRouter()


@router.get("/img/{imgurl:path}", summary="图片代理")
def get_img(imgurl: str) -> Any:
@router.get("/img/{imgurl:path}/{proxy}", summary="图片代理")
def get_img(imgurl: str, proxy: bool = False) -> Any:
"""
通过图片代理(使用代理服务器)
"""
if not imgurl:
return None
response = RequestUtils(ua=settings.USER_AGENT, proxies=settings.PROXY).get_res(url=imgurl)
if proxy:
response = RequestUtils(ua=settings.USER_AGENT, proxies=settings.PROXY).get_res(url=imgurl)
else:
response = RequestUtils(ua=settings.USER_AGENT).get_res(url=imgurl)
if response:
return Response(content=response.content, media_type="image/jpeg")
return None
Expand Down

0 comments on commit 8aa1027

Please sign in to comment.