8 Commits

Author SHA1 Message Date
starry
dcb502d3c8 v1.1.9 2025-09-08 00:02:51 +08:00
starry
a011d560c6 shell转换中确保host有协议头 2025-09-04 04:13:21 +08:00
starry
53060d50db update 2025-09-02 12:34:42 +08:00
starry
68868388d3 更新为v1.1.8 2025-09-02 10:33:41 +08:00
starry
75833b937b 放宽gist匹配限制 2025-09-02 10:06:32 +08:00
starry
45b4acc31f 调整一些默认配置 2025-09-02 01:03:50 +08:00
starry
0cd5a7334d 增加.ps1脚本的处理 2025-09-01 12:16:42 +08:00
starry
40f5b597ab 增加检查是否为网页类型 2025-09-01 12:05:16 +08:00
8 changed files with 55 additions and 40 deletions

View File

@@ -84,8 +84,8 @@ func DefaultConfig() *AppConfig {
RequestLimit int `toml:"requestLimit"` RequestLimit int `toml:"requestLimit"`
PeriodHours float64 `toml:"periodHours"` PeriodHours float64 `toml:"periodHours"`
}{ }{
RequestLimit: 200, RequestLimit: 500,
PeriodHours: 1.0, PeriodHours: 3.0,
}, },
Security: struct { Security: struct {
WhiteList []string `toml:"whiteList"` WhiteList []string `toml:"whiteList"`

View File

@@ -20,7 +20,7 @@ var (
regexp.MustCompile(`^(?:https?://)?github\.com/([^/]+)/([^/]+)/(?:blob|raw)/.*`), regexp.MustCompile(`^(?:https?://)?github\.com/([^/]+)/([^/]+)/(?:blob|raw)/.*`),
regexp.MustCompile(`^(?:https?://)?github\.com/([^/]+)/([^/]+)/(?:info|git-).*`), regexp.MustCompile(`^(?:https?://)?github\.com/([^/]+)/([^/]+)/(?:info|git-).*`),
regexp.MustCompile(`^(?:https?://)?raw\.github(?:usercontent|)\.com/([^/]+)/([^/]+)/.+?/.+`), regexp.MustCompile(`^(?:https?://)?raw\.github(?:usercontent|)\.com/([^/]+)/([^/]+)/.+?/.+`),
regexp.MustCompile(`^(?:https?://)?gist\.(?:githubusercontent|github)\.com/(.+?)/(.+?)/.+\.[a-zA-Z0-9]+$`), regexp.MustCompile(`^(?:https?://)?gist\.(?:githubusercontent|github)\.com/([^/]+)/([^/]+).*`),
regexp.MustCompile(`^(?:https?://)?api\.github\.com/repos/([^/]+)/([^/]+)/.*`), regexp.MustCompile(`^(?:https?://)?api\.github\.com/repos/([^/]+)/([^/]+)/.*`),
regexp.MustCompile(`^(?:https?://)?huggingface\.co(?:/spaces)?/([^/]+)/(.+)`), regexp.MustCompile(`^(?:https?://)?huggingface\.co(?:/spaces)?/([^/]+)/(.+)`),
regexp.MustCompile(`^(?:https?://)?cdn-lfs\.hf\.co(?:/spaces)?/([^/]+)/([^/]+)(?:/(.*))?`), regexp.MustCompile(`^(?:https?://)?cdn-lfs\.hf\.co(?:/spaces)?/([^/]+)/([^/]+)(?:/(.*))?`),
@@ -29,6 +29,14 @@ var (
} }
) )
// 全局变量:被阻止的内容类型
var blockedContentTypes = map[string]bool{
"text/html": true,
"application/xhtml+xml": true,
"text/xml": true,
"application/xml": true,
}
// GitHubProxyHandler GitHub代理处理器 // GitHubProxyHandler GitHub代理处理器
func GitHubProxyHandler(c *gin.Context) { func GitHubProxyHandler(c *gin.Context) {
rawPath := strings.TrimPrefix(c.Request.URL.RequestURI(), "/") rawPath := strings.TrimPrefix(c.Request.URL.RequestURI(), "/")
@@ -122,10 +130,15 @@ func proxyGitHubWithRedirect(c *gin.Context, u string, redirectCount int) {
} }
}() }()
// 如果Github上游404则返回错误信息 // 检查并处理被阻止的内容类型
if resp.StatusCode == http.StatusNotFound { if c.Request.Method == "GET" {
c.String(http.StatusForbidden, "无效的GitHub地址") if contentType := resp.Header.Get("Content-Type"); blockedContentTypes[strings.ToLower(strings.Split(contentType, ";")[0])] {
return c.JSON(http.StatusForbidden, map[string]string{
"error": "Content type not allowed",
"message": "检测到网页类型,本服务不支持加速网页,请检查您的链接是否正确。",
})
return
}
} }
// 检查文件大小限制 // 检查文件大小限制
@@ -152,8 +165,8 @@ func proxyGitHubWithRedirect(c *gin.Context, u string, redirectCount int) {
realHost = "https://" + realHost realHost = "https://" + realHost
} }
// 处理.sh文件的智能处理 // 处理.sh和.ps1文件的智能处理
if strings.HasSuffix(strings.ToLower(u), ".sh") { if strings.HasSuffix(strings.ToLower(u), ".sh") || strings.HasSuffix(strings.ToLower(u), ".ps1") {
isGzipCompressed := resp.Header.Get("Content-Encoding") == "gzip" isGzipCompressed := resp.Header.Get("Content-Encoding") == "gzip"
processedBody, processedSize, err := utils.ProcessSmart(resp.Body, isGzipCompressed, realHost) processedBody, processedSize, err := utils.ProcessSmart(resp.Body, isGzipCompressed, realHost)

View File

@@ -125,7 +125,7 @@ func main() {
fmt.Printf("H2c: 已启用\n") fmt.Printf("H2c: 已启用\n")
} }
fmt.Printf("版本号: v1.1.7\n") fmt.Printf("版本号: v1.1.9\n")
fmt.Printf("项目地址: https://github.com/sky22333/hubproxy\n") fmt.Printf("项目地址: https://github.com/sky22333/hubproxy\n")
// 创建HTTP2服务器 // 创建HTTP2服务器

View File

@@ -1,13 +1,13 @@
<!DOCTYPE html> <!DOCTYPE html>
<html lang="zh"> <html lang="zh-CN">
<head> <head>
<meta charset="UTF-8"> <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="Docker镜像流式下载工具,即点即下,无需等待"> <meta name="description" content="Docker镜像流式下载工具即点即下无需等待">
<meta name="keywords" content="Docker,镜像下载,流式下载,即时下载"> <meta name="keywords" content="Docker镜像下载流式下载即时下载">
<meta name="color-scheme" content="dark light"> <meta name="color-scheme" content="dark light">
<title>Docker离线镜像下载</title> <title>Docker离线镜像下载</title>
<link rel="icon" href="./favicon.ico"> <link rel="icon" href="/favicon.ico">
<style> <style>
:root { :root {
--background: #ffffff; --background: #ffffff;

15
src/public/index.html vendored
View File

@@ -1,14 +1,13 @@
<!DOCTYPE html> <!DOCTYPE html>
<html lang="zh"> <html lang="zh-CN">
<head> <head>
<meta charset="UTF-8"> <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="Github文件加速,docker镜像加速"> <meta name="description" content="Github文件加速docker镜像加速">
<meta name="keywords" content="Github,文件加速,ghproxy,docker镜像加速"> <meta name="keywords" content="Github文件加速ghproxydocker镜像加速">
<meta name="color-scheme" content="dark light"> <meta name="color-scheme" content="dark light">
<title>Github文件加速</title> <title>Github、Docker加速</title>
<link rel="icon" href="./favicon.ico"> <link rel="icon" href="/favicon.ico">
<style> <style>
:root { :root {
--background: #ffffff; --background: #ffffff;
@@ -602,7 +601,7 @@
<div class="hero"> <div class="hero">
<h1 class="hero-title">GitHub 文件加速</h1> <h1 class="hero-title">GitHub 文件加速</h1>
<p class="hero-subtitle"> <p class="hero-subtitle">
快速下载GitHub上的文件和仓库解决国内访问GitHub速度慢的问题支持AI模型库Hugging Face 快速下载GitHub上的文件和仓库解决国内访问GitHub速度慢的问题支持Docker镜像加速和Hugging Face仓库。
</p> </p>
</div> </div>
@@ -685,7 +684,7 @@
<strong>Quay.io 镜像:</strong> <strong>Quay.io 镜像:</strong>
docker pull <span class="domain-base"></span>/quay.io/org/image docker pull <span class="domain-base"></span>/quay.io/org/image
<strong>K8s 镜像:</strong> <strong>Kubernetes 镜像:</strong>
docker pull <span class="domain-base"></span>/registry.k8s.io/pause:3.8 docker pull <span class="domain-base"></span>/registry.k8s.io/pause:3.8
</div> </div>
</div> </div>

View File

@@ -1,13 +1,13 @@
<!DOCTYPE html> <!DOCTYPE html>
<html lang="zh"> <html lang="zh-CN">
<head> <head>
<meta charset="UTF-8"> <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="Docker镜像搜索"> <meta name="description" content="Docker镜像搜索">
<meta name="keywords" content="Docker,镜像搜索,docker search"> <meta name="keywords" content="Docker镜像搜索docker search">
<meta name="color-scheme" content="dark light"> <meta name="color-scheme" content="dark light">
<title>Docker镜像搜索</title> <title>Docker镜像搜索</title>
<link rel="icon" href="./favicon.ico"> <link rel="icon" href="/favicon.ico">
<style> <style>
:root { :root {
--background: #ffffff; --background: #ffffff;

View File

@@ -77,18 +77,21 @@ func processGitHubURLs(content, host string) string {
// transformURL URL转换函数 // transformURL URL转换函数
func transformURL(url, host string) string { func transformURL(url, host string) string {
if strings.Contains(url, host) { if strings.Contains(url, host) {
return url return url
} }
if strings.HasPrefix(url, "http://") { if strings.HasPrefix(url, "http://") {
url = "https" + url[4:] url = "https" + url[4:]
} else if !strings.HasPrefix(url, "https://") && !strings.HasPrefix(url, "//") { } else if !strings.HasPrefix(url, "https://") && !strings.HasPrefix(url, "//") {
url = "https://" + url url = "https://" + url
} }
cleanHost := strings.TrimPrefix(host, "https://")
cleanHost = strings.TrimPrefix(cleanHost, "http://")
cleanHost = strings.TrimSuffix(cleanHost, "/")
return cleanHost + "/" + url // 确保 host 有协议头
if !strings.HasPrefix(host, "http://") && !strings.HasPrefix(host, "https://") {
host = "https://" + host
}
host = strings.TrimSuffix(host, "/")
return host + "/" + url
} }

View File

@@ -13,7 +13,7 @@ import (
) )
const ( const (
CleanupInterval = 10 * time.Minute CleanupInterval = 20 * time.Minute
MaxIPCacheSize = 10000 MaxIPCacheSize = 10000
) )
@@ -98,7 +98,7 @@ func (i *IPRateLimiter) cleanupRoutine() {
i.mu.RLock() i.mu.RLock()
for ip, entry := range i.ips { for ip, entry := range i.ips {
if now.Sub(entry.lastAccess) > 1*time.Hour { if now.Sub(entry.lastAccess) > 2*time.Hour {
expired = append(expired, ip) expired = append(expired, ip)
} }
} }