fix:修复接口调用问题

This commit is contained in:
ZhangYonghao
2026-03-21 21:27:20 +08:00
parent eaefc318a6
commit 3b660203dd
5 changed files with 37 additions and 10 deletions

View File

@@ -7,4 +7,4 @@ DEFAULT_RETENTION_DAYS=7
MAX_RETENTION_DAYS=30
MAX_HTML_LENGTH=200000
API_KEY=""
ALLOW_UNSAFE_HTML=false
ALLOW_UNSAFE_HTML=true

View File

@@ -7,4 +7,4 @@ DEFAULT_RETENTION_DAYS=7
MAX_RETENTION_DAYS=30
MAX_HTML_LENGTH=200000
API_KEY=""
ALLOW_UNSAFE_HTML=false
ALLOW_UNSAFE_HTML=true

View File

@@ -49,6 +49,18 @@ CONTENT_SECURITY_POLICY = "; ".join(
)
def build_response_headers() -> dict[str, str]:
headers = {
"X-Content-Type-Options": "nosniff",
"Referrer-Policy": "no-referrer",
"Cache-Control": "public, max-age=300",
}
if not settings.allow_unsafe_html:
headers["Content-Security-Policy"] = CONTENT_SECURITY_POLICY
return headers
def require_api_key(x_api_key: str | None = Header(default=None, alias="X-API-Key")) -> None:
if not settings.api_key:
return
@@ -316,10 +328,5 @@ def get_html_content(unique_id: str, db: Session = Depends(get_db)) -> FileRespo
return FileResponse(
path=file_path,
media_type="text/html",
headers={
"Content-Security-Policy": CONTENT_SECURITY_POLICY,
"X-Content-Type-Options": "nosniff",
"Referrer-Policy": "no-referrer",
"Cache-Control": "public, max-age=300",
},
headers=build_response_headers(),
)

View File

@@ -33,6 +33,13 @@ class HTMLGenerateRequest(BaseModel):
@root_validator(pre=True)
def normalize_aliases(cls, values: dict) -> dict:
if isinstance(values.get("body"), dict):
merged_values = dict(values["body"])
for key, value in values.items():
if key != "body" and key not in merged_values:
merged_values[key] = value
values = merged_values
alias_map = {
"html": "html_content",
"content": "html_content",