增加更多加速

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 - 自动配置HTTPS
- 支持Al模型库Hugging Face
- 支持docker-ce官方压缩包下载
--- ---

View File

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

View File

@@ -29,6 +29,9 @@ var (
regexp.MustCompile(`^(?:https?://)?raw\.github(?:usercontent|)\.com/([^/]+)/([^/]+)/.+?/.+$`), regexp.MustCompile(`^(?:https?://)?raw\.github(?:usercontent|)\.com/([^/]+)/([^/]+)/.+?/.+$`),
regexp.MustCompile(`^(?:https?://)?gist\.github(?:usercontent|)\.com/([^/]+)/.+?/.+`), regexp.MustCompile(`^(?:https?://)?gist\.github(?:usercontent|)\.com/([^/]+)/.+?/.+`),
regexp.MustCompile(`^(?:https?://)?api\.github\.com/repos/([^/]+)/([^/]+)/.*`), 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 httpClient *http.Client
config *Config config *Config
@@ -66,7 +69,7 @@ func main() {
loadConfig() loadConfig()
} }
}() }()
// 前端访问路径,默认根路径 // 前端访问路径,默认根路径
router.Static("/", "./public") router.Static("/", "./public")
router.NoRoute(handler) router.NoRoute(handler)
@@ -84,22 +87,22 @@ func handler(c *gin.Context) {
} }
if !strings.HasPrefix(rawPath, "http") { if !strings.HasPrefix(rawPath, "http") {
c.String(http.StatusForbidden, "Invalid input.") c.String(http.StatusForbidden, "无效输入")
return return
} }
matches := checkURL(rawPath) matches := checkURL(rawPath)
if matches != nil { if matches != nil {
if len(config.WhiteList) > 0 && !checkList(matches, config.WhiteList) { if len(config.WhiteList) > 0 && !checkList(matches, config.WhiteList) {
c.String(http.StatusForbidden, "Forbidden by white list.") c.String(http.StatusForbidden, "不在白名单内,限制访问。")
return return
} }
if len(config.BlackList) > 0 && checkList(matches, config.BlackList) { if len(config.BlackList) > 0 && checkList(matches, config.BlackList) {
c.String(http.StatusForbidden, "Forbidden by black list.") c.String(http.StatusForbidden, "黑名单限制访问")
return return
} }
} else { } else {
c.String(http.StatusForbidden, "Invalid input.") c.String(http.StatusForbidden, "无效输入")
return return
} }
@@ -202,9 +205,10 @@ func checkURL(u string) []string {
return nil return nil
} }
// 匹配用户名、仓库名,或者用户名/仓库名
func checkList(matches, list []string) bool { func checkList(matches, list []string) bool {
for _, item := range list { 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 return true
} }
} }

View File

@@ -386,7 +386,7 @@
</div> </div>
<div class="tips"> <div class="tips">
<div class="tips-content"> <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>
</div> </div>
@@ -471,10 +471,17 @@
if (link.startsWith("https://") || link.startsWith("http://")) { if (link.startsWith("https://") || link.startsWith("http://")) {
formattedLink = "https://" + currentHost + "/" + link; 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; formattedLink = "https://" + currentHost + "/https://" + link;
} else { } else {
showToast('请输入有效的GitHub链接'); showToast('请输入有效的链接');
return; return;
} }
@@ -483,6 +490,7 @@
displayButton(); displayButton();
} }
function displayButton() { function displayButton() {
var copyButton = document.getElementById('copyButton'); var copyButton = document.getElementById('copyButton');
var redirButton = document.getElementById('redirButton'); var redirButton = document.getElementById('redirButton');