fix(frontend): 修复 Docker 部署下图片路径 & 子路由刷新问题#387
Open
MarkYangKp wants to merge 3 commits into
Open
Conversation
后端存储的 Markdown 图片使用根相对路径(/static/screenshots/...),
前端预览时临时补后端地址可以正常显示,但复制和下载直接使用了原始
相对路径,粘贴到外部 Markdown 工具后图片全部失效。
修复方案:
- 新增 getBackendOrigin() 安全获取后端 origin,替代脆弱的 replace('/api', '')
- 新增 toPortableMarkdown() 将根相对图片路径转为绝对 URL
- Web 前端和扩展端所有复制/下载入口统一走转换函数
- 扩展端 absolutizeMarkdownImages 正则扩大为所有根相对路径,并排除 // 协议相对 URL
Docker 构建时 base: './' 导致资源使用相对路径,在 /settings 等 子路由刷新时浏览器将 ./assets/xxx.js 解析到错误路径,JS 加载失败。 改为 Docker 构建时使用 base: '/'(绝对路径),本地/Tauri 保持 './'。
## Root Cause
Markdown 缓存写入时机错误。缓存文件在 中写入的是 GPT
原始输出(含 *Screenshot-[mm:ss] 标记),但截图 URL 替换发生在后续的
中。导致:
- 首次显示:前端拿到内存中最终处理过的 Markdown,截图正常
- 刷新页面:前端从缓存读到未经替换的原始 Markdown,截图丢失
## Fixes
1. note.py: 在 _post_process_markdown 后会写 Markdown 缓存,
确保缓存保存的是含  的最终版本
2. screenshot_marker.py: 正则 \d{2} → \d{1,2},兼容 LLM 输出的 1-digit 时间格式
3. prompt_builder.py: 增强 Prompt 格式约束,明确要求两位数字
4. test_screenshot_marker.py: 新增 6 个测试用例覆盖 1-digit 时间等边缘情况
Author
补充修复:截图刷新后 404之前这个 PR 只修复了前端的图片路径问题,但没有解决后端缓存导致的核心 bug。 根因
新增改动(3dc3ccb)
|
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.
Summary
Details
'./'切换为'/',前端 Dockerfile 新增ENV DOCKER_BUILD=1Test plan
/settings等子路由不再白屏