Compare commits
31 Commits
v1.1.7
...
registry-a
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6ff610f5af | ||
|
|
7534c64197 | ||
|
|
5928a0a9e4 | ||
|
|
685388fff9 | ||
|
|
c6d95e683f | ||
|
|
f8828ccb74 | ||
|
|
fdc156adad | ||
|
|
80b0173d7c | ||
|
|
31f62fde35 | ||
|
|
8d7619c7e4 | ||
|
|
a09db34787 | ||
|
|
31a3b67ab0 | ||
|
|
3590c7c073 | ||
|
|
3f614e8011 | ||
|
|
198a18508b | ||
|
|
780ac14a8f | ||
|
|
62b3cb6b70 | ||
|
|
714224bd29 | ||
|
|
7f6c46f0c8 | ||
|
|
fd9b0cf829 | ||
|
|
42ddfaab9d | ||
|
|
6144883a6e | ||
|
|
c704923b64 | ||
|
|
dcb502d3c8 | ||
|
|
a011d560c6 | ||
|
|
53060d50db | ||
|
|
68868388d3 | ||
|
|
75833b937b | ||
|
|
45b4acc31f | ||
|
|
0cd5a7334d | ||
|
|
40f5b597ab |
BIN
.github/demo/demo1.jpg
vendored
Normal file
BIN
.github/demo/demo1.jpg
vendored
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 79 KiB |
16
.github/workflows/docker-ghcr.yml
vendored
16
.github/workflows/docker-ghcr.yml
vendored
@@ -3,9 +3,9 @@ on:
|
||||
workflow_dispatch:
|
||||
inputs:
|
||||
version:
|
||||
description: 'Version number'
|
||||
description: '版本号 (例如: v1.0.0)'
|
||||
required: true
|
||||
default: 'latest'
|
||||
default: 'v1.0.0'
|
||||
|
||||
jobs:
|
||||
build:
|
||||
@@ -36,7 +36,12 @@ jobs:
|
||||
password: ${{ secrets.GITHUB_TOKEN }}
|
||||
|
||||
- name: Set version from input
|
||||
run: echo "VERSION=${{ github.event.inputs.version }}" >> $GITHUB_ENV
|
||||
run: |
|
||||
VERSION=${{ github.event.inputs.version }}
|
||||
if [[ $VERSION == v* ]]; then
|
||||
VERSION=${VERSION:1}
|
||||
fi
|
||||
echo "VERSION=$VERSION" >> $GITHUB_ENV
|
||||
|
||||
- name: Convert repository name to lowercase
|
||||
run: |
|
||||
@@ -47,10 +52,9 @@ jobs:
|
||||
- name: Build and push Docker image
|
||||
run: |
|
||||
docker buildx build --push \
|
||||
--platform linux/amd64,linux/arm64 \
|
||||
--platform linux/amd64 \
|
||||
--tag ghcr.io/${{ env.REPO_LOWER }}:${{ env.VERSION }} \
|
||||
--tag ghcr.io/${{ env.REPO_LOWER }}:latest \
|
||||
--build-arg VERSION=${{ env.VERSION }} \
|
||||
-f Dockerfile .
|
||||
env:
|
||||
GHCR_PUBLIC: true # 将镜像设置为公开
|
||||
GHCR_PUBLIC: true
|
||||
|
||||
22
.github/workflows/release.yml
vendored
22
.github/workflows/release.yml
vendored
@@ -1,7 +1,7 @@
|
||||
name: 发布二进制文件
|
||||
|
||||
on:
|
||||
workflow_dispatch: # 手动触发
|
||||
workflow_dispatch:
|
||||
inputs:
|
||||
version:
|
||||
description: '版本号 (例如: v1.0.0)'
|
||||
@@ -18,12 +18,13 @@ jobs:
|
||||
- name: 检出代码
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
fetch-depth: 0 # 获取完整历史,用于生成变更日志
|
||||
fetch-depth: 0
|
||||
|
||||
- name: 设置Go环境
|
||||
uses: actions/setup-go@v5
|
||||
with:
|
||||
go-version: '1.25'
|
||||
go-version-file: "src/go.mod"
|
||||
cache-dependency-path: "src/go.sum"
|
||||
|
||||
- name: 获取版本号
|
||||
id: version
|
||||
@@ -53,15 +54,24 @@ jobs:
|
||||
run: |
|
||||
mkdir -p build/hubproxy
|
||||
|
||||
- name: 安装 UPX
|
||||
uses: crazy-max/ghaction-upx@v3
|
||||
with:
|
||||
install-only: true
|
||||
|
||||
- name: 编译二进制文件
|
||||
run: |
|
||||
cd src
|
||||
|
||||
# Linux AMD64
|
||||
GOOS=linux GOARCH=amd64 go build -ldflags="-s -w" -o ../build/hubproxy/hubproxy-linux-amd64 .
|
||||
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags="-s -w" -o ../build/hubproxy/hubproxy-linux-amd64 .
|
||||
|
||||
# Linux ARM64
|
||||
GOOS=linux GOARCH=arm64 go build -ldflags="-s -w" -o ../build/hubproxy/hubproxy-linux-arm64 .
|
||||
CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build -ldflags="-s -w" -o ../build/hubproxy/hubproxy-linux-arm64 .
|
||||
|
||||
# 压缩二进制文件
|
||||
upx -9 ../build/hubproxy/hubproxy-linux-amd64
|
||||
upx -9 ../build/hubproxy/hubproxy-linux-arm64
|
||||
|
||||
- name: 复制配置文件
|
||||
run: |
|
||||
@@ -125,4 +135,4 @@ jobs:
|
||||
build/checksums.txt
|
||||
draft: false
|
||||
prerelease: false
|
||||
token: ${{ secrets.GITHUB_TOKEN }}
|
||||
token: ${{ secrets.GITHUB_TOKEN }}
|
||||
|
||||
@@ -4,11 +4,11 @@ ARG TARGETARCH
|
||||
|
||||
WORKDIR /app
|
||||
COPY src/go.mod src/go.sum ./
|
||||
RUN go mod download
|
||||
RUN go mod download && apk add upx
|
||||
|
||||
COPY src/ .
|
||||
|
||||
RUN CGO_ENABLED=0 GOOS=linux GOARCH=${TARGETARCH} go build -ldflags="-s -w" -trimpath -o hubproxy .
|
||||
RUN CGO_ENABLED=0 GOOS=linux GOARCH=${TARGETARCH} go build -ldflags="-s -w" -trimpath -o hubproxy . && upx -9 hubproxy
|
||||
|
||||
FROM alpine
|
||||
|
||||
|
||||
32
README.md
32
README.md
@@ -1,14 +1,15 @@
|
||||
# HubProxy
|
||||
|
||||
🚀 **Docker 和 GitHub 加速代理服务器**
|
||||
**Docker 和 GitHub 加速代理服务器**
|
||||
|
||||
一个轻量级、高性能的多功能代理服务,提供 Docker 镜像加速、GitHub 文件加速、下载离线镜像、在线搜索 Docker 镜像等功能。
|
||||
|
||||
|
||||
<p align="center">
|
||||
<img src="https://count.getloli.com/get/@sky22333.hubproxy?theme=rule34" alt="Visitors">
|
||||
</p>
|
||||
|
||||
## ✨ 特性
|
||||
## 特性
|
||||
|
||||
- 🐳 **Docker 镜像加速** - 支持 Docker Hub、GHCR、Quay 等多个镜像仓库加速,流式传输优化拉取速度。
|
||||
- 🐳 **离线镜像包** - 支持下载离线镜像包,流式传输加防抖设计。
|
||||
@@ -22,8 +23,13 @@
|
||||
- 🛡️ **完全自托管** - 避免依赖免费第三方服务的不稳定性,例如`cloudflare`等等。
|
||||
- 🚀 **多服务统一加速** - 单个程序即可统一加速 Docker、GitHub、Hugging Face 等多种服务,简化部署与管理。
|
||||
|
||||
## 详细文档
|
||||
|
||||
## 🚀 快速开始
|
||||
[中文文档](https://zread.ai/sky22333/hubproxy)
|
||||
|
||||
[English](https://deepwiki.com/sky22333/hubproxy)
|
||||
|
||||
## 快速开始
|
||||
|
||||
### Docker部署(推荐)
|
||||
```
|
||||
@@ -34,25 +40,21 @@ docker run -d \
|
||||
ghcr.io/sky22333/hubproxy
|
||||
```
|
||||
|
||||
|
||||
|
||||
### 一键脚本安装
|
||||
|
||||
```bash
|
||||
curl -fsSL https://raw.githubusercontent.com/sky22333/hubproxy/main/install.sh | sudo bash
|
||||
```
|
||||
|
||||
也可以直接下载二进制文件执行`./hubproxy`使用,无需配置文件即可启动,内置默认配置,支持所有功能。
|
||||
支持单个二进制文件直接启动,无需其他配置,内置默认配置,支持所有功能。
|
||||
|
||||
这个脚本会:
|
||||
- 🔍 自动检测系统架构(AMD64/ARM64)
|
||||
- 📥 从 GitHub Releases 下载最新版本
|
||||
- ⚙️ 自动配置系统服务
|
||||
- 🔄 保留现有配置(升级时)
|
||||
- 自动检测系统架构(AMD64/ARM64)
|
||||
- 从 GitHub Releases 下载最新版本
|
||||
- 自动配置系统服务
|
||||
- 保留现有配置(升级时)
|
||||
|
||||
|
||||
|
||||
## 📖 使用方法
|
||||
## 使用方法
|
||||
|
||||
### Docker 镜像加速
|
||||
|
||||
@@ -96,7 +98,7 @@ https://yourdomain.com/https://github.com/user/repo/releases/download/v1.0.0/fil
|
||||
git clone https://yourdomain.com/https://github.com/sky22333/hubproxy.git
|
||||
```
|
||||
|
||||
## ⚙️ 配置
|
||||
## 配置
|
||||
|
||||
<details>
|
||||
<summary>config.toml 配置说明</summary>
|
||||
@@ -242,7 +244,9 @@ example.com {
|
||||
|
||||
</div>
|
||||
|
||||
## 界面预览
|
||||
|
||||

|
||||
|
||||
## Star 趋势
|
||||
[](https://starchart.cc/sky22333/hubproxy)
|
||||
|
||||
@@ -1,8 +1,14 @@
|
||||
services:
|
||||
hubproxy:
|
||||
build: .
|
||||
image: ghcr.io/sky22333/hubproxy
|
||||
container_name: hubproxy
|
||||
restart: always
|
||||
ports:
|
||||
- '5000:5000'
|
||||
- "5000:5000"
|
||||
volumes:
|
||||
- ./src/config.toml:/root/config.toml
|
||||
- ./src/config.toml:/root/config.toml
|
||||
logging:
|
||||
driver: json-file
|
||||
options:
|
||||
max-size: "1g"
|
||||
max-file: "2"
|
||||
|
||||
@@ -83,6 +83,12 @@ authHost = "registry.k8s.io"
|
||||
authType = "anonymous"
|
||||
enabled = true
|
||||
|
||||
# Default Registry
|
||||
[defaultRegistry]
|
||||
upstream = "registry-1.docker.io"
|
||||
authHost = "auth.docker.io"
|
||||
enabled = true
|
||||
|
||||
[tokenCache]
|
||||
# 是否启用缓存(同时控制Token和Manifest缓存)显著提升性能
|
||||
enabled = true
|
||||
|
||||
@@ -49,6 +49,8 @@ type AppConfig struct {
|
||||
} `toml:"download"`
|
||||
|
||||
Registries map[string]RegistryMapping `toml:"registries"`
|
||||
|
||||
DefaultRegistry RegistryMapping `toml:"defaultRegistry"`
|
||||
|
||||
TokenCache struct {
|
||||
Enabled bool `toml:"enabled"`
|
||||
@@ -84,8 +86,8 @@ func DefaultConfig() *AppConfig {
|
||||
RequestLimit int `toml:"requestLimit"`
|
||||
PeriodHours float64 `toml:"periodHours"`
|
||||
}{
|
||||
RequestLimit: 200,
|
||||
PeriodHours: 1.0,
|
||||
RequestLimit: 500,
|
||||
PeriodHours: 3.0,
|
||||
},
|
||||
Security: struct {
|
||||
WhiteList []string `toml:"whiteList"`
|
||||
|
||||
@@ -5,6 +5,7 @@ import (
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
"regexp"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
@@ -16,6 +17,8 @@ import (
|
||||
"hubproxy/utils"
|
||||
)
|
||||
|
||||
var realmRegex = regexp.MustCompile(`realm="(https?://)([^/"]+)(/?[^"]*)"`)
|
||||
|
||||
// DockerProxy Docker代理配置
|
||||
type DockerProxy struct {
|
||||
registry name.Registry
|
||||
@@ -28,9 +31,16 @@ var dockerProxy *DockerProxy
|
||||
type RegistryDetector struct{}
|
||||
|
||||
// detectRegistryDomain 检测Registry域名并返回域名和剩余路径
|
||||
func (rd *RegistryDetector) detectRegistryDomain(path string) (string, string) {
|
||||
func (rd *RegistryDetector) detectRegistryDomain(c *gin.Context, path string) (string, string) {
|
||||
cfg := config.GetConfig()
|
||||
|
||||
// 兼容Containerd的ns参数
|
||||
if ns := c.Query("ns"); ns != "" {
|
||||
if mapping, exists := cfg.Registries[ns]; exists && mapping.Enabled {
|
||||
return ns, path
|
||||
}
|
||||
}
|
||||
|
||||
for domain := range cfg.Registries {
|
||||
if strings.HasPrefix(path, domain+"/") {
|
||||
remainingPath := strings.TrimPrefix(path, domain+"/")
|
||||
@@ -61,7 +71,13 @@ var registryDetector = &RegistryDetector{}
|
||||
|
||||
// InitDockerProxy 初始化Docker代理
|
||||
func InitDockerProxy() {
|
||||
registry, err := name.NewRegistry("registry-1.docker.io")
|
||||
cfg := config.GetConfig()
|
||||
upstream := "registry-1.docker.io"
|
||||
if cfg.DefaultRegistry.Upstream != "" {
|
||||
upstream = cfg.DefaultRegistry.Upstream
|
||||
}
|
||||
|
||||
registry, err := name.NewRegistry(upstream)
|
||||
if err != nil {
|
||||
fmt.Printf("创建Docker registry失败: %v\n", err)
|
||||
return
|
||||
@@ -99,7 +115,7 @@ func ProxyDockerRegistryGin(c *gin.Context) {
|
||||
func handleRegistryRequest(c *gin.Context, path string) {
|
||||
pathWithoutV2 := strings.TrimPrefix(path, "/v2/")
|
||||
|
||||
if registryDomain, remainingPath := registryDetector.detectRegistryDomain(pathWithoutV2); registryDomain != "" {
|
||||
if registryDomain, remainingPath := registryDetector.detectRegistryDomain(c, pathWithoutV2); registryDomain != "" {
|
||||
if registryDetector.isRegistryEnabled(registryDomain) {
|
||||
c.Set("target_registry_domain", registryDomain)
|
||||
c.Set("target_path", remainingPath)
|
||||
@@ -346,17 +362,21 @@ func (r *ResponseRecorder) Write(data []byte) (int, error) {
|
||||
}
|
||||
|
||||
func proxyDockerAuthOriginal(c *gin.Context) {
|
||||
var authURL string
|
||||
cfg := config.GetConfig()
|
||||
|
||||
authHost := "auth.docker.io"
|
||||
if cfg.DefaultRegistry.AuthHost != "" {
|
||||
authHost = cfg.DefaultRegistry.AuthHost
|
||||
}
|
||||
|
||||
if targetDomain, exists := c.Get("target_registry_domain"); exists {
|
||||
if mapping, found := registryDetector.getRegistryMapping(targetDomain.(string)); found {
|
||||
authURL = "https://" + mapping.AuthHost + c.Request.URL.Path
|
||||
} else {
|
||||
authURL = "https://auth.docker.io" + c.Request.URL.Path
|
||||
authHost = mapping.AuthHost
|
||||
}
|
||||
} else {
|
||||
authURL = "https://auth.docker.io" + c.Request.URL.Path
|
||||
}
|
||||
|
||||
authURL := "https://" + authHost + c.Request.URL.Path
|
||||
|
||||
if c.Request.URL.RawQuery != "" {
|
||||
authURL += "?" + c.Request.URL.RawQuery
|
||||
}
|
||||
@@ -399,10 +419,15 @@ func proxyDockerAuthOriginal(c *gin.Context) {
|
||||
}
|
||||
}
|
||||
|
||||
scheme := "http"
|
||||
if c.Request.TLS != nil || c.GetHeader("X-Forwarded-Proto") == "https" {
|
||||
scheme = "https"
|
||||
}
|
||||
|
||||
for key, values := range resp.Header {
|
||||
for _, value := range values {
|
||||
if key == "Www-Authenticate" {
|
||||
value = rewriteAuthHeader(value, proxyHost)
|
||||
value = rewriteAuthHeader(value, scheme, proxyHost)
|
||||
}
|
||||
c.Header(key, value)
|
||||
}
|
||||
@@ -413,13 +438,8 @@ func proxyDockerAuthOriginal(c *gin.Context) {
|
||||
}
|
||||
|
||||
// rewriteAuthHeader 重写认证头
|
||||
func rewriteAuthHeader(authHeader, proxyHost string) string {
|
||||
authHeader = strings.ReplaceAll(authHeader, "https://auth.docker.io", "http://"+proxyHost)
|
||||
authHeader = strings.ReplaceAll(authHeader, "https://ghcr.io", "http://"+proxyHost)
|
||||
authHeader = strings.ReplaceAll(authHeader, "https://gcr.io", "http://"+proxyHost)
|
||||
authHeader = strings.ReplaceAll(authHeader, "https://quay.io", "http://"+proxyHost)
|
||||
|
||||
return authHeader
|
||||
func rewriteAuthHeader(authHeader, scheme, proxyHost string) string {
|
||||
return realmRegex.ReplaceAllString(authHeader, fmt.Sprintf(`realm="%s://%s$3"`, scheme, proxyHost))
|
||||
}
|
||||
|
||||
// handleMultiRegistryRequest 处理多Registry请求
|
||||
@@ -598,12 +618,5 @@ func createUpstreamOptions(mapping config.RegistryMapping) []remote.Option {
|
||||
remote.WithTransport(utils.GetGlobalHTTPClient().Transport),
|
||||
}
|
||||
|
||||
// 预留将来不同Registry的差异化认证逻辑扩展点
|
||||
switch mapping.AuthType {
|
||||
case "github":
|
||||
case "google":
|
||||
case "quay":
|
||||
}
|
||||
|
||||
return options
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@ var (
|
||||
regexp.MustCompile(`^(?:https?://)?github\.com/([^/]+)/([^/]+)/(?:blob|raw)/.*`),
|
||||
regexp.MustCompile(`^(?:https?://)?github\.com/([^/]+)/([^/]+)/(?:info|git-).*`),
|
||||
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?://)?huggingface\.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代理处理器
|
||||
func GitHubProxyHandler(c *gin.Context) {
|
||||
rawPath := strings.TrimPrefix(c.Request.URL.RequestURI(), "/")
|
||||
@@ -121,11 +129,16 @@ func proxyGitHubWithRedirect(c *gin.Context, u string, redirectCount int) {
|
||||
fmt.Printf("关闭响应体失败: %v\n", err)
|
||||
}
|
||||
}()
|
||||
|
||||
// 如果Github上游404,则返回错误信息
|
||||
if resp.StatusCode == http.StatusNotFound {
|
||||
c.String(http.StatusForbidden, "无效的GitHub地址")
|
||||
return
|
||||
|
||||
// 检查并处理被阻止的内容类型
|
||||
if c.Request.Method == "GET" {
|
||||
if contentType := resp.Header.Get("Content-Type"); blockedContentTypes[strings.ToLower(strings.Split(contentType, ";")[0])] {
|
||||
c.JSON(http.StatusForbidden, map[string]string{
|
||||
"error": "Content type not allowed",
|
||||
"message": "检测到网页类型,本服务不支持加速网页,请检查您的链接是否正确。",
|
||||
})
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
// 检查文件大小限制
|
||||
@@ -152,15 +165,15 @@ func proxyGitHubWithRedirect(c *gin.Context, u string, redirectCount int) {
|
||||
realHost = "https://" + realHost
|
||||
}
|
||||
|
||||
// 处理.sh文件的智能处理
|
||||
if strings.HasSuffix(strings.ToLower(u), ".sh") {
|
||||
// 处理.sh和.ps1文件的智能处理
|
||||
if strings.HasSuffix(strings.ToLower(u), ".sh") || strings.HasSuffix(strings.ToLower(u), ".ps1") {
|
||||
isGzipCompressed := resp.Header.Get("Content-Encoding") == "gzip"
|
||||
|
||||
processedBody, processedSize, err := utils.ProcessSmart(resp.Body, isGzipCompressed, realHost)
|
||||
if err != nil {
|
||||
fmt.Printf("智能处理失败,回退到直接代理: %v\n", err)
|
||||
processedBody = resp.Body
|
||||
processedSize = 0
|
||||
fmt.Printf("脚本处理失败: %v\n", err)
|
||||
c.String(http.StatusBadGateway, "Script processing failed: %v", err)
|
||||
return
|
||||
}
|
||||
|
||||
// 智能设置响应头
|
||||
|
||||
@@ -125,7 +125,7 @@ func main() {
|
||||
fmt.Printf("H2c: 已启用\n")
|
||||
}
|
||||
|
||||
fmt.Printf("版本号: v1.1.7\n")
|
||||
fmt.Printf("版本号: v1.2.1\n")
|
||||
fmt.Printf("项目地址: https://github.com/sky22333/hubproxy\n")
|
||||
|
||||
// 创建HTTP2服务器
|
||||
|
||||
8
src/public/images.html
vendored
8
src/public/images.html
vendored
@@ -1,13 +1,13 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="zh">
|
||||
<html lang="zh-CN">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<meta name="description" content="Docker镜像流式下载工具,即点即下,无需等待">
|
||||
<meta name="keywords" content="Docker,镜像下载,流式下载,即时下载">
|
||||
<meta name="description" content="Docker镜像流式下载工具、即点即下无需等待">
|
||||
<meta name="keywords" content="Docker镜像下载、流式下载、即时下载">
|
||||
<meta name="color-scheme" content="dark light">
|
||||
<title>Docker离线镜像下载</title>
|
||||
<link rel="icon" href="./favicon.ico">
|
||||
<link rel="icon" href="/favicon.ico">
|
||||
<style>
|
||||
:root {
|
||||
--background: #ffffff;
|
||||
|
||||
15
src/public/index.html
vendored
15
src/public/index.html
vendored
@@ -1,14 +1,13 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="zh">
|
||||
|
||||
<html lang="zh-CN">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<meta name="description" content="Github文件加速,docker镜像加速">
|
||||
<meta name="keywords" content="Github,文件加速,ghproxy,docker镜像加速">
|
||||
<meta name="description" content="Github文件加速、docker镜像加速">
|
||||
<meta name="keywords" content="Github、文件加速、ghproxy、docker镜像加速">
|
||||
<meta name="color-scheme" content="dark light">
|
||||
<title>Github文件加速</title>
|
||||
<link rel="icon" href="./favicon.ico">
|
||||
<title>Github、Docker加速</title>
|
||||
<link rel="icon" href="/favicon.ico">
|
||||
<style>
|
||||
:root {
|
||||
--background: #ffffff;
|
||||
@@ -602,7 +601,7 @@
|
||||
<div class="hero">
|
||||
<h1 class="hero-title">GitHub 文件加速</h1>
|
||||
<p class="hero-subtitle">
|
||||
快速下载GitHub上的文件和仓库,解决国内访问GitHub速度慢的问题,支持AI模型库Hugging Face
|
||||
快速下载GitHub上的文件和仓库,解决国内访问GitHub速度慢的问题,支持Docker镜像加速和Hugging Face仓库。
|
||||
</p>
|
||||
</div>
|
||||
|
||||
@@ -685,7 +684,7 @@
|
||||
<strong>Quay.io 镜像:</strong>
|
||||
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
|
||||
</div>
|
||||
</div>
|
||||
|
||||
6
src/public/search.html
vendored
6
src/public/search.html
vendored
@@ -1,13 +1,13 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="zh">
|
||||
<html lang="zh-CN">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<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">
|
||||
<title>Docker镜像搜索</title>
|
||||
<link rel="icon" href="./favicon.ico">
|
||||
<link rel="icon" href="/favicon.ico">
|
||||
<style>
|
||||
:root {
|
||||
--background: #ffffff;
|
||||
|
||||
@@ -200,6 +200,13 @@ func (ac *AccessController) checkList(matches, list []string) bool {
|
||||
if strings.HasPrefix(fullRepo, item+"/") {
|
||||
return true
|
||||
}
|
||||
|
||||
if strings.HasPrefix(item, "*/") {
|
||||
p := item[2:]
|
||||
if p == repoName || (strings.HasSuffix(p, "*") && strings.HasPrefix(repoName, p[:len(p)-1])) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
@@ -10,49 +10,46 @@ import (
|
||||
)
|
||||
|
||||
// GitHub URL正则表达式
|
||||
var githubRegex = regexp.MustCompile(`https?://(?:github\.com|raw\.githubusercontent\.com|raw\.github\.com|gist\.githubusercontent\.com|gist\.github\.com|api\.github\.com)[^\s'"]+`)
|
||||
var githubRegex = regexp.MustCompile(`(?:^|[\s'"(=,\[{;|&<>])https?://(?:github\.com|raw\.githubusercontent\.com|raw\.github\.com|gist\.githubusercontent\.com|gist\.github\.com|api\.github\.com)[^\s'")]*`)
|
||||
|
||||
// MaxShellSize 限制最大处理大小为 10MB
|
||||
const MaxShellSize = 10 * 1024 * 1024
|
||||
|
||||
// ProcessSmart Shell脚本智能处理函数
|
||||
func ProcessSmart(input io.ReadCloser, isCompressed bool, host string) (io.Reader, int64, error) {
|
||||
defer input.Close()
|
||||
|
||||
func ProcessSmart(input io.Reader, isCompressed bool, host string) (io.Reader, int64, error) {
|
||||
content, err := readShellContent(input, isCompressed)
|
||||
if err != nil {
|
||||
return nil, 0, fmt.Errorf("内容读取失败: %v", err)
|
||||
return nil, 0, err
|
||||
}
|
||||
|
||||
if len(content) == 0 {
|
||||
return strings.NewReader(""), 0, nil
|
||||
}
|
||||
|
||||
if len(content) > 10*1024*1024 {
|
||||
return strings.NewReader(content), int64(len(content)), nil
|
||||
if !bytes.Contains(content, []byte("github.com")) && !bytes.Contains(content, []byte("githubusercontent.com")) {
|
||||
return bytes.NewReader(content), int64(len(content)), nil
|
||||
}
|
||||
|
||||
if !strings.Contains(content, "github.com") && !strings.Contains(content, "githubusercontent.com") {
|
||||
return strings.NewReader(content), int64(len(content)), nil
|
||||
}
|
||||
|
||||
processed := processGitHubURLs(content, host)
|
||||
processed := processGitHubURLs(string(content), host)
|
||||
|
||||
return strings.NewReader(processed), int64(len(processed)), nil
|
||||
}
|
||||
|
||||
func readShellContent(input io.ReadCloser, isCompressed bool) (string, error) {
|
||||
func readShellContent(input io.Reader, isCompressed bool) ([]byte, error) {
|
||||
var reader io.Reader = input
|
||||
|
||||
if isCompressed {
|
||||
peek := make([]byte, 2)
|
||||
n, err := input.Read(peek)
|
||||
if err != nil && err != io.EOF {
|
||||
return "", fmt.Errorf("读取数据失败: %v", err)
|
||||
return nil, fmt.Errorf("读取数据失败: %v", err)
|
||||
}
|
||||
|
||||
if n >= 2 && peek[0] == 0x1f && peek[1] == 0x8b {
|
||||
combinedReader := io.MultiReader(bytes.NewReader(peek[:n]), input)
|
||||
gzReader, err := gzip.NewReader(combinedReader)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("gzip解压失败: %v", err)
|
||||
return nil, fmt.Errorf("gzip解压失败: %v", err)
|
||||
}
|
||||
defer gzReader.Close()
|
||||
reader = gzReader
|
||||
@@ -61,17 +58,30 @@ func readShellContent(input io.ReadCloser, isCompressed bool) (string, error) {
|
||||
}
|
||||
}
|
||||
|
||||
data, err := io.ReadAll(reader)
|
||||
limit := int64(MaxShellSize + 1)
|
||||
limitedReader := io.LimitReader(reader, limit)
|
||||
|
||||
data, err := io.ReadAll(limitedReader)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("读取内容失败: %v", err)
|
||||
return nil, fmt.Errorf("读取内容失败: %v", err)
|
||||
}
|
||||
|
||||
return string(data), nil
|
||||
if int64(len(data)) > MaxShellSize {
|
||||
return nil, fmt.Errorf("脚本文件过大,超过 %d MB 限制", MaxShellSize/1024/1024)
|
||||
}
|
||||
|
||||
return data, nil
|
||||
}
|
||||
|
||||
func processGitHubURLs(content, host string) string {
|
||||
return githubRegex.ReplaceAllStringFunc(content, func(url string) string {
|
||||
return transformURL(url, host)
|
||||
return githubRegex.ReplaceAllStringFunc(content, func(match string) string {
|
||||
// 如果匹配包含前缀分隔符,保留它,防止出现重复转换
|
||||
if len(match) > 0 && match[0] != 'h' {
|
||||
prefix := match[0:1]
|
||||
url := match[1:]
|
||||
return prefix + transformURL(url, host)
|
||||
}
|
||||
return transformURL(match, host)
|
||||
})
|
||||
}
|
||||
|
||||
@@ -86,9 +96,12 @@ func transformURL(url, host string) string {
|
||||
} else if !strings.HasPrefix(url, "https://") && !strings.HasPrefix(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
|
||||
}
|
||||
@@ -13,7 +13,7 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
CleanupInterval = 10 * time.Minute
|
||||
CleanupInterval = 20 * time.Minute
|
||||
MaxIPCacheSize = 10000
|
||||
)
|
||||
|
||||
@@ -98,7 +98,7 @@ func (i *IPRateLimiter) cleanupRoutine() {
|
||||
|
||||
i.mu.RLock()
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user