Refine seller store implementation
This commit is contained in:
+10
-1
@@ -8,7 +8,12 @@ from urllib.parse import urlparse
|
||||
|
||||
from fastapi import APIRouter, HTTPException, Query, Response
|
||||
|
||||
from services.storage import ResourceSizeLimitError, download_bytes
|
||||
from services.storage import (
|
||||
ResourceDownloadTimeoutError,
|
||||
ResourceSizeLimitError,
|
||||
UnsafeRemoteUrlError,
|
||||
download_bytes,
|
||||
)
|
||||
|
||||
router = APIRouter(prefix="/api", tags=["proxy"])
|
||||
|
||||
@@ -40,8 +45,12 @@ async def proxy_image(url: str = Query(..., description="源站图片 URL")):
|
||||
raise HTTPException(status_code=400, detail="仅支持 http/https URL")
|
||||
try:
|
||||
data, ctype = await download_bytes(url, referer=guess_referer(url))
|
||||
except UnsafeRemoteUrlError as exc:
|
||||
raise HTTPException(status_code=400, detail=f"图片地址不允许代理:{exc}") from exc
|
||||
except ResourceSizeLimitError as exc:
|
||||
raise HTTPException(status_code=413, detail=f"图片文件过大,无法代理:{exc}") from exc
|
||||
except ResourceDownloadTimeoutError as exc:
|
||||
raise HTTPException(status_code=504, detail=str(exc)) from exc
|
||||
except Exception as exc: # noqa: BLE001
|
||||
raise HTTPException(status_code=502, detail=f"图片拉取失败: {exc}") from exc
|
||||
if not ctype.startswith("image/"):
|
||||
|
||||
Reference in New Issue
Block a user