Repository navigation
feat(P0): 纳入 FastHub 能力——SDK 懒加载/Host IPv6/建桶/AI 探测/配置导出导入 - #548
Merged
Merged
Conversation
…置导出导入)
按 FastHub 移植清单落地 P0(排除中心/地址源、本地数据库、本地主机):
1) 存储 SDK 懒加载(参照 FastHub lazy_sdk)
- 新增 app/utils/lazy_sdk.py(LazyModule + lazy_module + sdk_exception)
- s3/oss/cos/obs/sftp 适配器改用 TYPE_CHECKING + 运行时代理:导入工厂不再拉起任何重型 SDK
(实测导入耗时 913ms → 603ms,6 个 SDK 全部延迟到首次使用该协议)
- 回归测试 tests/test_storage_lazy_sdk.py(子进程断言 sys.modules 变化)
2) Host 头校验修正(参照 FastHub host_guard 的 IPv6 解析)
- CustomTrustedHostMiddleware 改为纯 ASGI 实现:host_of() 正确处理 [::1]:8000 / [::1] / 裸 ::1,
主机与允许清单统一小写;保留 * 放行、*.example.com 通配、www 301、非 http/ws 直通;
WS scope 拒绝时回 websocket.close(1008) 而非 HTTP 响应
- tests/test_host_guard.py(19 项)
3) 对象存储建桶(FastHub 建桶能力)
- BaseStorageAdapter 新增 create_bucket(默认 NotImplementedError)
- S3(us-east-1 以外带 LocationConstraint)、OSS(put_bucket)、COS(create_bucket)、
OBS(按 status 判定失败)各自实现
- POST /task/storage/browse/create-bucket(权限 module_task:storage:browse:update)
- Web:存储浏览桶列表页新增「新建桶」按钮(名称校验 + 刷新列表)
- tests/test_storage_create_bucket.py(12 项)
4) AI 拉取模型列表 / 连通性测试(FastHub ai 探测)
- POST /ai/chat/model/available、/ai/chat/model/test(不落库;base_url 复用 http(s) 校验)
- 只返回模型 id/owned_by 与延迟,错误文案不回显密钥
- Web:AI 模型配置面板新增「拉取模型」「测试连通」按钮 + 可点击模型标签
- tests/test_ai_model_probe.py(5 项)
5) 存储源配置导出/导入(FastHub backup 思路)
- GET /task/storage/node/export、POST /task/storage/node/import
- 导出字段白名单:**不含 password / advanced_config / is_default**;导入按名称去重、绝不覆盖
- Web:存储源管理页新增「导出配置」「导入配置」(下载 JSON / 选文件导入并提示新增·跳过·无效数)
- tests/test_storage_config_io.py(7 项)
验证:后端 pytest **147 passed**、ruff All checks passed、basedpyright 0 errors;
前端 web type-check 通过、eslint 无错、prettier 已格式化、vitest **41 passed**。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
按 FastHub 移植清单落地 P0(已排除:中心/地址源、本地数据库、本地主机/本机文件/本机终端/桌面壳)。
1. 存储 SDK 懒加载
app/utils/lazy_sdk.py(LazyModule/lazy_module/sdk_exception)s3 / oss / cos / obs / sftp适配器改为TYPE_CHECKING+ 运行时代理2. Host 头 IPv6 修正
CustomTrustedHostMiddleware重写为纯 ASGI:host_of()正确处理[::1]:8000/[::1]/ 裸::1*、*.example.com、www301、非 http/ws 直通;WS 拒绝回websocket.close(1008)3. 对象存储建桶
BaseStorageAdapter.create_bucket+ S3(LocationConstraint)/ OSS / COS / OBS 实现POST /task/storage/browse/create-bucket;Web 桶列表页新增「新建桶」4. AI 拉模型 / 连通性测试
POST /ai/chat/model/available、POST /ai/chat/model/test(不落库,密钥不回显)5. 存储源配置导出 / 导入
GET /task/storage/node/export、POST /task/storage/node/import验证
pytest147 passed(新增 5 个测试文件:lazy_sdk / host_guard / create_bucket / ai_model_probe / config_io)ruffAll checks passed;basedpyright0 errorsvue-tsc --noEmit通过;eslint无错;prettier已格式化;vitest41 passed