fix(site): 精简站点配置,移除名称/Banner/相关链接 (#15)
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
608afb88ea
commit
460cfdc78a
8 files changed
+24
-238
No files matched your search
@@ -1,5 +1,3 @@
|
||||
import json
|
||||
|
||||
from fastapi import APIRouter, Depends, File, Form, HTTPException, Query, Request, UploadFile, status
|
||||
from pydantic import BaseModel
|
||||
from sqlalchemy import func, select
|
||||
@@ -28,7 +26,7 @@ from app.services.storage import (
|
||||
|
||||
router = APIRouter(dependencies=[Depends(require_staff)])
|
||||
|
||||
_TEXT_KEYS = {"site_name", "icp_text", "police_text", "link_cirea", "link_housing"}
|
||||
_TEXT_KEYS = {"icp_text", "police_text", "link_cirea", "link_housing"}
|
||||
_LINK_KEYS = {"link_cirea", "link_housing"}
|
||||
_POSITIVE = {
|
||||
"upload_max_bytes": "上传大小上限必须是正整数",
|
||||
@@ -97,41 +95,6 @@ def _logo_id(value) -> str:
|
||||
return str(int(text))
|
||||
|
||||
|
||||
def _banner_ids(value) -> str:
|
||||
if not isinstance(value, list):
|
||||
_bad("banner_file_ids 必须是数组")
|
||||
numbers: list[int] = []
|
||||
for item in value:
|
||||
if isinstance(item, bool) or not isinstance(item, (int, str)):
|
||||
_bad("banner_file_ids 必须是附件编号")
|
||||
text = str(item).strip()
|
||||
if not text.isdigit() or int(text) <= 0:
|
||||
_bad("banner_file_ids 必须是附件编号")
|
||||
numbers.append(int(text))
|
||||
return json.dumps(numbers, separators=(",", ":"))
|
||||
|
||||
|
||||
def _friend_links(value) -> str:
|
||||
if not isinstance(value, list):
|
||||
_bad("friend_links 必须是数组")
|
||||
cleaned: list[dict[str, str]] = []
|
||||
for item in value:
|
||||
if not isinstance(item, dict):
|
||||
_bad("相关链接必须包含名称和地址")
|
||||
name = item.get("name")
|
||||
url = item.get("url")
|
||||
if not isinstance(name, str) or not isinstance(url, str):
|
||||
_bad("相关链接必须包含名称和地址")
|
||||
name = name.strip()
|
||||
url = url.strip()
|
||||
if not name or not url:
|
||||
_bad("相关链接必须包含名称和地址")
|
||||
if is_javascript_url(url):
|
||||
_bad("链接地址不正确")
|
||||
cleaned.append({"name": name, "url": url})
|
||||
return json.dumps(cleaned, ensure_ascii=False, separators=(",", ":"))
|
||||
|
||||
|
||||
def _positive(value, message: str) -> str:
|
||||
if isinstance(value, bool) or not isinstance(value, int) or value <= 0 or value > _INT_MAX:
|
||||
_bad(message)
|
||||
@@ -155,10 +118,6 @@ def _normalize_settings(payload: dict) -> dict[str, str]:
|
||||
stored[key] = _text_setting(key, value)
|
||||
elif key == "logo_file_id":
|
||||
stored[key] = _logo_id(value)
|
||||
elif key == "banner_file_ids":
|
||||
stored[key] = _banner_ids(value)
|
||||
elif key == "friend_links":
|
||||
stored[key] = _friend_links(value)
|
||||
elif key in _POSITIVE:
|
||||
stored[key] = _positive(value, _POSITIVE[key])
|
||||
elif key in _WORKDAYS:
|
||||
|
||||
Reference in new issue
Block a user