fix(markdown): resolve media previews under sign_all - #642
Open
LinYu369 wants to merge 1 commit into
Open
Conversation
- Rewrite relative media src (img/video/audio/source) to signed raw urls via fs/get, so previews work when sign_all is enabled or inside shares - Render image-syntax video links () as <video> elements, since browsers cannot play videos inside <img> - Allow video/audio/track elements and media attributes in the sanitize schema, which previously stripped them entirely - Resolve local media links by origin and strip the deployment base_path - Remove leftover console.log debug output
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 / 摘要
Fixes two markdown preview problems: images return 401 when
sign_allisenabled (the generated
/d/links carry no sign), and videos never render atall (image-syntax video links become
<img>, and the sanitize schema strips<video>elements entirely).修复两个 md 预览问题:开启
sign_all后图片链接不带签名导致 401;视频完全不显示(图片语法指向视频被转成<img>,且 sanitize 白名单会整体剥离<video>元素)。User-visible changes / 用户可感知的行为变化:
sign_allis enabled.or raw<video>tags) now render and play./@spaths to the share API automatically).Implementation changes / 重要实现变化:
fixMediaSrcrewrites relativesrcofimg/video/audio/sourceto signed raw urls obtained viafs/get(with caching, failure retry and a bounded concurrency pool).![]()links pointing to video files are rewritten to<video controls>elements.video/audio/trackelements and media attributes (they were previously stripped entirely).base_pathis stripped before resolving the storage path.console.logdebug statement.Config / storage / API / compatibility: none.
/ 无配置、存储、API 或兼容性变化。
This PR has breaking changes.
/ 此 PR 包含破坏性变更。
This PR changes public API, config, storage format, or migration behavior.
/ 此 PR 修改了公开 API、配置、存储格式或迁移行为。
This PR requires corresponding changes in related repositories.
/ 此 PR 需要关联仓库同步修改。
Related repository PRs / 关联仓库 PR:
Related Issues / 关联 Issue
N/A(无关联 Issue,本节可删除)
Testing / 测试
go test ./...— N/A, this is a frontend-only repository./ 不适用,本仓库为纯前端仓库,无 Go 代码。
pnpm lint(tsc --noEmit) — no errors in the changed file; the remaining errors are pre-existing and unrelated to this PR./ 变更文件无类型错误;其余报错为与本 PR 无关的既有问题。
pnpm build— succeeds.dist, withsign_all = true.POST /api/fs/getreturning a signedraw_url, and image requests hit/p/...?sign=...with 200.renders as a playable<video>with controls.<video src="..." controls>tags play as well.http(s)other-origin) images are unaffected./@sto the share API), not manually verified — please double-check with a share link if possible./ 分享页预览未手动验证(代码路径与普通预览一致),建议维护者用分享链接补充验证。
修复前

修复后的效果

测试用的md代码,媒体和md是在同一个目录下
Checklist / 检查清单
/ 我已阅读 CONTRIBUTING。
/ 我确认此贡献符合仓库许可证、贡献规范和行为准则。
gofmt,go fmt, orprettierwhere applicable./ 变更代码遵循项目 prettier 风格(与现有文件一致;本地未运行 prettier 命令)。
/ 不适用(未请求维护者审查)。
AI Disclosure / AI 使用声明
This PR includes AI-assisted content (code generation) produced with Qoder (Lingma). The core fix was manually verified end-to-end (images and videos render correctly with
sign_allenabled).此 PR 包含使用 Qoder (Lingma) 生成的 AI 辅助内容(代码生成),核心修复已端到端手动验证(sign_all 开启时图片、视频均可正常预览)。
/ 此 PR 包含 AI 辅助内容。
Tools used / 使用工具:
Usage scope / 使用范围:
Code generation / 代码生成
Refactoring / 重构
Documentation / 文档
Tests / 测试
Translation / 翻译
Review assistance / 审查辅助
I have reviewed and validated all AI-assisted content included in this PR.
/ 我已审核并验证此 PR 中的所有 AI 辅助内容。
I have ensured that all AI-assisted commits include
Co-Authored-Byattribution./ 我已确保所有 AI 辅助提交都包含
Co-Authored-By归属信息。(当前 commit 未包含,见下方说明)I can reproduce all AI-assisted content included in this PR without any AI tools.
/ 我可以在没有任何 AI 工具的情况下重现此 PR 中包含的所有 AI 辅助内容。(无法勾选,如实声明)