Skip to content

Commit 8215f91

Browse files
authored
Merge pull request #514 from Marrrrrrrrry/fix/m0-stop-bleeding
工程化加固、安全与性能修复、API 契约统一 snake_case(含 CI 测试流水线)
2 parents 6c76aab + 775f3fc commit 8215f91

75 files changed

Lines changed: 5343 additions & 2358 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/dependabot.yml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
version: 2
2+
updates:
3+
# Runtime deps. requirements.txt pins direct deps; requirements.lock.txt is
4+
# the hashed, transitive-resolved lockfile. Dependabot raises version PRs
5+
# against requirements.txt; regenerate the lockfile in the same PR
6+
# (uv pip compile requirements.txt --generate-hashes --universal -o requirements.lock.txt).
7+
- package-ecosystem: "pip"
8+
directory: "/"
9+
schedule:
10+
interval: "weekly"
11+
- package-ecosystem: "docker"
12+
directory: "/"
13+
schedule:
14+
interval: "weekly"
15+
- package-ecosystem: "github-actions"
16+
directory: "/"
17+
schedule:
18+
interval: "weekly"

.github/workflows/ci.yml

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
- dev
8+
pull_request:
9+
10+
concurrency:
11+
group: ci-${{ github.ref }}
12+
cancel-in-progress: true
13+
14+
permissions:
15+
contents: read
16+
17+
jobs:
18+
test:
19+
name: Lint and test
20+
runs-on: ubuntu-latest
21+
timeout-minutes: 15
22+
steps:
23+
- name: Checkout
24+
uses: actions/checkout@v4
25+
26+
- name: Setup Python
27+
uses: actions/setup-python@v5
28+
with:
29+
python-version: '3.12'
30+
31+
- name: Install dependencies
32+
run: |
33+
python -m pip install --upgrade pip
34+
# The hashed lockfile is the deploy artifact; install from it with
35+
# --require-hashes so CI fails on lockfile drift, exactly like the
36+
# Docker build does.
37+
pip install --require-hashes -r requirements.lock.txt
38+
pip install pytest pytest-asyncio httpx
39+
40+
- name: Ruff
41+
run: pipx run ruff==0.16.6 check .
42+
43+
- name: Verify lockfile matches requirements.txt
44+
# Dependabot bumps requirements.txt but cannot regenerate the hashed
45+
# lockfile; without this check a stale lockfile would silently keep
46+
# the Docker build on old versions.
47+
run: |
48+
python - <<'PY'
49+
import re, sys
50+
pins = dict(re.findall(r'^([\w-]+)==([\w.]+)$', open('requirements.txt').read(), re.M))
51+
lock = open('requirements.lock.txt').read()
52+
stale = []
53+
for name, ver in pins.items():
54+
m = re.search(rf'(?mi)^{re.escape(name)}==([\w.]+)\b', lock)
55+
if m is None or m.group(1) != ver:
56+
stale.append((name, ver, m.group(1) if m else 'ABSENT'))
57+
for name, req_ver, lock_ver in stale:
58+
print(f'STALE LOCKFILE: {name} requirements.txt={req_ver} lock={lock_ver}')
59+
sys.exit(1 if stale else 0)
60+
PY
61+
62+
- name: Run tests
63+
run: pytest -q

.gitignore

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,8 @@ docs/_build/
8080
.pybuilder/
8181
target/
8282
*.db
83-
./filecodebox.db-shm
84-
./filecodebox.db-wal
83+
*.db-shm
84+
*.db-wal
8585
# Jupyter Notebook
8686
.ipynb_checkpoints
8787

@@ -147,13 +147,8 @@ cython_debug/
147147
# Project
148148
.vscode
149149
.DS_Store
150-
for_test.py
151150
.html
152-
/evaluate/temp.py
153-
/evaluation/back.json
154151
data/.env
155-
.backup/
156-
/cloc-1.64.exe
157152

158153
# Ignore node_modules
159154
node_modules/

.pre-commit-config.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# First-time setup: pre-commit install
2+
# Behind a proxy: HTTPS_PROXY=http://<proxy-host>:<port> pre-commit run --all-files
3+
repos:
4+
- repo: https://github.com/astral-sh/ruff-pre-commit
5+
rev: v0.16.6
6+
hooks:
7+
- id: ruff-check
8+
args: [--fix]

Dockerfile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,12 @@ COPY --from=frontend-builder /build/fronted-2024/dist ./themes/2024
5858
COPY --from=frontend-builder /build/fronted-2023/dist ./themes/2023
5959

6060
# 安装系统安全更新 + Python 依赖
61+
# 依赖从带哈希的锁定文件安装(--require-hashes),保证构建可复现、防供应链篡改。
6162
# 清理 apt 缓存,降低镜像噪音与扫描面
6263
RUN apt-get update \
6364
&& apt-get upgrade -y --no-install-recommends \
6465
&& rm -rf /var/lib/apt/lists/* \
65-
&& pip install --no-cache-dir -r requirements.txt \
66+
&& pip install --no-cache-dir --require-hashes -r requirements.lock.txt \
6667
&& pip cache purge || true
6768

6869
# 环境变量配置

apps/admin/dependencies.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# @Author : Lan
33
# @File : depends.py
44
# @Software: PyCharm
5-
from fastapi import Header, HTTPException, Depends
5+
from fastapi import Header, HTTPException
66
from fastapi.requests import Request
77
import base64
88
import hmac
@@ -27,7 +27,7 @@ def _get_jwt_secret() -> bytes:
2727
def get_admin_session_expire_seconds() -> int:
2828
try:
2929
expires_in = int(
30-
getattr(settings, "adminSessionExpire", ADMIN_SESSION_EXPIRE_DEFAULT)
30+
getattr(settings, "admin_session_expire", ADMIN_SESSION_EXPIRE_DEFAULT)
3131
)
3232
except (TypeError, ValueError):
3333
return ADMIN_SESSION_EXPIRE_DEFAULT
@@ -155,14 +155,14 @@ async def share_required_login(authorization: str = Header(default=None)):
155155
"""
156156
验证分享上传权限
157157
158-
当settings.openUpload为False时,要求用户必须登录并具有管理员权限
159-
当settings.openUpload为True时,允许游客上传
158+
当 settings.open_upload 为False时,要求用户必须登录并具有管理员权限
159+
当 settings.open_upload 为True时,允许游客上传
160160
161161
:param authorization: 认证头信息
162162
:param request: 请求对象
163163
:return: 验证结果
164164
"""
165-
if not settings.openUpload:
165+
if not settings.open_upload:
166166
if not authorization or not authorization.startswith("Bearer "):
167167
raise HTTPException(
168168
status_code=403, detail="本站未开启游客上传,如需上传请先登录后台"

apps/admin/schemas.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,21 +39,18 @@ class BatchUpdateFileData(BaseModel):
3939
ids: list[int]
4040
expired_at: Optional[Union[datetime.datetime, str]] = None
4141
expired_count: Optional[int] = None
42-
clearExpiredAt: Optional[bool] = None
4342
clear_expired_at: Optional[bool] = None
4443

4544

4645
class FilePolicyActionData(BaseModel):
4746
id: int
4847
action: str
49-
downloadLimit: Optional[int] = None
5048
download_limit: Optional[int] = None
5149

5250

5351
class BatchFilePolicyActionData(BaseModel):
5452
ids: list[int]
5553
action: str
56-
downloadLimit: Optional[int] = None
5754
download_limit: Optional[int] = None
5855

5956

0 commit comments

Comments
 (0)