diff --git a/CHANGELOG.md b/CHANGELOG.md index 7eb963c..031cc7c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,14 +1,5 @@ # 更新日志 -4.2.4 - 2025-07-29 ---- -- CHANGE: 改进匹配器, 防止匹配不应匹配的内容 - -4.2.4-rc.0 - 2025-07-29 ---- -- PRE-RELEASE: v4.2.4-rc.0是v4.2.4预发布版本,请勿在生产环境中使用; -- CHANGE: 改进匹配器, 防止匹配不应匹配的内容 - 4.2.3 - 2025-07-27 --- - CHANGE: 改进错误页面加载器, 避免在选择`external`模式时错误页面渲染回退到json输出 diff --git a/DEV-VERSION b/DEV-VERSION index 4c573d6..f435fb6 100644 --- a/DEV-VERSION +++ b/DEV-VERSION @@ -1 +1 @@ -4.2.4-rc.0 \ No newline at end of file +4.2.3-rc.0 \ No newline at end of file diff --git a/VERSION b/VERSION index cf78d5b..ec87108 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -4.2.4 +4.2.3 \ No newline at end of file diff --git a/go.mod b/go.mod index 2635310..2e73766 100644 --- a/go.mod +++ b/go.mod @@ -4,7 +4,7 @@ go 1.24.5 require ( github.com/BurntSushi/toml v1.5.0 - github.com/WJQSERVER-STUDIO/httpc v0.8.2 + github.com/WJQSERVER-STUDIO/httpc v0.8.1 golang.org/x/net v0.42.0 golang.org/x/time v0.12.0 ) @@ -15,12 +15,15 @@ require ( github.com/fenthope/bauth v0.0.1 github.com/fenthope/ikumi v0.0.2 github.com/fenthope/ipfilter v0.0.1 - github.com/fenthope/reco v0.0.4 - github.com/fenthope/record v0.0.4 - github.com/go-json-experiment/json v0.0.0-20250725192818-e39067aee2d2 + github.com/fenthope/reco v0.0.3 + github.com/fenthope/record v0.0.3 + github.com/go-json-experiment/json v0.0.0-20250714165856-be8212f5270d github.com/hashicorp/golang-lru/v2 v2.0.7 - github.com/infinite-iroha/touka v0.3.4 + github.com/infinite-iroha/touka v0.3.3 github.com/wjqserver/modembed v0.0.1 ) -require github.com/valyala/bytebufferpool v1.0.0 // indirect +require ( + github.com/WJQSERVER-STUDIO/go-utils/copyb v0.0.6 // indirect + github.com/valyala/bytebufferpool v1.0.0 // indirect +) diff --git a/go.sum b/go.sum index f6f4f93..9a5bf1d 100644 --- a/go.sum +++ b/go.sum @@ -1,27 +1,29 @@ github.com/BurntSushi/toml v1.5.0 h1:W5quZX/G/csjUnuI8SUYlsHs9M38FC7znL0lIO+DvMg= github.com/BurntSushi/toml v1.5.0/go.mod h1:ukJfTF/6rtPPRCnwkur4qwRxa8vTRFBF0uk2lLoLwho= +github.com/WJQSERVER-STUDIO/go-utils/copyb v0.0.6 h1:/50VJYXd6jcu+p5BnEBDyiX0nAyGxas1W3DCnrYMxMY= +github.com/WJQSERVER-STUDIO/go-utils/copyb v0.0.6/go.mod h1:FZ6XE+4TKy4MOfX1xWKe6Rwsg0ucYFCdNh1KLvyKTfc= github.com/WJQSERVER-STUDIO/go-utils/iox v0.0.2 h1:AiIHXP21LpK7pFfqUlUstgQEWzjbekZgxOuvVwiMfyM= github.com/WJQSERVER-STUDIO/go-utils/iox v0.0.2/go.mod h1:mCLqYU32bTmEE6dpj37MKKiZgz70Jh/xyK9vVbq6pok= github.com/WJQSERVER-STUDIO/go-utils/limitreader v0.0.2 h1:8bBkKk6E2Zr+I5szL7gyc5f0DK8N9agIJCpM1Cqw2NE= github.com/WJQSERVER-STUDIO/go-utils/limitreader v0.0.2/go.mod h1:yPX8xuZH+py7eLJwOYj3VVI/4/Yuy5+x8Mhq8qezcPg= -github.com/WJQSERVER-STUDIO/httpc v0.8.2 h1:PFPLodV0QAfGEP6915J57vIqoKu9cGuuiXG/7C9TNUk= -github.com/WJQSERVER-STUDIO/httpc v0.8.2/go.mod h1:8WhHVRO+olDFBSvL5PC/bdMkb6U3vRdPJ4p4pnguV5Y= +github.com/WJQSERVER-STUDIO/httpc v0.8.1 h1:/eG8aYKL3WfQILIRbG+cbzQjPkNHEPTqfGUdQS5rtI4= +github.com/WJQSERVER-STUDIO/httpc v0.8.1/go.mod h1:mxXBf2hqbQGNHkVy/7wfU7Xi2s09MyZpbY2hyR+4uD4= github.com/fenthope/bauth v0.0.1 h1:+4UIQshGx3mYD4L3f2S4MLZOi5PWU7fU5GK3wsZvwzE= github.com/fenthope/bauth v0.0.1/go.mod h1:1fveTpgfR1p+WXQ8MXm9BfBCeNYi55j23jxCOGOvBSA= github.com/fenthope/ikumi v0.0.2 h1:5oaSTf/Msp7M2O3o/X20omKWEQbFhX4KV0CVF21oCdk= github.com/fenthope/ikumi v0.0.2/go.mod h1:IYbxzOGndZv/yRrbVMyV6dxh06X2wXCbfxrTRM1IruU= github.com/fenthope/ipfilter v0.0.1 h1:HrYAyixCMvsDAz36GRyFfyCNtrgYwzrhMcY0XV7fGcM= github.com/fenthope/ipfilter v0.0.1/go.mod h1:QfY0GrpG0D82HROgdH4c9eog4js42ghLIfl/iM4MvvY= -github.com/fenthope/reco v0.0.4 h1:yo2g3aWwdoMpaZWZX4SdZOW7mCK82RQIU/YI8ZUQThM= -github.com/fenthope/reco v0.0.4/go.mod h1:eMyS8HpdMVdJ/2WJt6Cvt8P1EH9Igzj5lSJrgc+0jeg= -github.com/fenthope/record v0.0.4 h1:/1JHNCxiXGLL/qCh4LEGaAvhj4CcKsb6siTxjLmjdO4= -github.com/fenthope/record v0.0.4/go.mod h1:G0a6KCiCDyX2SsC3nfzSN651fJKxH482AyJvzlnvAJU= -github.com/go-json-experiment/json v0.0.0-20250725192818-e39067aee2d2 h1:iizUGZ9pEquQS5jTGkh4AqeeHCMbfbjeb0zMt0aEFzs= -github.com/go-json-experiment/json v0.0.0-20250725192818-e39067aee2d2/go.mod h1:TiCD2a1pcmjd7YnhGH0f/zKNcCD06B029pHhzV23c2M= +github.com/fenthope/reco v0.0.3 h1:RmnQ0D9a8PWtwOODawitTe4BztTnS9wYwrDbipISNq4= +github.com/fenthope/reco v0.0.3/go.mod h1:mDkGLHte5udWTIcjQTxrABRcf56SSdxBOCLgrRDwI/Y= +github.com/fenthope/record v0.0.3 h1:v5urgs5LAkLMlljAT/MjW8fWuRHXPnAraTem5ui7rm4= +github.com/fenthope/record v0.0.3/go.mod h1:KFEkSc4TDZ3QIhP/wglD32uYVA6X1OUcripiao1DEE4= +github.com/go-json-experiment/json v0.0.0-20250714165856-be8212f5270d h1:+d6m5Bjvv0/RJct1VcOw2P5bvBOGjENmxORJYnSYDow= +github.com/go-json-experiment/json v0.0.0-20250714165856-be8212f5270d/go.mod h1:TiCD2a1pcmjd7YnhGH0f/zKNcCD06B029pHhzV23c2M= github.com/hashicorp/golang-lru/v2 v2.0.7 h1:a+bsQ5rvGLjzHuww6tVxozPZFVghXaHOwFs4luLUK2k= github.com/hashicorp/golang-lru/v2 v2.0.7/go.mod h1:QeFd9opnmA6QUJc5vARoKUSoFhyfM2/ZepoAG6RGpeM= -github.com/infinite-iroha/touka v0.3.4 h1:vYDjfXTkjpTe7tasSVbPeVAPSXzd/wS1T2tkiMx/Wwk= -github.com/infinite-iroha/touka v0.3.4/go.mod h1:xOKkEKTWYLHIBW6qbL2O6nSAO0RyDLsVXPtJxFYg/YM= +github.com/infinite-iroha/touka v0.3.3 h1:6Vy36bYjtbGKaBNiZBRcTne9Lcx8QTE6rpHqyMb3oiA= +github.com/infinite-iroha/touka v0.3.3/go.mod h1:9Y/MWlvlBL/8cqA+2ZUsnBr4h3f7yo3nOxsegIcBduw= github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw= github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc= github.com/wjqserver/modembed v0.0.1 h1:8ZDz7t9M5DLrUFlYgBUUmrMzxWsZPmHvOazkr/T2jEs= diff --git a/main.go b/main.go index 269727a..65a6e31 100644 --- a/main.go +++ b/main.go @@ -394,7 +394,7 @@ func main() { setupPages(cfg, r) 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) }) diff --git a/proxy/error.go b/proxy/error.go index 79f38ab..222f382 100644 --- a/proxy/error.go +++ b/proxy/error.go @@ -21,6 +21,7 @@ func HandleError(c *touka.Context, message string) { } func UnifiedToukaErrorHandler(c *touka.Context, code int, err error) { + errMsg := "" if err != nil { errMsg = err.Error() diff --git a/proxy/match.go b/proxy/match.go index 3f5f87f..a50d018 100644 --- a/proxy/match.go +++ b/proxy/match.go @@ -10,6 +10,11 @@ import ( ) var ( + githubPrefix = "https://github.com/" + rawPrefix = "https://raw.githubusercontent.com/" + gistPrefix = "https://gist.github.com/" + gistContentPrefix = "https://gist.githubusercontent.com/" + apiPrefix = "https://api.github.com/" githubPrefixLen int rawPrefixLen int gistPrefixLen int @@ -17,15 +22,6 @@ var ( apiPrefixLen int ) -const ( - githubPrefix = "https://github.com/" - rawPrefix = "https://raw.githubusercontent.com/" - gistPrefix = "https://gist.github.com/" - gistContentPrefix = "https://gist.githubusercontent.com/" - apiPrefix = "https://api.github.com/" - releasesDownloadSnippet = "releases/download/" -) - func init() { githubPrefixLen = len(githubPrefix) rawPrefixLen = len(rawPrefix) @@ -65,13 +61,7 @@ func Matcher(rawPath string, cfg *config.Config) (string, string, string, *GHPro } var matcher string switch action { - case "releases": - if strings.HasPrefix(remaining, releasesDownloadSnippet) { - matcher = "releases" - } else { - return "", "", "", NewErrorWithStatusLookup(400, "malformed github path: not a releases download url") - } - case "archive": + case "releases", "archive": matcher = "releases" case "blob": matcher = "blob" diff --git a/proxy/matcher_test.go b/proxy/matcher_test.go index 4b260c2..0c35381 100644 --- a/proxy/matcher_test.go +++ b/proxy/matcher_test.go @@ -38,18 +38,6 @@ func TestMatcher_Compatibility(t *testing.T) { config: cfgWithAuth, expectedUser: "owner", expectedRepo: "repo", expectedMatcher: "releases", }, - { - name: "GH Releases Path Page", - rawPath: "https://github.com/owner/repo/releases", - config: cfgWithAuth, - expectError: true, expectedErrCode: 400, - }, - { - name: "GH Releases Path Tag Page", - rawPath: "https://github.com/owner/repo/releases/tag/v0.0.1", - config: cfgWithAuth, - expectError: true, expectedErrCode: 400, - }, { name: "GH Archive Path", rawPath: "https://github.com/owner/repo.git/archive/main.zip",