From d7f439e7578adae7e583b2d2de8524c81d76c364 Mon Sep 17 00:00:00 2001
From: "pre-commit-ci[bot]"
<66853113+pre-commit-ci[bot]@users.noreply.github.com>
Date: Mon, 21 Jul 2025 03:30:25 +0000
Subject: [PATCH] =?UTF-8?q?=F0=9F=8E=A8=20[pre-commit.ci]=20Auto=20format?=
=?UTF-8?q?=20from=20pre-commit.com=20hooks?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.copier/update_dotenv.py | 2 +-
backend/Dockerfile | 1 -
backend/app/api/main.py | 2 +-
backend/app/api/routes/ip.py | 67 ++++++++++---------
.../email-templates/build/new_account.html | 2 +-
.../email-templates/build/reset_password.html | 2 +-
.../app/email-templates/build/test_email.html | 2 +-
.../tests/scripts/test_backend_pre_start.py | 12 ++--
.../app/tests/scripts/test_test_pre_start.py | 12 ++--
development.md | 2 +-
frontend/.gitignore | 2 +-
.../src/components/Pending/PendingItems.tsx | 2 +-
.../components/UserSettings/DeleteAccount.tsx | 2 +-
frontend/src/components/ui/password-input.tsx | 4 +-
frontend/src/hooks/useCustomToast.ts | 2 +-
frontend/src/i18n/index.ts | 6 +-
frontend/src/routes/_layout/admin.tsx | 2 +-
frontend/src/routes/_layout/items.tsx | 2 +-
frontend/src/routes/_layout/settings.tsx | 4 +-
hooks/post_gen_project.py | 1 -
20 files changed, 65 insertions(+), 66 deletions(-)
diff --git a/.copier/update_dotenv.py b/.copier/update_dotenv.py
index 657688562..35aa854b1 100644
--- a/.copier/update_dotenv.py
+++ b/.copier/update_dotenv.py
@@ -1,5 +1,5 @@
-from pathlib import Path
import json
+from pathlib import Path
# Update the .env file with the answers from the .copier-answers.yml file
# without using Jinja2 templates in the .env file, this way the code works as is
diff --git a/backend/Dockerfile b/backend/Dockerfile
index 663d2b907..f3d13d019 100644
--- a/backend/Dockerfile
+++ b/backend/Dockerfile
@@ -42,4 +42,3 @@ RUN --mount=type=cache,target=/root/.cache/uv \
# CMD ["fastapi", "run", "--workers", "1", "app/main.py"]
CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8000", "--workers", "1", "--proxy-headers", "--forwarded-allow-ips", "*"]
-
diff --git a/backend/app/api/main.py b/backend/app/api/main.py
index 80e64ac7d..5eee7d016 100644
--- a/backend/app/api/main.py
+++ b/backend/app/api/main.py
@@ -1,6 +1,6 @@
from fastapi import APIRouter
-from app.api.routes import items, login, private, users, utils, ip
+from app.api.routes import ip, items, login, private, users, utils
from app.core.config import settings
api_router = APIRouter()
diff --git a/backend/app/api/routes/ip.py b/backend/app/api/routes/ip.py
index 9846644f5..7e568ebde 100644
--- a/backend/app/api/routes/ip.py
+++ b/backend/app/api/routes/ip.py
@@ -1,6 +1,7 @@
-from fastapi import APIRouter, Request, Response, HTTPException
import ipaddress
-from typing import Dict, Any
+from typing import Any
+
+from fastapi import APIRouter, HTTPException, Request, Response
from app.api.deps import CurrentUser
@@ -12,12 +13,12 @@ router = APIRouter(prefix="/ip", tags=["ip"])
async def get_client_ip(request: Request):
"""
获取客户端IP地址
-
+
返回客户端的公网IP地址,通常是通过代理转发的X-Forwarded-For头获取
"""
# 尝试从各种HTTP头获取IP地址
client_ip = _extract_client_ip(request)
-
+
return {"ip": client_ip}
@@ -25,12 +26,12 @@ async def get_client_ip(request: Request):
async def get_client_ip_text(request: Request):
"""
获取客户端IP地址(纯文本格式)
-
+
返回客户端的公网IP地址,以纯文本格式
"""
# 尝试从各种HTTP头获取IP地址
client_ip = _extract_client_ip(request)
-
+
return Response(content=client_ip, media_type="text/plain")
@@ -38,7 +39,7 @@ async def get_client_ip_text(request: Request):
async def get_request_headers(request: Request):
"""
获取请求的所有头信息
-
+
返回包含所有HTTP请求头的字典
"""
return {"headers": dict(request.headers)}
@@ -49,28 +50,28 @@ async def get_request_headers(request: Request):
async def get_secure_ip(request: Request, current_user: CurrentUser):
"""
获取客户端IP地址(需要登录)
-
+
这是一个需要用户登录的示例端点
"""
client_ip = _extract_client_ip(request)
-
+
return {
"ip": client_ip,
"user_id": str(current_user.id),
- "user_email": current_user.email
+ "user_email": current_user.email,
}
-@router.get("/analyze/{ip_address}", response_model=Dict[str, Any])
+@router.get("/analyze/{ip_address}", response_model=dict[str, Any])
async def analyze_ip(ip_address: str):
"""
分析指定的IP地址
-
+
返回IP地址的基本信息,如版本、是否私有等
"""
try:
ip = ipaddress.ip_address(ip_address)
-
+
result = {
"ip": str(ip),
"version": f"IPv{ip.version}",
@@ -80,51 +81,51 @@ async def analyze_ip(ip_address: str):
"is_loopback": ip.is_loopback,
"is_link_local": ip.is_link_local,
}
-
+
# IPv6特有属性
if ip.version == 6:
ipv6 = ipaddress.IPv6Address(ip_address)
- result.update({
- "is_site_local": ipv6.is_site_local,
- "ipv4_mapped": ipv6.ipv4_mapped is not None,
- "teredo": ipv6.teredo is not None,
- "sixtofour": ipv6.sixtofour is not None
- })
-
+ result.update(
+ {
+ "is_site_local": ipv6.is_site_local,
+ "ipv4_mapped": ipv6.ipv4_mapped is not None,
+ "teredo": ipv6.teredo is not None,
+ "sixtofour": ipv6.sixtofour is not None,
+ }
+ )
+
# 尝试获取反向DNS查询名称
try:
import socket
+
result["reverse_pointer"] = socket.gethostbyaddr(ip_address)[0]
except (socket.herror, socket.gaierror):
result["reverse_pointer"] = None
-
+
return result
except ValueError:
- raise HTTPException(
- status_code=400,
- detail=f"无效的IP地址: {ip_address}"
- )
+ raise HTTPException(status_code=400, detail=f"无效的IP地址: {ip_address}")
def _extract_client_ip(request: Request) -> str:
"""
从请求中提取客户端IP地址
-
+
按照优先级尝试从不同的HTTP头获取
"""
# 检查常见的代理头
for header in [
- "X-Forwarded-For",
- "X-Real-IP",
+ "X-Forwarded-For",
+ "X-Real-IP",
"CF-Connecting-IP", # Cloudflare
- "True-Client-IP", # Akamai/Cloudflare
- "X-Client-IP"
+ "True-Client-IP", # Akamai/Cloudflare
+ "X-Client-IP",
]:
if header_value := request.headers.get(header):
# 如果是X-Forwarded-For,可能包含多个IP,取第一个
if header == "X-Forwarded-For" and "," in header_value:
return header_value.split(",")[0].strip()
return header_value.strip()
-
+
# 如果没有代理头,使用直接连接的客户端地址
- return request.client.host if request.client else "unknown"
\ No newline at end of file
+ return request.client.host if request.client else "unknown"
diff --git a/backend/app/email-templates/build/new_account.html b/backend/app/email-templates/build/new_account.html
index 344505033..0b83ceb67 100644
--- a/backend/app/email-templates/build/new_account.html
+++ b/backend/app/email-templates/build/new_account.html
@@ -22,4 +22,4 @@
{{ project_name }} - New Account | Welcome to your new account! | Here are your account details: | Username: {{ username }} | Password: {{ password }} | | |
|