fix: 修复后端启动失败与前端构建失败,修正 README 许可证描述 - #17
Open
weed33834 wants to merge 2 commits into
Open
Conversation
- backend/requirements.txt: 补充缺失的 pydantic-settings 依赖 (config.py 依赖 BaseSettings,但该包未被 fastapi/pydantic 传递依赖) - frontend/src/vite-env.d.ts: 新增 Vite 类型声明文件,修复 tsc 报错 TS2882(side-effect import of './index.css') - frontend/src/pages/ModelConfig.tsx: 将渲染体内直接调用 load() 改为 useEffect,消除 React 反模式(渲染期 setState) - README.md / README.zh-CN.md / README.zh-TW.md: 修正 License 段 描述,与实际 MIT LICENSE 文件保持一致
Issue jaychouchannel#15: Generate.tsx 两个 useEffect 在模板切换时无条件覆盖 systemOverride,用户手改的 system prompt 被清空。改为仅在内容 为空或仍为模板默认值时才跟随模板,用户自定义后不再被覆盖。 Issue jaychouchannel#14: History 页面只展示代码不渲染 SVG 预览。后端 /api/history/{id}/svg 已实现,前端 api.ts/History.tsx 未对接。 新增 getHistorySvg API,点击记录时加载 SVG 并在右侧展示。 其他清理: - 删除从未被引用的 SetupBanner.tsx 组件 - 删除从未被调用的 factory.from_db_row 函数 - templates.py 种子日志从 print 改为 logging.warning - .gitignore 补充 *.tsbuildinfo / vite.config.d.ts / vite.config.js - git rm --cached 清理已提交的构建产物
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.
问题概述
按 README Quick Start 从零搭建环境时,后端和前端均无法正常启动/构建,存在多个独立问题。本次 PR 同时修复了 2 个 open issues 和若干代码质量问题。
问题详情与修复
1. 后端无法启动 — 缺少
pydantic-settings依赖backend/app/config.py:7使用了from pydantic_settings import BaseSettings,但pydantic-settings是独立包,不被fastapi/pydantic传递依赖。requirements.txt中遗漏了此项,导致按文档执行pip install -r requirements.txt后启动uvicorn app.main:app直接ModuleNotFoundError。修复:
requirements.txt新增pydantic-settings>=2.5.0。2. 前端生产构建失败 — 缺少
vite-env.d.tsfrontend/src/下缺少标准的 Vite 类型声明文件vite-env.d.ts。main.tsx中import "./index.css"在tsc -b阶段报错TS2882: Cannot find module or type declarations for side-effect import of ./index.css,npm run build退出码 1。修复:新增
frontend/src/vite-env.d.ts,内容为/// <reference types="vite/client" />。3.
ModelConfig.tsx在渲染体中调用load()(React 反模式)frontend/src/pages/ModelConfig.tsx:40直接在组件函数体中执行if (...) load(),load()内部调用setLoading(true)等 setState。这在 React 渲染期间触发状态更新,会导致控制台告警,且 StrictMode 双渲染会发起重复请求。其他页面(History、Templates)均正确使用useEffect。修复:改为
useEffect(() => { load(); }, [])。4. README License 段与实际 LICENSE 文件矛盾
README.md(及 zh-CN / zh-TW 版本)的 License 段声称"未声明开源许可证,保留所有权利",但根目录LICENSE实为 MIT License(Copyright 2026 Jay Chou)。这一矛盾会误导用户以为项目不可自由使用。修复:将三份 README 的 License 段改为正确的 MIT 说明,并链接到
LICENSE文件。5. Issue #15 — 模板切换覆盖用户自定义 system prompt
Generate.tsx存在两个useEffect依赖templateId/tpl,切换模板时无条件setSystemOverride(tpl.system_prompt),用户手动修改的 system prompt 被清空。修复:合并为单个 useEffect,引入
tplSystemPrompt状态跟踪模板默认值。仅当systemOverride为空或仍等于上一个模板默认值时才跟随模板更新;用户自定义后切换模板不再覆盖。6. Issue #14 — History 页面不渲染 SVG 预览
后端
GET /api/history/{id}/svg已实现(backend/app/routes/history.py:27),但前端api.ts缺少对应方法,History.tsx也未调用。修复:
api.ts新增getHistorySvg: (id) => req<{svg:string}>(\/api/history/${id}/svg`)`History.tsx点击记录时调用该 API,在右侧代码区下方新增 SVG 预览面板(复用 Generate 页的dangerouslySetInnerHTML方案,SVG 已过后端sanitize_svg消毒)7. 死代码清理
frontend/src/components/SetupBanner.tsx:全仓库 grep 仅此一处定义,无任何 import 引用,且组件本身也只是静态文案,未真正检测后端ONE_ENCRYPT_KEY状态backend/app/providers/factory.py的from_db_row函数:grep 确认仅定义从未被调用,generate.py用自建的_load_provider直接调make_providertemplates.py种子日志从print改为logging.warning,与main.py的 logging 配置一致8. 仓库卫生 — 清理被提交的构建产物
.gitignore未忽略*.tsbuildinfo,导致tsconfig.tsbuildinfo、tsconfig.node.tsbuildinfo、vite.config.d.ts、vite.config.js被 git 跟踪。修复:
.gitignore补充相关规则,git rm --cached移除已提交的构建产物。验证
pydantic-settings后from app.config import Settings导入成功npx tsc --noEmit编译通过,无类型错误项目设计很完善,安全方面(Fernet 加密、SVG 消毒、沙箱执行)做得很到位。这次修复的几个问题主要是开箱即用层面和前端体验上的缺失,希望能帮到其他新入手的同学。如果有什么需要调整的地方请告知,也欢迎关注交流 🙌