From b368436a60d7f6fe3b9ee2bc19618a516b83773c Mon Sep 17 00:00:00 2001 From: NewName Date: Wed, 25 Dec 2024 05:27:28 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=9B=B4=E5=A4=9A=E5=8A=A0?= =?UTF-8?q?=E9=80=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 2 ++ ghproxy/config.json | 6 ++++-- ghproxy/main.go | 16 ++++++++++------ ghproxy/public/index.html | 18 +++++++++++++----- 4 files changed, 29 insertions(+), 13 deletions(-) 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官方压缩包下载


@@ -468,13 +468,20 @@ var currentHost = window.location.host; var formattedLink = ""; var link = githubLinkInput.value.trim(); - + if (link.startsWith("https://") || link.startsWith("http://")) { formattedLink = "https://" + currentHost + "/" + link; - } else if (link.startsWith("github.com/") || link.startsWith("raw.githubusercontent.com/") || link.startsWith("gist.githubusercontent.com/")) { + } else if ( + link.startsWith("github.com/") || + link.startsWith("raw.githubusercontent.com/") || + link.startsWith("gist.githubusercontent.com/") || + link.startsWith("huggingface.co/") || + link.startsWith("cdn-lfs.hf.co/") || + link.startsWith("download.docker.com/") + ) { formattedLink = "https://" + currentHost + "/https://" + link; } else { - showToast('请输入有效的GitHub链接'); + showToast('请输入有效的链接'); return; } @@ -483,6 +490,7 @@ displayButton(); } + function displayButton() { var copyButton = document.getElementById('copyButton'); var redirButton = document.getElementById('redirButton'); @@ -521,4 +529,4 @@ - + \ No newline at end of file