Skip to content

Conversation

@clown145
Copy link
Contributor

@clown145 clown145 commented Jan 13, 2026

修复 README 弹窗中相对路径图片无法显示的问题,同时支持仓库内相对链接的跳转。

当 README 中使用相对路径引用图片(如 ./images/screenshot.png)或其他文档(如 ./docs/usage.md)时,由于路径解析问题导致无法正确加载。本 PR 实现了路径自动转换功能,并复用用户已配置的 GitHub 加速代理。

Modifications / 改动点

修改文件: dashboard/src/components/shared/ReadmeDialog.vue

功能实现:

  1. 相对图片路径转换为 GitHub Raw URL(https://raw.githubusercontent.com/...),支持代理加速
  2. 相对文档链接转换为 GitHub Blob URL(https://github.com/.../blob/main/...
  3. 复用用户在设置中配置的 GitHub 代理(localStorage.selectedGitHubProxy
  • This is NOT a breaking change. / 这不是一个破坏性变更。

Screenshots or Test Results / 运行截图或测试结果

chrome_9OyIM4G7Sp

验证步骤:

  1. 运行 npm run build 通过 ✅
  2. 安装包含相对路径图片的插件,查看 README 弹窗
  3. 确认图片正确加载,点击仓库内文档链接可正常跳转到 GitHub

Checklist / 检查清单

  • 😊 如果 PR 中有新加入的功能,已经通过 Issue / 邮件等方式和作者讨论过。/ If there are new features added in the PR, I have discussed it with the authors through issues/emails, etc.
  • 👀 我的更改经过了良好的测试,并已在上方提供了"验证步骤"和"运行截图"。/ My changes have been well-tested, and "Verification Steps" and "Screenshots" have been provided above.
  • 🤓 我确保没有引入新依赖库,或者引入了新依赖库的同时将其添加到了 requirements.txtpyproject.toml 文件相应位置。/ I have ensured that no new dependencies are introduced, OR if new dependencies are introduced, they have been added to the appropriate locations in requirements.txt and pyproject.toml.
  • 😮 我的更改没有引入恶意代码。/ My changes do not introduce malicious code.

Summary by Sourcery

增强 README 对话框,使其能够正确解析并打开针对托管在 GitHub 上的插件的仓库相对链接和图片。

新功能:

  • 将 README 对话框中的相对图片源转换为 GitHub 原始文件(raw)URL,并可选择通过用户配置的 GitHub 代理进行访问。
  • 将 README 对话框中的仓库相对文档链接转换为 GitHub blob URL,并在新标签页中安全打开。
Original summary in English

Summary by Sourcery

Enhance the README dialog to correctly resolve and open repository-relative links and images for GitHub-hosted plugins.

New Features:

  • Convert relative image sources in the README dialog to GitHub raw URLs, optionally routed through the user-configured GitHub proxy.
  • Convert repository-relative document links in the README dialog to GitHub blob URLs and open them safely in a new tab.

@auto-assign auto-assign bot requested review from Fridemn and anka-afk January 13, 2026 15:21
@dosubot dosubot bot added size:M This PR changes 30-99 lines, ignoring generated files. area:webui The bug / feature is about webui(dashboard) of astrbot. labels Jan 13, 2026
Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - 我发现了 1 个问题,并给出了一些整体性的反馈:

  • 当前对 GitHub 仓库的解析和 URL 生成假定为简单的 https://github.com/owner/repo 形式,并且默认分支为 main;建议支持更多常见变体,例如 /owner/repo//owner/repo.git,或带有 /tree/<branch> 的 URL,这样在默认分支不是 main 的仓库中,链接和图片也能正常工作。
  • parseGitHubRepoInfo 使用了相对宽松的正则表达式,可能会错误解析包含点号或额外路径段的仓库名;如果收紧这部分逻辑(例如显式去掉 .git 并忽略尾部额外路径),可以让 URL 转换更加健壮。
给 AI 代理的提示
Please address the comments from this code review:

## Overall Comments
- 当前对 GitHub 仓库的解析和 URL 生成假定为简单的 `https://github.com/owner/repo` 形式,并且默认分支为 `main`;建议支持更多常见变体,例如 `/owner/repo/``/owner/repo.git`,或带有 `/tree/<branch>` 的 URL,这样在默认分支不是 `main` 的仓库中,链接和图片也能正常工作。
- `parseGitHubRepoInfo` 使用了相对宽松的正则表达式,可能会错误解析包含点号或额外路径段的仓库名;如果收紧这部分逻辑(例如显式去掉 `.git` 并忽略尾部额外路径),可以让 URL 转换更加健壮。

## Individual Comments

### Comment 1
<location> `dashboard/src/components/shared/ReadmeDialog.vue:57-60` </location>
<code_context>
 });

+// 解析 GitHub 仓库信息
+function parseGitHubRepoInfo(repoUrl) {
+  if (!repoUrl) return null;
+  // 支持格式: https://github.com/user/repohttps://github.com/user/repo.git
+  const match = repoUrl.match(/github\.com\/([^/]+)\/([^/.]+)/);
+  if (!match) return null;
+  return { owner: match[1], repo: match[2] };
</code_context>

<issue_to_address>
**issue (bug_risk):** 用于解析 GitHub 仓库的正则会漏掉包含点号的合法仓库名,并且可能错误处理 `.git` 后缀。

`([^/.]+)` 会在遇到 `.``/` 时停止,因此像 `my.repo` 这样的仓库名会被解析为 `my`。它之所以“去掉” `.git`,只是因为在 `.` 处停止,从而将仓库名中的合法点号与 `.git` 后缀混在一起处理。更清晰的做法是捕获直到下一个 `/` 的所有内容,然后再去掉可选的 `.git` 后缀:

```js
const match = repoUrl.match(/github\.com\/([^/]+)\/([^/]+)(?:\.git)?/);
if (!match) return null;
const owner = match[1];
const repo = match[2].replace(/\.git$/, "");
return { owner, repo };
```

这样可以正确处理 `user/repo``user/repo.git`,以及名称中包含点号的仓库。
</issue_to_address>

Sourcery 对开源项目是免费的——如果你觉得我们的代码审查有帮助,请考虑分享一下 ✨
帮我变得更有用!请在每条评论上点 👍 或 👎,我会根据反馈改进之后的审查。
Original comment in English

Hey - I've found 1 issue, and left some high level feedback:

  • The GitHub repo parsing and URL generation assumes a simple https://github.com/owner/repo shape and a main default branch; consider handling more common variants such as /owner/repo/, /owner/repo.git, or URLs with /tree/<branch> so links and images work for non-main default branches.
  • parseGitHubRepoInfo uses a relatively loose regex that may mis-parse repository names containing dots or additional path segments; tightening this logic (e.g., explicitly stripping .git and ignoring trailing paths) would make the URL conversions more robust.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The GitHub repo parsing and URL generation assumes a simple `https://github.com/owner/repo` shape and a `main` default branch; consider handling more common variants such as `/owner/repo/`, `/owner/repo.git`, or URLs with `/tree/<branch>` so links and images work for non-`main` default branches.
- `parseGitHubRepoInfo` uses a relatively loose regex that may mis-parse repository names containing dots or additional path segments; tightening this logic (e.g., explicitly stripping `.git` and ignoring trailing paths) would make the URL conversions more robust.

## Individual Comments

### Comment 1
<location> `dashboard/src/components/shared/ReadmeDialog.vue:57-60` </location>
<code_context>
 });

+// 解析 GitHub 仓库信息
+function parseGitHubRepoInfo(repoUrl) {
+  if (!repoUrl) return null;
+  // 支持格式: https://github.com/user/repohttps://github.com/user/repo.git
+  const match = repoUrl.match(/github\.com\/([^/]+)\/([^/.]+)/);
+  if (!match) return null;
+  return { owner: match[1], repo: match[2] };
</code_context>

<issue_to_address>
**issue (bug_risk):** Regex for parsing GitHub repo misses valid repo names containing dots and may mis-handle `.git` suffix.

`([^/.]+)` stops at `.` or `/`, so repos like `my.repo` are parsed as `my`. It also only strips `.git` because of the `.` stop, mixing up valid dots in repo names with the `.git` suffix. A clearer approach is to capture everything to the next `/` and then strip an optional `.git` suffix:

```js
const match = repoUrl.match(/github\.com\/([^/]+)\/([^/]+)(?:\.git)?/);
if (!match) return null;
const owner = match[1];
const repo = match[2].replace(/\.git$/, "");
return { owner, repo };
```

This correctly handles `user/repo`, `user/repo.git`, and repos with dots in the name.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:webui The bug / feature is about webui(dashboard) of astrbot. size:M This PR changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant