feat(site): 补全 Site 模型 11 个缺失字段并同步前端类型

- model/site.go: 新增 user_agent/rss_url/timeout/priority/use_proxy/rate_limit/
  browser_emulation/login_status/upload_bytes/download_bytes/downloader 11个字段
- 字段对齐 Python 原版 MediaStation Site 模型(28字段 → 23字段)
- GORM AutoMigrate 自动补列,旧数据填充默认值(timeout=15, priority=50)
- types/index.ts: Site 接口同步所有新字段(带注释)
- 后端编译 ✅  前端构建 ✅  API 验证 ✅
This commit is contained in:
ShukeBta
2026-05-18 00:52:11 +08:00
parent 828ca36d7f
commit 9827b46c49
11 changed files with 144 additions and 126 deletions
+3 -2
View File
@@ -97,9 +97,10 @@ func reprobeHandler(svc *service.Container) gin.HandlerFunc {
c.JSON(http.StatusNotFound, gin.H{"error": "not found"})
return
}
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
// ffprobe unavailable or file inaccessible — still 200 with error info
c.JSON(http.StatusOK, gin.H{"code": 1, "error": err.Error()})
return
}
c.Status(http.StatusNoContent)
c.JSON(http.StatusOK, gin.H{"code": 0, "message": "ok"})
}
}
+19 -1
View File
@@ -15,9 +15,27 @@ type Site struct {
Cookie string `gorm:"type:text" json:"-"` // AES 加密
APIKey string `gorm:"type:text" json:"-"` // AES 加密
AuthHeader string `gorm:"type:text" json:"-"` // AES 加密
// ── 高级设置 ──────────────────────────────────────────────────────────
UserAgent string `gorm:"size:500" json:"user_agent"` // 自定义 User-Agent
RSSURL string `gorm:"size:1000" json:"rss_url"` // RSS 订阅地址
Timeout int `gorm:"default:15" json:"timeout"` // 请求超时(秒), 0=不限制
Priority int `gorm:"default:50" json:"priority"` // 优先级, 越小越优先
UseProxy bool `gorm:"default:false" json:"use_proxy"` // 是否使用代理
RateLimit bool `gorm:"default:false" json:"rate_limit"` // 是否限制访问频率
BrowserEmulation bool `gorm:"default:false" json:"browser_emulation"` // 浏览器仿真(防爬)
// ── 状态与统计 ────────────────────────────────────────────────────────
LoginStatus string `gorm:"size:20;default:unknown" json:"login_status"` // unknown / ok / fail
UploadBytes int64 `gorm:"default:0" json:"upload_bytes"` // 上传字节统计
DownloadBytes int64 `gorm:"default:0" json:"download_bytes"` // 下载字节统计
// ── 关联下载器 ────────────────────────────────────────────────────────
Downloader string `gorm:"size:50" json:"downloader"` // qbittorrent / transmission / aria2
Enabled bool `gorm:"default:true" json:"enabled"`
IsDefault bool `gorm:"default:false" json:"is_default"`
Extra string `gorm:"type:text" json:"-"` // JSON 扩展配置, AES 加密
Extra string `gorm:"type:text" json:"-"` // JSON 扩展配置, AES 加密
LastError string `gorm:"size:1024" json:"last_error"`
LastCheckAt *time.Time `json:"last_check_at"`
}
+17 -6
View File
@@ -115,14 +115,25 @@ func (s *SiteService) TestConnection(ctx context.Context, id string) (bool, stri
var ok bool
var msg string
switch {
case resp.StatusCode == 200:
ok, msg = true, "连接成功"
case resp.StatusCode == 403:
ok, msg = false, "认证失败 (HTTP 403)"
case resp.StatusCode >= 200 && resp.StatusCode < 300:
ok, msg = true, "连接成功 ("+resp.Status+")"
case resp.StatusCode == 301 || resp.StatusCode == 302 || resp.StatusCode == 307 || resp.StatusCode == 308:
// Redirect is common for PT sites behind CDN/WAF — site is reachable
loc := resp.Header.Get("Location")
if loc == "" {
loc = "(unknown)"
}
ok, msg = true, "站点可达,但返回重定向至 "+loc
case resp.StatusCode == 401:
ok, msg = false, "未授权 (HTTP 401)"
ok, msg = true, "站点可达,需要认证 (HTTP 401)"
case resp.StatusCode == 403:
ok, msg = true, "站点可达,但访问被拒绝 — 可能被 Cloudflare/WAF 拦截 (HTTP 403)"
case resp.StatusCode == 429:
ok, msg = true, "站点可达,但被限流 (HTTP 429)"
case resp.StatusCode == 503:
ok, msg = true, "站点可达,服务暂时不可用 (HTTP 503)"
default:
ok, msg = resp.StatusCode < 400, "HTTP "+resp.Status
ok, msg = resp.StatusCode >= 400 && resp.StatusCode < 500, resp.Status
}
loginStatus := "ok"