增加更多加速

This commit is contained in:
NewName
2024-12-25 05:27:28 +08:00
parent 33927a7578
commit b368436a60
4 changed files with 29 additions and 13 deletions

View File

@@ -6,6 +6,8 @@
- 超级轻量级
- 简单方便
- 自动配置HTTPS
- 支持Al模型库Hugging Face
- 支持docker-ce官方压缩包下载
---

View File

@@ -2,7 +2,9 @@
"whiteList": [
],
"blackList": [
"example3",
"example4"
"user1",
"user2",
"repository1",
"repository2"
]
}

View File

@@ -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
}
}

View File

@@ -386,7 +386,7 @@
</div>
<div class="tips">
<div class="tips-content">
<p>支持release、archive文件支持git clone、wget、curl等等操作,转换后的链接可直接使用</p><br>
<p>支持release、archive文件支持git clone、wget、curl等等操作<br>支持Al模型库Hugging Face支持docker-ce官方压缩包下载</p><br>
</div>
</div>
@@ -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 @@
</script>
</body>
</html>
</html>