Skip to content

Commit e027ec0

Browse files
authored
Merge pull request #157 from WJQSERVER-STUDIO/dev
fix matcher(4.2.6)
2 parents b0388e6 + 97ee25b commit e027ec0

3 files changed

Lines changed: 39 additions & 8 deletions

File tree

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# 更新日志
22

3+
4.2.6 - 2025-08-01
4+
---
5+
- CHANGE: 修正匹配器
6+
37
4.2.5 - 2025-07-31
48
---
59
- CHANGE: 进一步完善匹配器, 兼容更多情况

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
4.2.5
1+
4.2.6

main.go

Lines changed: 34 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"net/http"
99
"os"
1010
"runtime/debug"
11+
"strings"
1112
"time"
1213

1314
"ghproxy/api"
@@ -394,14 +395,40 @@ func main() {
394395
setupPages(cfg, r)
395396
r.SetRedirectTrailingSlash(false)
396397

397-
r.GET("/github.com/:user/:repo/releases/download/*filepath", func(c *touka.Context) {
398-
c.Set("matcher", "releases")
399-
proxy.RoutingHandler(cfg)(c)
400-
})
398+
r.GET("/github.com/:user/:repo/releases/*filepath", func(c *touka.Context) {
399+
// 规范化路径: 移除前导斜杠, 简化后续处理
400+
filepath := c.Param("filepath")
401+
if len(filepath) > 0 && filepath[0] == '/' {
402+
filepath = filepath[1:]
403+
}
401404

402-
r.GET("/github.com/:user/:repo/releases/:tag/download/*filepath", func(c *touka.Context) {
403-
c.Set("matcher", "releases")
404-
proxy.RoutingHandler(cfg)(c)
405+
isValidDownload := false
406+
407+
// 检查两种合法的下载链接格式
408+
// 情况 A: "download/..."
409+
if strings.HasPrefix(filepath, "download/") {
410+
isValidDownload = true
411+
} else {
412+
// 情况 B: ":tag/download/..."
413+
slashIndex := strings.IndexByte(filepath, '/')
414+
// 确保 tag 部分存在 (slashIndex > 0)
415+
if slashIndex > 0 {
416+
pathAfterTag := filepath[slashIndex+1:]
417+
if strings.HasPrefix(pathAfterTag, "download/") {
418+
isValidDownload = true
419+
}
420+
}
421+
}
422+
423+
// 根据匹配结果执行最终操作
424+
if isValidDownload {
425+
c.Set("matcher", "releases")
426+
proxy.RoutingHandler(cfg)(c)
427+
} else {
428+
// 任何不符合下载链接格式的 'releases' 路径都被视为浏览页面并拒绝
429+
proxy.ErrorPage(c, proxy.NewErrorWithStatusLookup(400, "unsupported releases page, only download links are allowed"))
430+
return
431+
}
405432
})
406433

407434
r.GET("/github.com/:user/:repo/archive/*filepath", func(c *touka.Context) {

0 commit comments

Comments
 (0)