diff --git a/README.md b/README.md index d072573..8a5dc1c 100644 --- a/README.md +++ b/README.md @@ -6,6 +6,8 @@ - 超级轻量级 - 简单方便 - 自动配置HTTPS +- 支持Al模型库Hugging Face +- 支持docker-ce官方压缩包下载 --- diff --git a/ghproxy/config.json b/ghproxy/config.json index 1759066..cc16e22 100644 --- a/ghproxy/config.json +++ b/ghproxy/config.json @@ -2,7 +2,9 @@ "whiteList": [ ], "blackList": [ - "example3", - "example4" + "user1", + "user2", + "repository1", + "repository2" ] } diff --git a/ghproxy/main.go b/ghproxy/main.go index cfab36c..5b4a559 100644 --- a/ghproxy/main.go +++ b/ghproxy/main.go @@ -29,6 +29,9 @@ var ( regexp.MustCompile(`^(?:https?://)?raw\.github(?:usercontent|)\.com/([^/]+)/([^/]+)/.+?/.+$`), regexp.MustCompile(`^(?:https?://)?gist\.github(?:usercontent|)\.com/([^/]+)/.+?/.+`), regexp.MustCompile(`^(?:https?://)?api\.github\.com/repos/([^/]+)/([^/]+)/.*`), + regexp.MustCompile(`^(?:https?://)?huggingface\.co/spaces/([^/]+)/([^/]+).*`), + regexp.MustCompile(`^(?:https?://)?cdn-lfs\.hf\.co/repos/.+`), + regexp.MustCompile(`^(?:https?://)?download\.docker\.com/.+\.(tgz|zip)$`), } httpClient *http.Client config *Config @@ -66,7 +69,7 @@ func main() { loadConfig() } }() - // 前端访问路径,默认根路径 + // 前端访问路径,默认根路径 router.Static("/", "./public") router.NoRoute(handler) @@ -84,22 +87,22 @@ func handler(c *gin.Context) { } if !strings.HasPrefix(rawPath, "http") { - c.String(http.StatusForbidden, "Invalid input.") + c.String(http.StatusForbidden, "无效输入") return } matches := checkURL(rawPath) if matches != nil { if len(config.WhiteList) > 0 && !checkList(matches, config.WhiteList) { - c.String(http.StatusForbidden, "Forbidden by white list.") + c.String(http.StatusForbidden, "不在白名单内,限制访问。") return } if len(config.BlackList) > 0 && checkList(matches, config.BlackList) { - c.String(http.StatusForbidden, "Forbidden by black list.") + c.String(http.StatusForbidden, "黑名单限制访问") return } } else { - c.String(http.StatusForbidden, "Invalid input.") + c.String(http.StatusForbidden, "无效输入") return } @@ -202,9 +205,10 @@ func checkURL(u string) []string { return nil } +// 匹配用户名、仓库名,或者用户名/仓库名 func checkList(matches, list []string) bool { for _, item := range list { - if strings.HasPrefix(matches[0], item) { + if strings.HasPrefix(matches[0], item) || strings.HasPrefix(matches[1], item) || strings.HasPrefix(matches[0]+"/"+matches[1], item) { return true } } diff --git a/ghproxy/public/index.html b/ghproxy/public/index.html index db14b58..13e21b6 100644 --- a/ghproxy/public/index.html +++ b/ghproxy/public/index.html @@ -386,7 +386,7 @@
支持release、archive文件,支持git clone、wget、curl等等操作,转换后的链接可直接使用
支持release、archive文件,支持git clone、wget、curl等等操作
支持Al模型库Hugging Face,支持docker-ce官方压缩包下载