fix:修复接口调用问题
This commit is contained in:
@@ -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(),
|
||||
)
|
||||
|
||||
@@ -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",
|
||||
|
||||
Reference in New Issue
Block a user