feat: 站点访问统计与可配置侧边栏组件
- 新增访问统计:visitstats 服务与查询、visit_capture 中间件、爬虫/来源识别、管理端 analytics 页面 - 新增侧边栏:sidebar 服务与 handler、管理端 sidebar 配置页、前端侧边栏组件 - 新增 widget 嵌入代码生成(widgetCode)与 widgetApi - 遥测逻辑迁移至 handler 层,删除 service/telemetry - env 示例补充 Docker 部署可信代理 IP 说明
This commit is contained in:
31
backend/service/visit_bot_test.go
Normal file
31
backend/service/visit_bot_test.go
Normal file
@@ -0,0 +1,31 @@
|
||||
package service
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestClassifyBot(t *testing.T) {
|
||||
cases := []struct {
|
||||
ua string
|
||||
want string
|
||||
}{
|
||||
{"Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)", "Googlebot"},
|
||||
{"Mozilla/5.0 (compatible; bingbot/2.0)", "bingbot"},
|
||||
{"Mozilla/5.0 (compatible; Baiduspider/2.0)", "Baiduspider"},
|
||||
{"Mozilla/5.0 (compatible; Bytespider; https://zhanzhang.toutiao.com/)", "Bytespider"},
|
||||
{"curl/8.4.0", "curl"},
|
||||
{"Wget/1.21", "Wget"},
|
||||
{"python-requests/2.31", "python-requests"},
|
||||
{"Go-http-client/2.0", "Go-http-client"},
|
||||
{"GPTBot/1.0", "GPTBot"},
|
||||
{"ClaudeBot/1.0", "ClaudeBot"},
|
||||
{"HeadlessChrome/120", "HeadlessChrome"},
|
||||
// 人类浏览器不命中
|
||||
{"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0 Safari/537.36", ""},
|
||||
{"Mozilla/5.0 (iPhone; CPU iPhone OS 17_0 like Mac OS X) AppleWebKit/605.1.15 Mobile/15E148 Safari/604.1", ""},
|
||||
{"", ""},
|
||||
}
|
||||
for _, c := range cases {
|
||||
if got := ClassifyBot(c.ua); got != c.want {
|
||||
t.Errorf("ClassifyBot(%q) = %q, want %q", c.ua, got, c.want)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user