Compare commits

..

No commits in common. "e027ec0080953efa69dadc98384160a8479e7dd7" and "b0388e6abc1e11029bea246757242f9476357d7b" have entirely different histories.

3 changed files with 8 additions and 39 deletions

View file

@ -1,9 +1,5 @@
# 更新日志 # 更新日志
4.2.6 - 2025-08-01
---
- CHANGE: 修正匹配器
4.2.5 - 2025-07-31 4.2.5 - 2025-07-31
--- ---
- CHANGE: 进一步完善匹配器, 兼容更多情况 - CHANGE: 进一步完善匹配器, 兼容更多情况

View file

@ -1 +1 @@
4.2.6 4.2.5

41
main.go
View file

@ -8,7 +8,6 @@ import (
"net/http" "net/http"
"os" "os"
"runtime/debug" "runtime/debug"
"strings"
"time" "time"
"ghproxy/api" "ghproxy/api"
@ -395,40 +394,14 @@ func main() {
setupPages(cfg, r) setupPages(cfg, r)
r.SetRedirectTrailingSlash(false) r.SetRedirectTrailingSlash(false)
r.GET("/github.com/:user/:repo/releases/*filepath", func(c *touka.Context) { r.GET("/github.com/:user/:repo/releases/download/*filepath", func(c *touka.Context) {
// 规范化路径: 移除前导斜杠, 简化后续处理 c.Set("matcher", "releases")
filepath := c.Param("filepath") proxy.RoutingHandler(cfg)(c)
if len(filepath) > 0 && filepath[0] == '/' { })
filepath = filepath[1:]
}
isValidDownload := false r.GET("/github.com/:user/:repo/releases/:tag/download/*filepath", func(c *touka.Context) {
c.Set("matcher", "releases")
// 检查两种合法的下载链接格式 proxy.RoutingHandler(cfg)(c)
// 情况 A: "download/..."
if strings.HasPrefix(filepath, "download/") {
isValidDownload = true
} else {
// 情况 B: ":tag/download/..."
slashIndex := strings.IndexByte(filepath, '/')
// 确保 tag 部分存在 (slashIndex > 0)
if slashIndex > 0 {
pathAfterTag := filepath[slashIndex+1:]
if strings.HasPrefix(pathAfterTag, "download/") {
isValidDownload = true
}
}
}
// 根据匹配结果执行最终操作
if isValidDownload {
c.Set("matcher", "releases")
proxy.RoutingHandler(cfg)(c)
} else {
// 任何不符合下载链接格式的 'releases' 路径都被视为浏览页面并拒绝
proxy.ErrorPage(c, proxy.NewErrorWithStatusLookup(400, "unsupported releases page, only download links are allowed"))
return
}
}) })
r.GET("/github.com/:user/:repo/archive/*filepath", func(c *touka.Context) { r.GET("/github.com/:user/:repo/archive/*filepath", func(c *touka.Context) {