mirror of
https://github.com/woodchen-ink/proxy-go.git
synced 2025-07-18 08:31:55 +08:00
移除不再使用的配置文件和信号处理模块,更新扩展名规则中的阈值注释以简化理解。
This commit is contained in:
parent
11378a7e0c
commit
a141672243
@ -1,27 +0,0 @@
|
||||
{
|
||||
"MAP": {
|
||||
"/path1": {
|
||||
"DefaultTarget": "https://path1.com/path/path/path",
|
||||
"ExtensionMap": {
|
||||
"jpg,png,avif": "https://path1-img.com/path/path/path",
|
||||
"mp4,webm": "https://path1-video.com/path/path/path"
|
||||
},
|
||||
"SizeThreshold": 204800
|
||||
},
|
||||
"/path2": "https://path2.com",
|
||||
"/path3": {
|
||||
"DefaultTarget": "https://path3.com",
|
||||
"SizeThreshold": 512000
|
||||
}
|
||||
},
|
||||
"Compression": {
|
||||
"Gzip": {
|
||||
"Enabled": false,
|
||||
"Level": 6
|
||||
},
|
||||
"Brotli": {
|
||||
"Enabled": false,
|
||||
"Level": 4
|
||||
}
|
||||
}
|
||||
}
|
@ -19,8 +19,8 @@ type PathConfig struct {
|
||||
type ExtensionRule struct {
|
||||
Extensions []string // 支持的扩展名列表
|
||||
Target string // 目标服务器
|
||||
SizeThreshold int64 // 最小文件大小阈值
|
||||
MaxSize int64 // 最大文件大小阈值
|
||||
SizeThreshold int64 // 最小阈值
|
||||
MaxSize int64 // 最大阈值
|
||||
}
|
||||
|
||||
type CompressionConfig struct {
|
||||
@ -37,8 +37,8 @@ type CompressorConfig struct {
|
||||
type ExtRuleConfig struct {
|
||||
Extensions string `json:"Extensions"` // 逗号分隔的扩展名
|
||||
Target string `json:"Target"` // 目标服务器
|
||||
SizeThreshold int64 `json:"SizeThreshold"` // 最小文件大小阈值
|
||||
MaxSize int64 `json:"MaxSize"` // 最大文件大小阈值
|
||||
SizeThreshold int64 `json:"SizeThreshold"` // 最小阈值
|
||||
MaxSize int64 `json:"MaxSize"` // 最大阈值
|
||||
}
|
||||
|
||||
// 处理扩展名映射的方法
|
||||
|
@ -1,32 +0,0 @@
|
||||
package utils
|
||||
|
||||
import (
|
||||
"os"
|
||||
"os/signal"
|
||||
"sync"
|
||||
"syscall"
|
||||
)
|
||||
|
||||
func SetupCloseHandler(callback func()) {
|
||||
c := make(chan os.Signal, 1)
|
||||
done := make(chan bool, 1)
|
||||
var once sync.Once
|
||||
|
||||
signal.Notify(c, os.Interrupt, syscall.SIGTERM)
|
||||
go func() {
|
||||
<-c
|
||||
once.Do(func() {
|
||||
callback()
|
||||
done <- true
|
||||
})
|
||||
}()
|
||||
|
||||
go func() {
|
||||
select {
|
||||
case <-done:
|
||||
os.Exit(0)
|
||||
case <-c:
|
||||
os.Exit(1)
|
||||
}
|
||||
}()
|
||||
}
|
@ -6,6 +6,7 @@ import (
|
||||
"encoding/hex"
|
||||
"fmt"
|
||||
"log"
|
||||
"math"
|
||||
"net"
|
||||
"net/http"
|
||||
neturl "net/url"
|
||||
@ -219,11 +220,12 @@ func GetTargetURL(client *http.Client, r *http.Request, pathConfig config.PathCo
|
||||
ext = strings.ToLower(ext)
|
||||
for _, rule := range pathConfig.ExtRules {
|
||||
// 处理阈值默认值
|
||||
if rule.SizeThreshold <= 0 {
|
||||
rule.SizeThreshold = 500 * 1024 // 默认最小阈值 500KB
|
||||
if rule.SizeThreshold < 0 {
|
||||
rule.SizeThreshold = 0 // 默认不限制
|
||||
}
|
||||
|
||||
if rule.MaxSize <= 0 {
|
||||
rule.MaxSize = 10 * 1024 * 1024 // 默认最大阈值 10MB
|
||||
rule.MaxSize = math.MaxInt64 // 设置为最大值表示不限制
|
||||
}
|
||||
|
||||
// 检查是否包含通配符
|
||||
@ -241,10 +243,9 @@ func GetTargetURL(client *http.Client, r *http.Request, pathConfig config.PathCo
|
||||
// 如果没有找到匹配的具体扩展名规则,使用通配符规则
|
||||
if len(matchingRules) == 0 {
|
||||
if len(wildcardRules) > 0 {
|
||||
log.Printf("[Route] %s -> 使用通配符规则 (扩展名: %s)", path, ext)
|
||||
log.Printf("[Route] %s -> 使用通配符规则", path)
|
||||
matchingRules = wildcardRules
|
||||
} else {
|
||||
log.Printf("[Route] %s -> %s (没有找到扩展名 %s 的规则)", path, targetBase, ext)
|
||||
return targetBase, false
|
||||
}
|
||||
}
|
||||
@ -265,8 +266,11 @@ func GetTargetURL(client *http.Client, r *http.Request, pathConfig config.PathCo
|
||||
rule := &matchingRules[i]
|
||||
|
||||
// 检查文件大小是否在阈值范围内
|
||||
if contentLength > rule.SizeThreshold && contentLength <= rule.MaxSize {
|
||||
if contentLength >= rule.SizeThreshold && contentLength <= rule.MaxSize {
|
||||
// 找到匹配的规则
|
||||
log.Printf("[Route] %s -> %s (文件大小: %s, 在区间 %s 到 %s 之间)",
|
||||
path, rule.Target, FormatBytes(contentLength),
|
||||
FormatBytes(rule.SizeThreshold), FormatBytes(rule.MaxSize))
|
||||
bestRule = rule
|
||||
break
|
||||
}
|
||||
|
@ -32,8 +32,8 @@ import {
|
||||
interface ExtRuleConfig {
|
||||
Extensions: string; // 逗号分隔的扩展名
|
||||
Target: string; // 目标服务器
|
||||
SizeThreshold: number; // 最小文件大小阈值(字节)
|
||||
MaxSize: number; // 最大文件大小阈值(字节)
|
||||
SizeThreshold: number; // 最小阈值(字节)
|
||||
MaxSize: number; // 最大阈值(字节)
|
||||
}
|
||||
|
||||
interface PathMapping {
|
||||
@ -610,7 +610,7 @@ export default function ConfigPage() {
|
||||
if (maxSizeBytes > 0 && sizeThresholdBytes >= maxSizeBytes) {
|
||||
toast({
|
||||
title: "错误",
|
||||
description: "最大文件大小阈值必须大于最小文件大小阈值",
|
||||
description: "最大阈值必须大于最小阈值",
|
||||
variant: "destructive",
|
||||
});
|
||||
return;
|
||||
@ -981,7 +981,7 @@ export default function ConfigPage() {
|
||||
</div>
|
||||
<div className="grid gap-4">
|
||||
<div className="grid gap-2">
|
||||
<Label htmlFor="ruleSizeThreshold">最小文件大小阈值</Label>
|
||||
<Label htmlFor="ruleSizeThreshold">最小阈值</Label>
|
||||
<div className="flex gap-2">
|
||||
<Input
|
||||
id="ruleSizeThreshold"
|
||||
@ -1012,7 +1012,7 @@ export default function ConfigPage() {
|
||||
</div>
|
||||
</div>
|
||||
<div className="grid gap-2">
|
||||
<Label htmlFor="ruleMaxSize">最大文件大小阈值</Label>
|
||||
<Label htmlFor="ruleMaxSize">最大阈值</Label>
|
||||
<div className="flex gap-2">
|
||||
<Input
|
||||
id="ruleMaxSize"
|
||||
|
Loading…
x
Reference in New Issue
Block a user