Merge pull request #157 from WJQSERVER-STUDIO/dev

fix matcher(4.2.6)
This commit is contained in:
WJQSERVER
2025-08-01 08:43:06 +08:00
committed by GitHub
3 changed files with 39 additions and 8 deletions

View File

@@ -1,5 +1,9 @@
# 更新日志 # 更新日志
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.5 4.2.6

41
main.go
View File

@@ -8,6 +8,7 @@ import (
"net/http" "net/http"
"os" "os"
"runtime/debug" "runtime/debug"
"strings"
"time" "time"
"ghproxy/api" "ghproxy/api"
@@ -394,14 +395,40 @@ func main() {
setupPages(cfg, r) setupPages(cfg, r)
r.SetRedirectTrailingSlash(false) r.SetRedirectTrailingSlash(false)
r.GET("/github.com/:user/:repo/releases/download/*filepath", func(c *touka.Context) { r.GET("/github.com/:user/:repo/releases/*filepath", func(c *touka.Context) {
c.Set("matcher", "releases") // 规范化路径: 移除前导斜杠, 简化后续处理
proxy.RoutingHandler(cfg)(c) filepath := c.Param("filepath")
}) if len(filepath) > 0 && filepath[0] == '/' {
filepath = filepath[1:]
}
r.GET("/github.com/:user/:repo/releases/:tag/download/*filepath", func(c *touka.Context) { isValidDownload := false
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) {