Skip to content

Commit 8e2fb74

Browse files
authored
增加更多加速
1 parent a110c13 commit 8e2fb74

File tree

4 files changed

+29
-13
lines changed

4 files changed

+29
-13
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
- 超级轻量级
77
- 简单方便
88
- 自动配置HTTPS
9+
- 支持Al模型库Hugging Face
10+
- 支持docker-ce官方压缩包下载
911

1012
---
1113

ghproxy/config.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22
"whiteList": [
33
],
44
"blackList": [
5-
"example3",
6-
"example4"
5+
"user1",
6+
"user2",
7+
"repository1",
8+
"repository2"
79
]
810
}

ghproxy/main.go

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ var (
2929
regexp.MustCompile(`^(?:https?://)?raw\.github(?:usercontent|)\.com/([^/]+)/([^/]+)/.+?/.+$`),
3030
regexp.MustCompile(`^(?:https?://)?gist\.github(?:usercontent|)\.com/([^/]+)/.+?/.+`),
3131
regexp.MustCompile(`^(?:https?://)?api\.github\.com/repos/([^/]+)/([^/]+)/.*`),
32+
regexp.MustCompile(`^(?:https?://)?huggingface\.co/spaces/([^/]+)/([^/]+).*`),
33+
regexp.MustCompile(`^(?:https?://)?cdn-lfs\.hf\.co/repos/.+`),
34+
regexp.MustCompile(`^(?:https?://)?download\.docker\.com/.+\.(tgz|zip)$`),
3235
}
3336
httpClient *http.Client
3437
config *Config
@@ -66,7 +69,7 @@ func main() {
6669
loadConfig()
6770
}
6871
}()
69-
// 前端访问路径,默认根路径
72+
// 前端访问路径,默认根路径
7073
router.Static("/", "./public")
7174
router.NoRoute(handler)
7275

@@ -84,22 +87,22 @@ func handler(c *gin.Context) {
8487
}
8588

8689
if !strings.HasPrefix(rawPath, "http") {
87-
c.String(http.StatusForbidden, "Invalid input.")
90+
c.String(http.StatusForbidden, "无效输入")
8891
return
8992
}
9093

9194
matches := checkURL(rawPath)
9295
if matches != nil {
9396
if len(config.WhiteList) > 0 && !checkList(matches, config.WhiteList) {
94-
c.String(http.StatusForbidden, "Forbidden by white list.")
97+
c.String(http.StatusForbidden, "不在白名单内,限制访问。")
9598
return
9699
}
97100
if len(config.BlackList) > 0 && checkList(matches, config.BlackList) {
98-
c.String(http.StatusForbidden, "Forbidden by black list.")
101+
c.String(http.StatusForbidden, "黑名单限制访问")
99102
return
100103
}
101104
} else {
102-
c.String(http.StatusForbidden, "Invalid input.")
105+
c.String(http.StatusForbidden, "无效输入")
103106
return
104107
}
105108

@@ -202,9 +205,10 @@ func checkURL(u string) []string {
202205
return nil
203206
}
204207

208+
// 匹配用户名、仓库名,或者用户名/仓库名
205209
func checkList(matches, list []string) bool {
206210
for _, item := range list {
207-
if strings.HasPrefix(matches[0], item) {
211+
if strings.HasPrefix(matches[0], item) || strings.HasPrefix(matches[1], item) || strings.HasPrefix(matches[0]+"/"+matches[1], item) {
208212
return true
209213
}
210214
}

ghproxy/public/index.html

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -386,7 +386,7 @@ <h1>Github文件加速</h1>
386386
</div>
387387
<div class="tips">
388388
<div class="tips-content">
389-
<p>支持release、archive文件,支持git clone、wget、curl等等操作,转换后的链接可直接使用</p><br>
389+
<p>支持release、archive文件,支持git clone、wget、curl等等操作<br>支持Al模型库Hugging Face,支持docker-ce官方压缩包下载</p><br>
390390
</div>
391391
</div>
392392

@@ -468,13 +468,20 @@ <h5>请根据对应的仓库使用对应的加速域名</h5>
468468
var currentHost = window.location.host;
469469
var formattedLink = "";
470470
var link = githubLinkInput.value.trim();
471-
471+
472472
if (link.startsWith("https://") || link.startsWith("http://")) {
473473
formattedLink = "https://" + currentHost + "/" + link;
474-
} else if (link.startsWith("github.com/") || link.startsWith("raw.githubusercontent.com/") || link.startsWith("gist.githubusercontent.com/")) {
474+
} else if (
475+
link.startsWith("github.com/") ||
476+
link.startsWith("raw.githubusercontent.com/") ||
477+
link.startsWith("gist.githubusercontent.com/") ||
478+
link.startsWith("huggingface.co/") ||
479+
link.startsWith("cdn-lfs.hf.co/") ||
480+
link.startsWith("download.docker.com/")
481+
) {
475482
formattedLink = "https://" + currentHost + "/https://" + link;
476483
} else {
477-
showToast('请输入有效的GitHub链接');
484+
showToast('请输入有效的链接');
478485
return;
479486
}
480487

@@ -483,6 +490,7 @@ <h5>请根据对应的仓库使用对应的加速域名</h5>
483490
displayButton();
484491
}
485492

493+
486494
function displayButton() {
487495
var copyButton = document.getElementById('copyButton');
488496
var redirButton = document.getElementById('redirButton');
@@ -521,4 +529,4 @@ <h5>请根据对应的仓库使用对应的加速域名</h5>
521529
</script>
522530
</body>
523531

524-
</html>
532+
</html>

0 commit comments

Comments
 (0)