mirror of
https://github.com/WJQSERVER-STUDIO/ghproxy.git
synced 2026-02-03 00:01:10 +08:00
refine matcher: will not match releases page
This commit is contained in:
parent
4df21fd258
commit
d232d1cf12
10 changed files with 58 additions and 25 deletions
|
|
@ -21,7 +21,6 @@ func HandleError(c *touka.Context, message string) {
|
|||
}
|
||||
|
||||
func UnifiedToukaErrorHandler(c *touka.Context, code int, err error) {
|
||||
|
||||
errMsg := ""
|
||||
if err != nil {
|
||||
errMsg = err.Error()
|
||||
|
|
|
|||
|
|
@ -22,6 +22,10 @@ var (
|
|||
apiPrefixLen int
|
||||
)
|
||||
|
||||
var (
|
||||
releasesDownloadSinnipt = "releases/download/"
|
||||
)
|
||||
|
||||
func init() {
|
||||
githubPrefixLen = len(githubPrefix)
|
||||
rawPrefixLen = len(rawPrefix)
|
||||
|
|
@ -61,7 +65,13 @@ func Matcher(rawPath string, cfg *config.Config) (string, string, string, *GHPro
|
|||
}
|
||||
var matcher string
|
||||
switch action {
|
||||
case "releases", "archive":
|
||||
case "releases":
|
||||
if strings.HasPrefix(remaining, releasesDownloadSinnipt) {
|
||||
matcher = "releases"
|
||||
} else {
|
||||
return "", "", "", NewErrorWithStatusLookup(400, "malformed github path: not a releases download url")
|
||||
}
|
||||
case "archive":
|
||||
matcher = "releases"
|
||||
case "blob":
|
||||
matcher = "blob"
|
||||
|
|
|
|||
|
|
@ -38,6 +38,18 @@ 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",
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue